flosell / iam-policy-json-to-terraform

Small tool to convert an IAM Policy in JSON format into a Terraform aws_iam_policy_document
https://flosell.github.io/iam-policy-json-to-terraform/
Apache License 2.0
774 stars 58 forks source link

Provide more examples of where to start the JSON, multiple policies in one, etc., plus more informative messaging #48

Closed joemilacek closed 2 years ago

joemilacek commented 2 years ago

I keep pasting different sections of IAM policy JSON into the web converter and nothing happens. Which section of policy do I start at? Can I include multiple policies in one? The tool isn't giving me any feedback.

This sounds great but it is not working for me without some more specific information.

For example:

{
            "PolicyName": "DeployLambdaFunctions",
            "PolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Action": [
                            "lambda:Get*",
                            "lambda:List*",
                            "lambda:CreateFunction",
                            "lambda:DeleteFunction",
                            "lambda:CreateFunction",
                            "lambda:DeleteFunction",
                            "lambda:UpdateFunctionConfiguration",
                            "lambda:UpdateFunctionCode",
                            "lambda:PublishVersion",
                            "lambda:CreateAlias",
                            "lambda:DeleteAlias",
                            "lambda:UpdateAlias",
                            "lambda:AddPermission",
                            "lambda:RemovePermission",
                            "lambda:InvokeFunction"
                        ],
                        "Resource": [
                            {
                                "Fn::Sub": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AppId}-*"
                            }
                        ]
                    }
                ]
            }
        }

...results in nothing:

image

Other pastes w/ actual formatting issues do give some error output, so it's not like the whole web app isn't working for me.

I'm sure I'm doing something wrong, but if it's not too much trouble to hint at what it could be, that would be awesome!

This could just be my ignorance though!!

flosell commented 2 years ago

Hi @joemilacek, thanks for reaching out! Looking at your example, my guess is this is coming from a CloudFormation Template? Those are slightly different from the plain IAM policy documents this tool is intended for. Using only the PolicyDocument part and stripping out CF-specifics (the FN::Sub in your example) would convert:

{
  "Version": "2012-10-17",
  "Statement": 
    {
      "Effect": "Allow",
      "Action": [
        "lambda:Get*",
        "lambda:List*",
        "lambda:CreateFunction",
        "lambda:DeleteFunction",
        "lambda:CreateFunction",
        "lambda:DeleteFunction",
        "lambda:UpdateFunctionConfiguration",
        "lambda:UpdateFunctionCode",
        "lambda:PublishVersion",
        "lambda:CreateAlias",
        "lambda:DeleteAlias",
        "lambda:UpdateAlias",
        "lambda:AddPermission",
        "lambda:RemovePermission",
        "lambda:InvokeFunction"
      ],
      "Resource": ["arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AppId}-*"]
   }
}

Now, beyond this, you actually raise two good, more general points:

What do you think?

flosell commented 2 years ago

I've had a bit of time today so I've tried to make some improvements:

I'm closing this issue for now, feel free to reopen if you feel there's more to be done