I’m wondering if it’s possible to have a root level resource be defined conditionally based on a variable.
Something like this:
dynamic "aws_eip" "public_ip" {
for_each = var.has_eip == ? [] : [1]
content {
vpc=true
network_interface = "xyz"
}
}
resource "aws_instance" "inst1" {
...
}
But it seems to have no effect, and the eip is not created.
Hi @suenchunhui,
That feature is not yet implemented. You can track its progress by following the following GitHub issue:
However, from your example it seems like you just want to conditionally switch between zero and one instances depending on a variable, in which case you can do that using count
:
dynamic "aws_eip" "public_ip" {
count = var.has_eip == ? 0 : 1
vpc = true
network_interface = "xyz"
}