Terraform: Bug: leading whitespace causes aws_iam_policy to incorrectly report valid JSON policies as invalid

Created on 12 Oct 2017  ยท  6Comments  ยท  Source: hashicorp/terraform

Terraform Version

0.10.7, 0.9.11

Terraform Configuration Files

resource "aws_iam_policy" "nodes_sqs_policy" {
    name        = "nodes_sqs_policy"
    description = "nodes SQS"
    policy = <<EOF
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "sqs:GetQueueAttributes"
          ],
          "Resource": [
            "arn:aws:sqs:us-east-1:123123123:myapp-dev-us-east-1*"
          ]
        }
      ]
    }
EOF
}

Expected Behavior

The policy was applied

Actual Behavior

1 error(s) occurred:

* aws_iam_policy.nodes_sqs_policy: "policy" contains an invalid JSON policy

Important Factoids

Removing the whitespace before the first character in the policy allows it to be applied:

data "template_file" "nodes_iam_sqs" {
    name        = "nodes_sqs_policy"
    description = "nodes SQS"
    policy = <<EOF
{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "sqs:GetQueueAttributes"
          ],
          "Resource": [
            "arn:aws:sqs:us-east-1:123123123:myapp-dev-us-east-1*"
          ]
        }
      ]
    }
EOF
}

According to RFC 4627, "Insignificant whitespace is allowed before or after any of the six structural characters."

References

11906 is where the JSON validation was applied.

Most helpful comment

The AWS provider has moved out of the main terraform repo, and this bug report has moved here: https://github.com/terraform-providers/terraform-provider-aws/issues/1873

All 6 comments

Aaand this is in the wrong repo.

just ran into this issue, thanks

lame. Can we please fix? Thanks

The AWS provider has moved out of the main terraform repo, and this bug report has moved here: https://github.com/terraform-providers/terraform-provider-aws/issues/1873

I had the same problem and got it fixed by removing all the spaces before the left curly brace that is immediately after the <

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings