iam-policy-json-to-terraform is a free, open source cloud infrastructure management project written in JavaScript and released under Apache-2.0. It has 816 GitHub stars, 58 forks and 19 open issues, and was last pushed 4 days ago. On this registry it ranks #74 of 76 tracked projects in Cloud Infrastructure Management, with 5 head-to-head comparisons available.

What is iam-policy-json-to-terraform?

iam-policy-json-to-terraform is a small Apache-2.0 command line and web tool that converts an AWS IAM policy written in JSON into a Terraform aws_iam_policy_document data source, aimed at infrastructure engineers who already manage AWS access with Terraform.

What it is

The project lives in the Terraform and AWS IAM ecosystem, tagged with aws, terraform, hcl, iam, iam-policy and infrastructure-as-code. It takes a JSON IAM policy as input and prints HCL for a data "aws_iam_policy_document" block, so the policy can be expressed in Terraform configuration rather than pasted in as raw JSON. It ships as both a command line binary and a browser version hosted on GitHub Pages.

The concrete problem is translation. IAM policies routinely arrive as JSON from the AWS console, from existing deployed policies, or from documentation, while Terraform's aws_iam_policy_document expects HCL with statement blocks carrying sid, effect, actions and resources. Rewriting those by hand is tedious and easy to get wrong. This tool replaces that manual rewriting step, and it also gives an alternative to embedding a JSON heredoc inside an aws_iam_policy resource when a native data source would be cleaner.

Key capabilities

  • Converts a policy piped on stdin: echo '{"Statement":[{"Effect":"Allow","Action":["ec2:Describe*"],"Resource":"*"}]}' | iam-policy-json-to-terraform returns a data "aws_iam_policy_document" "policy" block with statement, effect = "Allow", resources = ["*"] and actions = ["ec2:Describe*"].
  • Reads from a file with a redirect: iam-policy-json-to-terraform < some-policy.json.
  • Emits the aws_iam_policy_document data source shape, including the sid attribute alongside effect, resources and actions.
  • Offers a hosted web version for one-off conversions, reachable from the project homepage.
  • Compiles to JavaScript for the browser: ./go web-build generates a web.js file that exposes a convert(policyName,jsonString) function in the global namespace.
  • Installs through several channels: brew install iam-policy-json-to-terraform, an asdf plugin, binaries from the releases page, or go install github.com/flosell/iam-policy-json-to-terraform@latest.
  • Coordinates development through a single ./go entry point with targets such as build, test, fmt, fmtcheck, seccheck, web-build, web-deploy, web-serve, web-e2e and web-visual-regression-test.

Who uses it and how

  • Terraform practitioners on AWS who hold an existing JSON policy and want it as an aws_iam_policy_document data source without retyping each statement.
  • Teams migrating access definitions out of the AWS console and into infrastructure-as-code, where the source material is JSON but the target is HCL.
  • Automation and CI workflows, because the tool reads stdin and writes stdout with no interactive step.
  • Contributors to the web frontend, which is plain HTML, JS and CSS inside web/index.html, with TestCafe end-to-end tests in web_test.js run through ./go web-e2e.
  • Newcomers who prefer a walkthrough; a two-minute introduction recorded by the folks at env0 is linked from the README.

Getting started

Install with brew install iam-policy-json-to-terraform, add the asdf plugin, download a binary from the releases page into your PATH, or run go install github.com/flosell/iam-policy-json-to-terraform@latest. The hosted web version is available for quick conversions without installing anything.

How it compares

The facts provided describe no paid products that this project replaces, and they name no comparable conversion tools. It therefore stands alone in this registry as the entry covering JSON-to-aws_iam_policy_document conversion.

When to use it — and when not to

A self-hoster operates very little: a local binary or a static web build, released under Apache-2.0, with no database, storage or SMTP dependency described. It suits teams that want a narrow, auditable transform and are comfortable running their own tooling, and it is a poor fit for anyone expecting a managed service or a broader IAM review and remediation product. Two honest caveats: the registry lists JavaScript as the language while the documented developer install and build path relies on Go tooling such as go install and ./go, so contributors should expect mixed toolchain requirements, and the README is short with 19 open issues, so edge cases in nested or unusual policy structures may need checking against the output by hand.

project readme (upstream, from github) — read inline

iam-policy-json-to-terraform

Build Status

Small tool to convert an IAM Policy in JSON format into a Terraform aws_iam_policy_document

Web Version

Check out a web version of the tool here.

For command line usage and automation, check out the instructions below.

Installation

OSX

$ brew install iam-policy-json-to-terraform

asdf

$ asdf plugin add iam-policy-json-to-terraform https://github.com/carlduevel/asdf-iam-policy-json-to-terraform.git

Other

Download the latest binary from the releases page and put it into your PATH under the name iam-policy-json-to-terraform

Developer

If you're a go developer and have your GOPATH defined and have added your $GOPATH/bin directory to your path, you can simply run this command.

$ go install github.com/flosell/iam-policy-json-to-terraform@latest

Usage

From raw JSON

$ echo '{"Statement":[{"Effect":"Allow","Action":["ec2:Describe*"],"Resource":"*"}]}' | iam-policy-json-to-terraform
data "aws_iam_policy_document" "policy" {
  statement {
    sid       = ""
    effect    = "Allow"
    resources = ["*"]
    actions   = ["ec2:Describe*"]
  }
}

From a JSON policy file

$ iam-policy-json-to-terraform < some-policy.json

If a video demo is more your thing, checkout this nice 2min introduction by the folks at env0.

Local development

Prerequisites

  • Clone the repository to a location of your choosing:

    $ git clone git@github.com:flosell/iam-policy-json-to-terraform.git
    
  • Install dependencies and tools for the web build (golang tooling is automatically installed when used):

    $ cd iam-policy-json-to-terraform
    $ ./go tools_web
    

Development

Entry point

./go is your primary point of entry for any development activity. Call it without arguments to learn more:

$ ./go help
build                          Test and build the whole application
clean                          Remove build artifacts
fmt                            Format code
fmtcheck                       Run linter
seccheck                       Run security checks
test                           Run all tests
test-readme                    Run the commands mentioned in the README for sanity-checking
tools                          Install additional required tooling
tools-main                     Install additional required tooling for the main version
tools-web                      Install additional required tooling for the web version
web-build                      Build the web version
web-deploy                     Deploy the web version to GitHub pages
web-e2e                        Run end to end tests for web version (requires web-build)
web-e2e-live                   Run end to end tests for web version in live mode for development (requires web-build)
web-serve                      Serve the web version on a local development server
web-visual-regression-approve  Accept changes in Web UI visuals
web-visual-regression-test     Test for changes in Web UI visuals
Web Development

To develop the web-frontend, you'll need to first compile the JavaScript version of iam-policy-json-to-terraform. ./go web-build will do that, generating a web.js file. Include it and it'll expose a convert(policyName,jsonString) function in the global namespace.

Currently, the complete web-frontend is plain HTML, JS and CSS, all within web/index.html. Edit or refine as needed.

End-To-End Tests for the web frontend exist as TestCafe tests in web_test.js and can be run using ./go web-e2e.

Frequently asked questions

Is iam-policy-json-to-terraform free to use?

iam-policy-json-to-terraform is open source under the Apache-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does iam-policy-json-to-terraform do?

Small tool to convert an IAM Policy in JSON format into a Terraform aws_iam_policy_document

What is iam-policy-json-to-terraform written in?

iam-policy-json-to-terraform is primarily written in JavaScript. Its source is publicly available at https://github.com/flosell/iam-policy-json-to-terraform, and it has 816 GitHub stars.