Created
September 24, 2025 22:44
-
-
Save matt-FFFFFF/c26482d7afe8bf4db8cb952b463ccd9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource "azapi_resource" "diagnostic_settings" { | |
| for_each = local.diagnostic_settings_azapi | |
| type = local.diagnostic_settings_type | |
| name = each.value.name | |
| parent_id = var.this_resource_id | |
| body = each.value.body | |
| ignore_null_property = true | |
| lifecycle { | |
| ignore_changes = [body.properties.logs, body.properties.metrics] | |
| } | |
| } | |
| data "azapi_resource" "diagnostic_settings" { | |
| for_each = azapi_resource.diagnostic_settings | |
| type = each.value.type | |
| resource_id = each.value.id | |
| response_export_values = { | |
| metrics = "properties.metrics" | |
| logs = "properties.logs" | |
| } | |
| } | |
| locals { | |
| combined_metrics = { | |
| for k, v in data.azapi_resource.diagnostic_settings : k => distinct( | |
| concat( | |
| coalescelist(v.response_export_values.metrics, []), | |
| coalescelist(local.metrics_supplied[k], []) | |
| ) | |
| ) | |
| } | |
| combined_logs = { | |
| for k, v in data.azapi_resource.diagnostic_settings : k => distinct( | |
| concat( | |
| coalescelist(v.response_export_values.logs, []), | |
| coalescelist(local.logs_supplied[k], []) | |
| ) | |
| ) | |
| } | |
| } | |
| resource "azapi_update_resource" "diagnostic_settings" { | |
| for_each = data.azapi_resource.diagnostic_settings | |
| resource_id = each.value.id | |
| type = each.value.type | |
| body = { | |
| properties = { | |
| metrics = local.combined_metrics[each.key] | |
| logs = local.combined_logs[each.key] | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This method doesn't care about duplicate items if there is a attribute that is effectively a key. If you have this scenario then you need to do something more complex.