Closed alexeyauslender closed 1 year ago
Any comments on that? We had to go down the ARM template route, because the TF resource is unusable in its current state and for the web test purpose.
Thanks for opening this issue. This was a problem in the 2.x version of the provider which is no longer actively maintained. If this is still an issue with the 3.x version of the provider please do let us know by opening a new issue, thanks!
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Community Note
Terraform (and AzureRM Provider) Version
Terraform v0.13.5 provider registry.terraform.io/hashicorp/azurerm v2.31.0
Affected Resource(s)
azurerm_monitor_metric_alert
Terraform Configuration Files
Debug Output
In fiddler I can see the following payloads sent to Azure api by terraform First alert metric is created properly with webtest as a target, please notice that in 'scopes' test appears to be the first resource
Second is created wrong with Appinsights as the target, please notice that in 'scopes' Appinsights appears to be the first resource
Third is created wrong with Appinsights as the target, please notice that in 'scopes' Appinsights appears to be the first resource
Panic Output
Expected Behaviour
Create the metric alert for each web test in the list. The availability test should be a target resource in created metric alert.
Actual Behaviour
Some metric alerts created with an Appinsights as a target and some with an availability test resource as a target.
Steps to Reproduce
terraform apply
Important Factoids
References
I think the problem is with 'scopes' argument implementation, which uses hash set data structure instead of using array. Unit test that I am referencing here, works accidently, exactly as a first metric alert created by my code. When the api call make by terraform happens, the first resource in a scope is test and the second is Appinsights. If the hash set order would be different, the result would be the same as mine (for two resources that were created botched) and Appinsights would be a target resource in created metric alert. https://github.com/terraform-providers/terraform-provider-azurerm/blob/1f316b3c34ce16bc423bb87691fb8c5f3c4a7955/azurerm/internal/services/monitor/tests/monitor_metric_alert_resource_test.go#L474