-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: leading whitespace causes aws_iam_policy to incorrectly report valid JSON policies as invalid #1873
Comments
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
|
Also affects terraform 0.11.4, aws provider 1.13.0 |
+1 I encountered this as well |
#trim |
+1 |
+1 Same issue for me. |
I finally had a minute to write #5887 but I don't currently have an environment I can run acceptance tests in. If someone can pull my branch, run |
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. |
Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you! |
Can be in a stale state, but it's still a bug 😄 |
OMG!! Just a small whitespace in starting is stopping!!! harsh |
|
Even with jsonencode, it's giving me MalformedPolicyDocument: JSON strings must not have leading spaces |
FWIW I have switched almost exclusively to the aws_iam_policy_document data resources for these policies. JSON blocks cause more trouble than they are worth. Here is a very hand utility you can use to generate them from the json policy themselves in more or less one line with echo. https://github.com/flosell/iam-policy-json-to-terraform |
Any updates on this? |
Indented heredoc should work here: instead of ref: https://developer.hashicorp.com/terraform/language/expressions/strings#indented-heredocs |
Warning This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them. Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed. |
This functionality has been released in v5.43.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
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. |
Terraform Version
0.10.7, 0.9.11
Affected Resource(s)
Terraform Configuration Files
Expected Behavior
The policy was applied
Actual Behavior
Important Factoids
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:
References
Terraform #11906 is where the JSON validation was applied.
The text was updated successfully, but these errors were encountered: