Hi,
I’ve run into a challenge with mutually exclusive dynamic blocks… specifically, I’m setting up a shared module for AWS S3 Redirect buckets - which is using the aws_s3_bucket_website_configuration resource.
This resource has 2 useful possible argument blocks:
routing_rule
(conflicts withrouting_rules
)routing_rules
(conflicts withrouting_rule
)
I was hoping to do something like this:
resource "aws_s3_bucket_website_configuration" "redirect" {
...
...
dynamic "routing_rule" {
for_each = var.routing_rule
content {
...
}
}
dynamic "routing_rules" {
for_each = var.routing_rules
content {
...
}
}
}
…where in any given case either routing_rule
or routing_rules
is set - but not both. The default value for both is []
.
But even with one set, I see this error:
Blocks of type "routing_rules" are not expected here.
I think perhaps the routing_rules
block is being “initialised” - even though the variable is not set and hence no rules would be deployed.
I can see a possible workaround to have two separate resources (one for rule
and one for rules
).
But does anyone know of a way to do this within one resource? Or a better way?
Thanks,
Gareth