If you ever get unsupported attribute error when using redirect_all_requests_to
as part of terraform-aws-modules/s3-bucket/aws public module with a similar config
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "3.10.1"
bucket = "mybucket"
website = {
redirect_all_requests_to = "https://cloud.google.com"
}
}
╷
│ Error: Unsupported attribute
│
│ on .terraform/modules/s3_bucket/main.tf line 106, in resource "aws_s3_bucket_website_configuration" "this":
│ 106: host_name = redirect_all_requests_to.value.host_name
│ ├────────────────
│ │ redirect_all_requests_to.value is "https://cloud.google.com"
│
│ Can't access attributes on a primitive-typed value (string).
╵
Replace website
config block with the following:
website = {
redirect_all_requests_to = {
host_name = "https://cloud.google.com"
}
}
1 Like
Thanks for sharing what you learned, @AlexPerkbox!
Unfortunately this poor error message seems to result from this module using an insufficiently-precise type constraint for the input variable website
:
This type constraint is clearly incorrect because we can see from your error message that the module does not actually accept “a value of any type” here: the module expects an object with several specific attributes, and fails if the given value is not an object type with those attributes. The comment saying map(string)
is also clearly incorrect because you noticed that at least one of the attributes is supposed to be a nested object, not a string.
It may be worth sharing this feedback with the maintainers of the module. I don’t know if they’ll be able to improve this now without risking backward compatibility, but a more correct type constraint for this input variable would look something like this:
type = object({
index_document = optional(string)
error_document = optional(string)
redirect_all_requests_to = optional(object({
host_name = string
protocol = string
}))
# etc...
})
If the variable’s type had been specified correctly then Terraform would have given you better feedback about the fact that redirect_all_requests_to
is supposed to be an object rather than a string, rather than this less helpful error message with the module internally trying to access an attribute it didn’t actually declare that it needed.