Is there a deeper reason, why Terraform is not providing an if-statement to declare resources like this
resource "aws_ssm_parameter" "foo" {
if = var.create_foo # this is not available
name = "foo"
type = "String"
value = "bar"
}
To me this feels like a very common use-case.
I know that one can write
resource "aws_ssm_parameter" "foo" {
count = var.create_foo ? 1 : 0
name = "foo"
type = "String"
value = "bar"
}
but this feels more like a workaround. This is also not the end of the story. In addition to this less readable count-construct, one also needs to refer to the first parameter everywhere else using aws_ssm_parameter.foo[0] everywhere.
So my question is: Why does Terraform not implement such a keyword? Is there a reason this does not fit into the design? Is it just technically complicated to implement and might come some time soon?
I am honestly thinking about writing some kind of terraform-pre-processor which would automatically replace all if-statements by the corresponding count statement as well as all references to this resource with an added [0] (or something slightly more robust). Any reasons that might not be a good idea?
Aucun commentaire:
Enregistrer un commentaire