0.10.7, 0.9.11
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
}
The policy was applied
1 error(s) occurred:
* aws_iam_policy.nodes_sqs_policy: "policy" contains an invalid JSON policy
According to RFC 4627, "Insignificant whitespace is allowed before or after any of the six structural characters."
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
}
Terraform #11906 is where the JSON validation was applied.
Adding this here as docs but this can cause bugs on resources that depend on this policy and the warning is extremely disconcerting.
The example would be if you have an aws_iam_role_policy_attachment depend on your policy it will tell you that the policy does not exist.
I came across this today as well. This is a bug right?
policy = <<CONFIG
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::our-org-secrets",
"arn:aws:s3:::our-org-secrets/*"
]
}
]
}
CONFIG
"policy" contains an invalid JSON policy
Also affects terraform 0.11.4, aws provider 1.13.0
+1 I encountered this as well
+1
+1 Same issue for me.

I finally had a minute to write https://github.com/terraform-providers/terraform-provider-aws/pull/5887 but I don't currently have an environment I can run acceptance tests in. If someone can pull my branch, run make testacc TEST=./aws TESTARGS='-run=TestAccAWSLaunchTemplate_', and post results in the PR thread, that might help get this merged.
I found a donor account, test results are added.
馃憤
As a workaround on using the ugly JSON inline Heredoc, the aws_iam_policy_document data source works great, HCL to JSON transformer.
Most helpful comment
I finally had a minute to write https://github.com/terraform-providers/terraform-provider-aws/pull/5887 but I don't currently have an environment I can run acceptance tests in. If someone can pull my branch, run
make testacc TEST=./aws TESTARGS='-run=TestAccAWSLaunchTemplate_', and post results in the PR thread, that might help get this merged.