aasmith / iam2tf

Converts AWS IAM policies into Terraform's `aws_iam_policy_document` format.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iam2tf

Synopsis

Converts AWS IAM policies into Terraform's aws_iam_policy_document format.

Usage

Given a JSON IAM policy document on stdin, it will produce an equivalent terraform document on stdout:

$ ruby iam2tf.rb < example.json

It is also available as a docker image:

$ docker run -i aasmith/iam2tf < example.json

Example Output

data "aws_iam_policy_document" "iam2tf" {

  statement {
    sid    = ""
    effect = "Allow"

    actions = [
      "sts:AssumeRole"
    ]

    principals {
      type = "Service"

      identifiers = [
        "ecs-tasks.amazonaws.com"
      ]
    }

  }

}

Example Input

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": "ecs-tasks.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

Running Tests

Current status: better than nothing.

for i in test/*.json; do echo $i; ruby iam2tf.rb < $i || break; done

TODO

  • Improve error handling
  • Add command line options to accept multiple files, etc.

References

About

Converts AWS IAM policies into Terraform's `aws_iam_policy_document` format.

License:MIT License


Languages

Language:Ruby 64.8%Language:HCL 35.2%