-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
OpenTofu Version
None. Currently using Hashicorp Terraform.
Use Cases
We often use count = var.xxxx ? 1 : 0
in various flavours but with the same purpose of determining to create or not create a single resource.
While this is currently supported it means that resources require an indexed reference, and this also means that if you later change something to be conditional then you have a lot of manual state manipulation required.
I'd like to see this natively supported as it would simplify a lot of code.
Attempted Solutions
Workarounds are using count = ...
expressions.
Proposal
Add an additional meta-data atttribute opentofu-options
and a sub-attribute resource-enabled
, for example:
resource "aws_key_pair" "my-key-pair" {
...
opentofu-options {
resource-enabled = var.create-key-pair
}
}
When a resource is not enabled (known at plan time), then any reference to it in the graph becomes invalid and this would prevent a bunch of munging such as coalesce(aws-key_pair.my-key-pair.*.name, "")
or equivalent.
References
enabled
parameter to avoid logical statements incount
hashicorp/terraform#21953 - long thread, lots of motivation, no movement