Skip to content

Commit 31cc5d7

Browse files
authored
fix: Resolve unsupported attribute error in S3 website block (#358)
* fix: Resolve unsupported attribute error in S3 website block Resolves #354 * chore: Comment updates
1 parent 934d4f2 commit 31cc5d7

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

examples/complete/website.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module "website_default" {
2+
source = "../../"
3+
4+
namespace = var.namespace
5+
stage = var.stage
6+
name = var.name
7+
8+
// Distinguish this module instance from the one in main.tf and prevent S3 bucket name collisions
9+
attributes = concat(var.attributes, ["website"])
10+
11+
cloudfront_access_logging_enabled = false
12+
13+
website_enabled = true
14+
15+
context = module.this.context
16+
}
17+
18+
module "website_redirect_all" {
19+
source = "../../"
20+
21+
namespace = var.namespace
22+
stage = var.stage
23+
name = var.name
24+
25+
// Distinguish this module instance from the one in main.tf and prevent S3 bucket name collisions
26+
attributes = concat(var.attributes, ["website-redirect-all"])
27+
28+
cloudfront_access_logging_enabled = false
29+
30+
website_enabled = true
31+
redirect_all_requests_to = "https://cloudposse.com"
32+
33+
context = module.this.context
34+
}

main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,12 @@ resource "aws_s3_bucket" "origin" {
319319

320320
dynamic "website" {
321321
for_each = var.website_enabled ? local.website_config[var.redirect_all_requests_to == "" ? "default" : "redirect_all"] : []
322+
# The lookup is needed to safely access optional website config keys, since locals defines 2 distinct flavours of website config
322323
content {
323-
error_document = website.value.error_document
324-
index_document = website.value.index_document
325-
redirect_all_requests_to = website.value.redirect_all_requests_to
326-
routing_rules = website.value.routing_rules
324+
error_document = lookup(website.value, "error_document", null)
325+
index_document = lookup(website.value, "index_document", null)
326+
redirect_all_requests_to = lookup(website.value, "redirect_all_requests_to", null)
327+
routing_rules = lookup(website.value, "routing_rules", null)
327328
}
328329
}
329330
}

0 commit comments

Comments
 (0)