Select arguments from child module

Hi, I could really use some help with this please.

I’m deploying Azure App Services and need to configure diagnostic settings. Diagnostic settings consist of various log categories which vary between App Service Plan SKUs. My main TF module has a variable for the App Service Plan SKU, so that the SKU can be changed using tfvars dependant on environment.

The TF resource azurerm_monitor_diagnostic_setting is used to configure diagnostic settings on any Azure resources, and I’m using it to define the log categories that need to be enabled for the app services. The premium SKUs have log categories that are not available in the basic SKU, e.g “AppServiceFileAuditLogs”. I have to define all of the log categories in the resource so that they are configured if the SKU is premium, but if the SKU is set to basic then terraform complains that:

“StatusCode=400 – Original Error: autorest/azure: Service returned an error. Status=400 Code=“BadRequest” Message=“Category ‘AppServiceFileAuditLogs’ is not supported.””

That makes sense since that category is not supported in the basic SKU.

Currently I have the diagnostic settings configured in a separate module to the app service. Is there any way to be selective about which configuration arguments you pull in from a child module? Or if I put the diagnostic settings in the same module as the app service, is there a way to only use particular configuration arguments when the SKU has a specific value?

Thanks!

Resolved using dynamic blocks.