All Tools View Categories About Contact Privacy

Terraform IAM Policy Resource Generator

Generate a complete aws_iam_policy resource, optionally with a role and policy attachment.

Generates a starting-point HCL module — review and rename the placeholders before applying. Runs entirely in your browser.

  

About Terraform IAM Policy Resource Generator

Terraform IAM Policy Resource Generator goes beyond wrapping a policy JSON document in a bare jsonencode(...) call: it generates a complete, named aws_iam_policy resource with editable name, path, and description arguments, and — when you turn on the role option — an aws_iam_role plus an aws_iam_role_policy_attachment wiring the new policy to that role. The role's trust document is generated from a chosen AWS service principal (EC2, Lambda, ECS tasks, and more), so the output is a small, deployable mini-module rather than a single orphaned policy resource.

The policy document itself is embedded with jsonencode(...), the standard, idiomatic pattern most real Terraform codebases use for a raw IAM policy, since it accepts a JSON-compatible literal directly and reproduces your policy exactly, only re-indented to fit the HCL block.

Every generated name is a clearly labeled placeholder. This is a starting point for review, not a finished module: rename resource identifiers, the policy path, and the role name to fit your project, and add any dynamic Terraform references (like another resource's ARN) by hand — this tool only converts the static JSON you paste.

Features

  • Full aws_iam_policy resource with editable name, path, and description.
  • Optional aws_iam_role + aws_iam_role_policy_attachment pair, toggled with one checkbox.
  • Service-principal trust policy for the role — EC2, Lambda, ECS tasks, Step Functions, Glue, or EKS.
  • Uses the idiomatic jsonencode(...) pattern for both the policy and the trust document.
  • Works on any valid JSON, with a structural warning if it does not look like a complete IAM policy.
  • One-click copy of the generated HCL.
  • 100% client-side — nothing is uploaded.

How to Use

  1. Paste your policy JSON, or click the sample.
  2. Set the resource name, policy name, path, and description.
  3. Optionally check "Also generate a role + attachment" and pick a service principal and role name.
  4. Click Generate Terraform.
  5. Copy the HCL and rename the placeholders to fit your project before applying.

Examples

Example 1 — policy only. A simple S3 read-only statement produces one aws_iam_policy.example resource.

Example 2 — policy + role. With the role option on and "lambda" selected, the output additionally includes aws_iam_role.example (trusted by lambda.amazonaws.com) and an aws_iam_role_policy_attachment linking the two — a deployable mini-module for a Lambda execution role.

Benefits

  • A deployable module, not a lone resource — policy, role, and attachment together in one step.
  • Real trust-policy generation for common AWS service principals.
  • Uses the pattern real Terraform codebases actually use for embedding policy JSON.
  • Clearly labeled placeholders so you know exactly what to rename.
  • Private — generation runs entirely in your browser.

Frequently Asked Questions

Is this generated Terraform ready to apply as-is?
It is a reasonable starting point, not a guaranteed drop-in. Resource names (<code>aws_iam_policy.example</code>, <code>aws_iam_role.example</code>), the policy <code>name</code>/<code>path</code>/<code>description</code>, and the role name are all placeholders — rename them to fit your own Terraform project's naming conventions and review the trust policy before applying.
What does the "also generate a role + attachment" option add?
By itself an <code>aws_iam_policy</code> resource is not attached to anything. Turning this on additionally generates an <code>aws_iam_role</code> with an <code>assume_role_policy</code> trust document for the AWS service you pick (EC2, Lambda, ECS tasks, and so on), plus an <code>aws_iam_role_policy_attachment</code> resource that wires the new policy to that role by ARN — so the output is a small deployable module instead of one orphaned policy resource.
Why <code>jsonencode(...)</code> instead of nested HCL blocks for the policy document?
<code>jsonencode()</code> accepts a JSON-compatible object literal directly, so pasting your policy JSON (reformatted for HCL indentation) into it reproduces the policy exactly and is the idiomatic pattern used across real Terraform codebases — it avoids re-deriving equivalent HCL <code>for</code>/map syntax.
Does this handle Terraform variable references, like an S3 bucket ARN created elsewhere in the same module?
No. This converts a static, already-resolved policy JSON document into static HCL. If you need to reference another resource's attribute (e.g. <code>aws_s3_bucket.example.arn</code>) inside the policy, edit the generated JSON string by hand to add that interpolation.
Which service principals are available for the trust policy?
EC2, Lambda, ECS tasks, Step Functions (states), Glue, and EKS. If you need a different or a cross-account principal, generate the role here and edit the <code>assume_role_policy</code> block by hand, or use the dedicated IAM Trust Policy Generator tool.
Does it validate that my JSON is a well-formed IAM policy first?
It only requires valid JSON to generate HCL. If the parsed JSON does not look like a complete IAM policy it still converts, but shows a structural warning above the output.
Is my policy JSON uploaded anywhere?
No — parsing and HCL generation both run entirely in your browser.