Search code examples
terraformterraform-provider-azureazure-rm

What is a good way to design Terraform code so that I can create many web applications with the same default settings, then customize a handful?


I have about 20 web applications that are created the azurerm_windows_function_app resource. These web applications all generally have the same configuration. But two of them will have virtual applications defined. Ideally, I would like to some how define these virtual applications better than what I'm currently doing while maintaining the for_each loop I use to generate these resources. I make use of a module that defines all of the default settings and call that module in the main.tf.

Currently, I'm using azurerm_resource_group_template_depoyment to apply the virtual applications because setting the virtual application was not possible in older versions of the azurerm provider. But now this capability is available with the azurerm_windows_function_app and would like to make use of it.

I'm honestly not sure if there is a design pattern I'm not familiar with to achieve this, or if I am still required to use the azurerm_resource_group_template_deployment resource.


Solution

  • I would create all the needed variables separately in the module variable file, and give the a default value, the value most of the resources need. Then, I'd make a set or map of objects, which will each represent a web app, where you only put values for webapps that need others than the default. If no value is present, the webapp will be created with the default values.