All Tools View Categories About Contact Privacy

IAM Policy to Terraform HCL Converter

Convert IAM policy JSON into a Terraform aws_iam_policy resource block using jsonencode().

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

  

About IAM Policy to Terraform HCL Converter

Migrating an existing IAM policy into Terraform usually means wrapping it in an aws_iam_policy resource and choosing how to represent the policy document. IAM Policy to Terraform HCL Converter paste your policy JSON and produces an aws_iam_policy resource block that embeds the document using Terraform's jsonencode(...) function — the standard, idiomatic way most real-world Terraform codebases embed a raw IAM policy, since jsonencode() accepts a JSON-compatible literal directly and keeps the policy easy to read and diff.

The output is a starting point, not a finished module: the resource name and the policy's name argument are clearly labeled placeholders (aws_iam_policy.example, "example-policy") that you should rename to match your own project's conventions, and if your policy needs to reference another resource dynamically (say, a bucket ARN via aws_s3_bucket.example.arn) you will need to add that interpolation by hand — this tool only converts the static JSON you paste, it cannot infer which values should become dynamic Terraform references.

The JSON itself is not rewritten or reinterpreted at all beyond re-indenting it to fit inside the HCL block — every key, action, resource, and condition is preserved exactly as pasted.

Features

  • Generates an aws_iam_policy resource block using the idiomatic jsonencode(...) pattern.
  • Custom Terraform resource name and policy name fields.
  • Preserves your policy JSON exactly, only re-indented to fit the HCL block.
  • 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 Terraform resource name and policy name (or leave the defaults).
  3. Click Convert to Terraform.
  4. Copy the HCL and rename the placeholders to fit your project before applying.

Examples

Example. A simple S3 read-only statement converts into: resource "aws_iam_policy" "example" { name = "example-policy" policy = jsonencode({ ... }) }, with the policy JSON pretty-printed and indented inside the jsonencode(...) call.

Benefits

  • Skips the manual reformatting of wrapping an existing policy in an aws_iam_policy resource.
  • Uses the pattern real Terraform codebases actually usejsonencode(), not a hand-rolled HCL object translation.
  • Clearly labeled placeholders so you know exactly what to rename.
  • Private — conversion 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. The resource name (e.g. <code>aws_iam_policy.example</code>) and the <code>name</code> argument are placeholders you should rename to fit your own Terraform project's naming conventions before applying. Review the generated file like any other Terraform you didn't hand-write.
Why <code>jsonencode(...)</code> instead of writing the policy out as nested HCL blocks?
Because <code>jsonencode()</code> accepts a JSON-compatible object/array literal directly, pasting your existing policy JSON (reformatted for HCL indentation) into <code>jsonencode(...)</code> is the simplest, most robust, and most idiomatic pattern used across real Terraform codebases for embedding a raw IAM policy document — it avoids re-deriving the equivalent HCL <code>for</code>/map syntax that a hand-rolled per-key HCL translation would require, and it round-trips your policy exactly.
Does this handle Terraform variable references or interpolation, like referencing a bucket ARN dynamically?
No. This tool converts a static, already-resolved policy JSON document into a static HCL snippet. If you need to reference another resource's attribute (e.g. <code>aws_s3_bucket.example.arn</code>) inside the policy, you will need to edit the generated JSON string in your Terraform file by hand to add that interpolation — the converter has no way to know which values in your policy should become dynamic references.
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 (missing <code>Version</code>, empty <code>Statement</code>, and similar) 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.