Closed awinter125 closed 3 years ago
Hello @awinter125
Do you have a sample code to share ? What kind of resources are you trying to configure ?
Hi @BzSpi ,
sure.
` data "azurerm_resources" "this" { resource_group_name = "myresourcegroupid" }
module "diagnostic-settings" { for_each = { for index, item in data.azurerm_resources.this.resources: index => item }
source = "claranet/diagnostic-settings/azurerm"
resource_id = each.value.id
logs_destinations_ids = [ azurerm_storage_account.logs.id, azurerm_log_analytics_workspace.example.id, azurerm_eventhub_authorization_rule.logs.id, ]
log_analytics_destination_type = "Dedicated"
} `
Basically the module is called on every ressource id in the given resource group. The module then tries to get the categories with azurerm_monitor_diagnostic_categories datasource in r-diagnostic.tf. If the resource does not support diagnostic settings, the datasource will fail, thus terraform. I was just looking for a smart way to set diagnostics on all resources instead of having to define it for every resource individually.
I don't think this is possible with the current version of Terraform and the Azure provider. I would suggest you to write a bash script with Azure CLI with error management in order to have this behavior. https://docs.microsoft.com/en-us/cli/azure/monitor/diagnostic-settings?view=azure-cli-latest
This module is more intended to be used with resources already declared in Terraform.
@BzSpi - you are right, i figured that. I just was a bit mislead by your example in the readme and thought maybe i missed something. Anyway - thanks for answering!
Tanks for the module. In the example code you try to iterate over the list of all resources and enable the diagnostic settings. This actually would be really useful. Unfortunately the datasource throws an error on each resource not supporting diagnostic settings and afaik there is no way to set the datasource to ignore errors or return an empty result instead. Any solutions to this?