-
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
Impossible to loop in lambda_function inside aws_s3_bucket_notification #14589
Comments
I have exactly this use-case but for a separate purpose: I have a Cloudfront distribution, in which I need about 30 different path patterns with identical caching behavior. I would like to be able to simply say Are there any possible workarounds at this time? |
Since Terraform configurations are HCL, and it's pretty easy to convert HCL to JSON and back, I'm thinking that writing a small script to generate the Terraform configuration is my only recourse (other than backpedaling and going back to Cloudformation). What I did was create a file, which was the list of path names I needed, and then mutate a partial Terraform configuration (a valid portion of the Terraform configuration for the "cache behaviors" section), and append all of them to a file. Finally, I dropped the (very long) result into the Terraform configuration. This was easier than handwriting it, but still results in a very long template. I'm thinking I might be able to create a module for the cache behaviors or something, so I can at least put all of the generated code in a separate file so that the original Terraform configuration is a little easier to digest. I used https://github.com/kvz/json2hcl to serde JSON/HCL. cat one-value-per-line.txt | while read pattern ; do cat partial-tf-config.tf | json2hcl -reverse | jq '.cache_behavior[].path_pattern = "'$pattern'"' | json2hcl | tee -a generated-config.tf ; done
terraform fmt generated-config.tf |
Hi @JulesDT! Sorry for the long silence here. This issue is covering the same use-case as #7034, which we've now resolved due to a new feature in master ready for the forthcoming v0.12.0 release. I left a comment over there showing how the new feature can be used. Thanks for reporting this, and sorry again for the delay in responding. |
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. |
Terraform Version
Terraform v0.9.4
Affected Resource(s)
Terraform Configuration Files
Two different syntax tested (first one valid doing the somehow expected behavior but not the wanted behavior, second one being the one we want that doesn't exist)
Debug Output
N/A
Panic Output
N/A
Expected Behavior
I would expect each lambda to be added to the bucket notification.
Actual Behavior
Actually, because
aws_s3_bucket_notification
is unique for each bucket, each loop iteration rewrites the iteration before.The second syntax just says that
count
is an unknown parameter forlambda_function
.Steps to Reproduce
terraform apply --parallelism=1
Important Factoids
account-admin
role is used so everything should be fineReferences
Thanks for the help, I am still available for precisions if necessary
The text was updated successfully, but these errors were encountered: