-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Error when using a template as the policy for an s3 bucket #3076
Comments
Just ran into same issue. Been racking my brain trying to get |
👍 Just ran into this as well. I'll take a look to see if I can spot anything obviously wrong here. |
Just a wild guess, is it due to the In terraform/helper/schema/schema.go Line 922 in 8fdffb6
|
@radeksimko @catsby Any ideas here? |
A partial workaround is to first render the template to your tfstate with something like:
Then you can |
👍 just ran into this, made me think my JSON was bad, head scratched for a while. |
Also observed the above problem today. As an aside, not sure if it's related, but if I: plan The second plan results in a spurious looking "change":
The only difference is the bracketing around "Resource" |
@mrwilby we've seen that as well, but I think it is unrelated to this issue. You can workaround your issue by formatting the JSON in the exact way that AWS formats it in its response (i.e. you should use brackets around your |
@jszwedko Thanks. I actually have the JSON with the brackets. Something inside the terraform codebase (I assume) is doing the conversion with/without brackets. |
Oops! I reversed what you had above, it looks like AWS is storing it sans-brackets -- you can verify by doing a |
Any updates on this issue? |
See hashicorp/terraform#3076 parer error. Cannot use policy template file until this issue is fixed. Use inline syntax instead.
So, I did a compare on what amazon thinks is the policy, and the policy that terraform is pushing, and I got the following:
and
Notice that the Resource elements are in the reverse order! Once I adjusted the ordering I no longer have this issue. I do wish we could have a more semantic compare though... v0.6.13 EDIT: The issue with the above fix is that the ordering returned by AWS is not always the same. So in cases where you are using modules, and have multiple versions, it may not be possible to specify the correct ordering for each instance of the module. |
@dansteen I think your last comment is unrelated to the original bug report with I have a feeling the original report is a core bug that affects other resources using Hopefully will be fixed in #4961 |
getting similar issue with using a template file's rendered output for the policy field for a kms key (I even tried adding the depends_on to see if it would help, it didn't):
|
@radeksimko Sounds reasonable. Looking forward to #4961! |
I'm still hitting this error on 0.6.16. I'm trying to pass my "Resource" value to a template file and hitting the "Error parsing JSON: invalid character '$' looking for beginning of value" |
I'm also getting this error on v0.6.16, it always ask to change but there's no change on the policy. |
The solution at the moment was to split each Action in one statement and keep the "Sid": "", on each... Also, removed all unnecessary brackets. |
@ahaynssen Workaround I found was to add the |
Should fix #3076 but I need to add some tests. :)
Should fix #3076 but I need to add some tests. :)
This is fixed in #4961. |
@mitchellh I'm probably missing something, but it looks like the PR you linked to (#4961) as well as the PR that that one links to as superseding (#6430) were both closed without merging. Were these rebased onto master as other commits? I also see some commits above by @phinze referencing this issue, but these appear to not be yet merged (#7204). |
To close the loop on this, it is no longer a problem if you use the template data source, e.g.: # main.tf
provider "aws" {
region = "us-west-1"
}
data "template_file" "init" {
template = "${file("s3-policy.tpl")}"
}
resource "aws_s3_bucket" "woofound" {
bucket = "12345-soechu-images"
policy = "${data.template_file.init.rendered}"
}
It is still a problem with the normal |
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. |
When I try to use a template as the policy for my s3 bucket:
I get the following message (not an error) when I run "terraform plan --module-depth=1":
However, when I run "terraform apply" everything works fine, and the policy is correctly set on S3.
The text was updated successfully, but these errors were encountered: