New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
monitor_diagnostic_setting: suppress diff on metric/log against default value #7463
Conversation
The test result of the modified test case: terraform-provider-azurerm on monitor_diag_setting_diffsuppress [$!] took 5m 11s
💤 😡 130 via 🦉 v1.14.4 make testacc TEST=./azurerm/internal/services/monitor/tests TESTARGS="-run='TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspaceDedicated'"
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test ./azurerm/internal/services/monitor/tests -v -run='TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspaceDedicated' -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspaceDedicated
=== PAUSE TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspaceDedicated
=== CONT TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspaceDedicated
--- PASS: TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspaceDedicated (385.52s)
PASS
ok github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/monitor/tests 385.536s |
I tested this a little with the example configuration in the linked issue. After applying the configuration, if I then remove a resource "azurerm_monitor_diagnostic_setting" "test" {
name = "aaa-tbamford-test-api-diagnostics"
target_resource_id = azurerm_api_management.test.id
log_analytics_workspace_id = azurerm_log_analytics_workspace.test.id
log_analytics_destination_type = "Dedicated"
// log {
// category = "GatewayLogs"
// enabled = true
//
// retention_policy {
// enabled = true
// days = 30
// }
// }
// metric {
// category = "Gateway Requests"
// enabled = true
//
// retention_policy {
// enabled = true
// days = 30
// }
// }
} |
Hey @manicminer You're right! |
8dc0d3c
to
00df4bc
Compare
I have switched to using customized diff instead. But because of bug hashicorp/terraform-plugin-sdk#497 in plugin SDK, it is not able to access nested block of type set in CustmoizedDiff now. Let's hold on this PR until that issue being fixed. |
Closing this in favour of hashicorp/terraform-plugin-sdk#497 - once that's fixed we can re-open this and take another look |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks! |
Some resource type (specified by
target_resource_id
) has its own set of diagnostic settings. If the user didn't explicitly specify some of the settings inPUT
request body, the representation of the diag settings will still contain those settings, with the default values (0/disabled). This is not an idempotent API, IMHO.Under this situation, each time user has to specify all the available diagnostic settings of the target resource, even though some of these settings are just contain the default value(0/disbaled). This violates the convention over configuration principle.
This PR adds suppress function for those settings (
metric
andlog
), the function will suppress diff only when the old settings have "net" more elements than the new one, and the delta settings have default value.Test Result
The two failures are not related to this PR, but has its own issue: #7310
Further Thoughts
The implementation of the suppress function is not ideal as it will be called multiple times for the including elements of the
Set
(because the implementation ofSet
in terraform store its elements via a map). This means there will be a little performance penalty.On the other hand, Tom has suggested using a custom hash function, while it seems not fit to fix this issue.
(fix: #7235)