-
-
Notifications
You must be signed in to change notification settings - Fork 253
fix: error: No more than 1 "s3_origin_config" blocks are allowed #359
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
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes The change is localized to a single dynamic block with straightforward logic. Review effort is minimal due to the targeted nature of the fix, though verification against the reported bug scenario is necessary. Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
main.tf (1)
603-613: Correct fix for s3_origin_config duplication, but consider using[1]for consistency.Wrapping
var.s3_originsin a list ensures the dynamic block creates only ones3_origin_configper origin (by iterating the for_each once), which fixes the Terraform error when multiple S3 origins are configured with origin access identity enabled. The content block correctly references the outer loop'sorigin.value, not the inner loop variable.However, the loop variable from
s3_origin_config.valueis never used, making the wrapping ofvar.s3_originsunnecessary. The similar pattern at line 520 uses[1]instead, which is more idiomatic and clearer about intent.Consider this refactor for consistency and clarity:
dynamic "s3_origin_config" { - for_each = local.origin_access_identity_enabled ? [var.s3_origins] : [] + for_each = local.origin_access_identity_enabled ? [1] : [] content { # the following enables specifying the origin_access_identity used by the origin created by this module, prior to the module's creation: origin_access_identity = (
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
main.tf(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-31T11:46:57.218Z
Learnt from: jwadolowski
PR: cloudposse/terraform-aws-cloudfront-s3-cdn#340
File: main.tf:570-578
Timestamp: 2025-07-31T11:46:57.218Z
Learning: In terraform-aws-cloudfront-s3-cdn module, custom_origin_config in the custom_origins variable was always a required parameter, not optional. CloudFront origins require either custom_origin_config or s3_origin_config but not both, so null was never a valid value for custom_origin_config in custom origins.
Applied to files:
main.tf
🔇 Additional comments (1)
main.tf (1)
603-613: Fix is correct and successfully resolves the Terraform error.The change from
for_each = local.origin_access_identity_enabled ? var.s3_origins : []tofor_each = local.origin_access_identity_enabled ? [var.s3_origins] : []properly eliminates the duplication issue. Wrapping the list in brackets converts multiple iterations over individual origins to a single iteration, ensuring exactly ones3_origin_configblock per origin instead of N² blocks, which complies with CloudFront's constraint.
9670304 to
b615755
Compare
When using multiple s3_origins with origin_access_type set to "origin_access_identity", multiple s3_origin_config blocks were incorrectly created. Fixed to create only one s3_origin_config block.
b615755 to
8266c04
Compare
|
/terratest |
|
This fix looks good to me. Thank you |
|
These changes were released in v1.1.0. |
what
No more than 1 s3_origin_config blocks are allowederror when using multiple S3 origins with origin access identity enabledfor_eachfrom iterating overvar.s3_originsto using[1]to create a singles3_origin_configblockwhy
references
fixes #325
to reproduce error
origin_access_controlwithorigin_access_identityhttps://github.com/Eyjafjallajokull/terraform-aws-cloudfront-s3-cdn/blob/96703043867c986ff3fc1550448118111a9f5659/examples/complete/main.tf#L102
terraform planfails with the above error.