Hello.
I’m facing a case where an existing resource can have 2 different names, depending on an installed software version. I need to use this resource as a data source.
My issue is with a openstack_identity_role_v3 data source but I guess that if such a way exists, it would be the same for any provider.
The interpretations of the arguments to data sources are entirely up to the provider implementing the data source, so there’s unfortunately no general answer here. The capabilities of the data sources tend to be reflective of and restricted to whatever vendor API they are wrapping.
Unless the data source supports an “OR”-type query (and it looks like this one does not), I think the closest you could get here is to use a conditional expression in the data source configuration and determine some other way which installed software version a particular instance of your module is using, to know which of the two names to choose:
data "openstack_identity_role_v3" "example" {
name = local.example ? "name_a" : "name_b"
}
I used local.example here as a placeholder for some expression that returns a different result depending on the installed software version you mentioned. If that version number you need to make the decision isn’t already determined somewhere else in the Terraform configuration then you’d need to either arrange for it to be published somewhere that Terraform can read with some other data source, or set it via an input variable which you’d then need to set explicitly.
Thanks @apparentlymart. I didn’t think of this ternary syntax. I don’t see a data source that could help me, so I’ll resort to use an external variable.