Me and my colleague are setting up a new code and sort of template for an Application Gateway in Azure.
We mostly use locals and dynamic blocks, because there will be a lot of similar/repeatative objects.
Below it’s a block for backend settings and cookie_based_affinity is there manually defined as “Disabled”. However I would need this setting to have a “Default value” which can be “Disabled” and then to have an option to override the value to “Enabled”.
If we could make it working within the dynamic block that would be preferred. However going somehow around it using locals or even variable.tf is also an option.
I think you have some options here. It may depend how you want to do the override, and what the input looks like, but I think you should be able to do something like
# In this case, you're using a boolean within that data structure to set or unset it
cookie_based_affinity = backend_http_settings.value.cookie_based_affinity ? "Enabled" : "Disabled"
If this works for your use case, I think that’s the simplest and also the cleanest, since you’re using a boolean to control it.
You might also look at using try() in certain situations, like try(backend_http_settings.value.cookie_based_affinity, "Disabled") (in this case, I think it would have to be the value “Enabled” vs. a boolean).
Or you can merge two data structures (i.e., merge defaults with your list of objects) in such a way that you can have default settings.
Thank you, I will try it for sure. Tho’ not sure whether that’s going to work, because when I change it on a dynamic block level, it will use the same value for each local. Which is not what I would like to use. Or at least from those adjustments that I tried it worked like that. But I think I didn’t try any similar to yours.
See the SO link - it should be possible to define defaults if you want. One way would be to merge the defaults with each item in the list, but I think there should be a cleaner way too.
If you show an example of how the data structure you’re passing into that looks, someone might be able to provide a little more help as to how else you could do it.