Best practices: create resources based on condition


i have got two environments, where i want to run the terraform project. The first one is the dev environment, the second one is the stage and production environment). In my szenario i have to create different resources (in azure), as an example think of staticly provided ip addresses.

My idea was to create these resources based on an condition (either an environment variable or based on the azure tenant id). But as I figured out there is no option for these conditions, only to fill variables like a name, a region or something else based on a condition?

Would be very helpful if you could summerize the suggested behavior for that case.

Kind regards

Hi @scs-tec,

You can conditionally create the values in a resource’s for_each expression, which will correspondingly create instances based on those values. If the for_each expression evaluates to an empty map or set, then no instances will be created.