Issue Description
While importing a manually created azure monitor metric alert in terraform, a case sensitivity issue is encountered where,
- Azure requires the resource type in the Web Test ID to be webtests (lowercase).
- However, Terraform modifies the ID to webTests (PascalCase), which leads to a terraform plan failure.
Creation of these new Alerts and Web test via terraform works fine without issues.
Example Behaviour
Terraform modifies the Web Test ID from:
~ web_test_id = "/subscriptions/<your-sub-id>/resourceGroups/<your-resource-group>/providers/Microsoft.Insights/webtests/tf-test-appinsights-webtest"
-> "/subscriptions/<your-sub-id>/resourceGroups/<your-resource-group>/providers/Microsoft.Insights/webTests/tf-test-appinsights-webtest"
This results in the following error during terraform plan:
Error: ID was missing the 'webTests' element
Impact
This case sensitivity mismatch prevents Terraform from managing Azure Monitor metric alerts effectively, even when the correct Web Test ID (with webtests) is provided.
Cause
- This error is typically observed with older versions of the azurerm provider used within the configuration.
Solutions:
- Please ensure that the latest version of the azurerm provider is used, since the latest version would have all the major bugs and fixes addressed already.
-
With the latest version, importing the manually created resource into terraform will give the case sensitive drift on the web_test_id (webtests -> webTests), try applying the drift, and you shouldn't receive any errors during terraform apply. Applying this drift shall have no issues on the alert resource.
# azurerm_monitor_metric_alert.example will be updated in-place
~ resource "azurerm_monitor_metric_alert" "example" {
name = "alerttesting"
.
.
# (6 unchanged attributes hidden)
~ application_insights_web_test_location_availability_criteria {
failed_location_count = 2
~ web_test_id = "/subscriptions/<your-sub-id>/resourcegroups/<your-resource-grp>/providers/microsoft.insights/webtests/alerttesting-tf-test" -> "/subscriptions/<your-sub-id>/resourceGroups/<your-resource-grp>/providers/Microsoft.Insights/webTests/alerttesting-tf-test"
}
}
Plan: 0 to add, 1 to change, 0 to destroy.
Additional Information
- Details about the supported attributes for resource
azurerm_monitor_metric_alert can be found here on our official documentation.
If you are still not able to solve your issue, please reach out HCP Terraform support at
tf-cloud@hashicorp.support or submit a ticket via our support portal.