hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.53k stars 4.6k forks source link

Error: Provider produced inconsistent result after apply when creating azurerm_monitor_activity_log_alert #20182

Open ooteniya opened 1 year ago

ooteniya commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

0.12.31

AzureRM Provider Version

3.39.0

Affected Resource(s)/Data Source(s)

Terraform Configuration Files

Basic use of azurerm_monitor_activity_log_alert

Debug Output/Panic Output

provider "registry.terraform.io/-/azurerm" produced an unexpected new value
for was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Expected Behaviour

Terraform should be able to create the resource group then action group and finally alert rules from scratch without running into issues

Actual Behaviour

After creating the resource group, action group and it starts creating the 13 alert rules, it fails on a different alert rules every time we retry it with the following error:

When applying changes to
...azurerm_monitor_activity_log_alert.activity_log_alert["example_alert"],
provider "registry.terraform.io/-/azurerm" produced an unexpected new value
for was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Note: example_alert alert rule is actually created in Azure, but is absent from the terraform state This looks very similar to #10371 but with different resources

Steps to Reproduce

Deploy 1 resource group, 1 action group, 50 alert rules. sometimes it succeeds sometimes fails

Important Factoids

No response

References

10371

teowa commented 1 year ago

Hi @ooteniya , thanks for submitting the issue! I tried to reproduce the was present, but now absent error with below config, but seems I can't. Could you please provide some detailed config to reproduce the error? Or some screenshot of json view of the activity log alert from Portal.

TF config ```hcl provider "azurerm" { features {} } resource "azurerm_resource_group" "test" { name = "testRG" location = "westeurope" } resource "azurerm_monitor_action_group" "test1" { name = "acctestActionGroup1" resource_group_name = azurerm_resource_group.test.name short_name = "acctestag1" } resource "azurerm_monitor_action_group" "test2" { name = "acctestActionGroup2" resource_group_name = azurerm_resource_group.test.name short_name = "acctestag2" } resource "azurerm_storage_account" "test" { name = "teststestsa" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_monitor_activity_log_alert" "test" { name = "acctestActivityLogAlert" resource_group_name = azurerm_resource_group.test.name enabled = true description = "This is just a test acceptance." scopes = [ azurerm_resource_group.test.id, azurerm_storage_account.test.id, ] criteria { category = "ResourceHealth" operation_name = "Microsoft.Storage/storageAccounts/write" resource_provider = "Microsoft.Storage" resource_type = "Microsoft.Storage/storageAccounts" resource_group = azurerm_resource_group.test.name resource_id = azurerm_storage_account.test.id recommendation_category = "OperationalExcellence" recommendation_impact = "High" level = "Critical" status = "Updated" sub_status = "Updated" resource_health { current = ["Degraded", "Unavailable", "Unknown"] previous = ["Available"] reason = ["PlatformInitiated", "Unknown"] } } action { action_group_id = azurerm_monitor_action_group.test1.id } action { action_group_id = azurerm_monitor_action_group.test2.id webhook_properties = { from = "terraform test" to = "microsoft azure" } } } ```
davidsloyer commented 1 year ago

Experiencing the same issue

Resource_type: azurerm_monitor_activity_log_alert

Reproduce:
Error occurs randomly when deploying Activity Log Alert Rules Resources are successfully deployed, but post-apply result fails and redeploy is not allowed because the resource already exists.

Occuring in TF version: 1.4.5, 1.4.6 and 1.5.1 (tested all)

Azurerm provider version: 3.59.0 and 3.61.0 tested

Raw Log: " 2023-06-27T17:56:27.1599272Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [20s elapsed] 2023-06-27T17:56:37.1600914Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [30s elapsed] 2023-06-27T17:56:47.1602589Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [40s elapsed] 2023-06-27T17:56:57.1604093Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [50s elapsed] 2023-06-27T17:57:07.1611172Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [1m0s elapsed] 2023-06-27T17:57:17.1612916Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [1m10s elapsed] 2023-06-27T17:57:27.1621752Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [1m20s elapsed] 2023-06-27T17:57:37.1630906Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [1m30s elapsed] 2023-06-27T17:57:47.1632734Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [1m40s elapsed] 2023-06-27T17:57:57.1639991Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [1m50s elapsed] 2023-06-27T17:58:07.1650755Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [2m0s elapsed] 2023-06-27T17:58:11.6111052Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Creation complete after 2m5s [id=/subscriptions/d952b48a-3183-48cf-8a23-8c6f7f5a302f/resourceGroups/rg-monitoringinfra-prd-eus2/providers/Microsoft.Insights/metricAlerts/mma-infra-virtualmachines-percentage-cpu-average-greaterthan-95-it-mgmt-prd] 2023-06-27T17:58:11.6581002Z 2023-06-27T17:58:11.6581675Z Error: Provider produced inconsistent result after apply 2023-06-27T17:58:11.6581921Z 2023-06-27T17:58:11.6582123Z When applying changes to 2023-06-27T17:58:11.6582437Z module.monitor_activity_log_alert["mala01"].azurerm_monitor_activity_log_alert.mala, 2023-06-27T17:58:11.6582683Z provider "provider[\"registry.terraform.io/hashicorp/azurerm\"].monitoring" 2023-06-27T17:58:11.6582881Z produced an unexpected new value: Root resource was present, but now absent. 2023-06-27T17:58:11.6582978Z 2023-06-27T17:58:11.6583401Z This is a bug in the provider, which should be reported in the provider's own 2023-06-27T17:58:11.6583552Z issue tracker. 2023-06-27T17:58:11.7126931Z ##[error]Terraform command 'apply' failed with exit code '1'.: Provider produced inconsistent result after apply 2023-06-27T17:58:11.7161003Z ##[error] Error: Provider produced inconsistent result after apply

When applying changes to module.monitor_activity_log_alert["mala01"].azurerm_monitor_activity_log_alert.mala, provider "provider[\"registry.terraform.io/hashicorp/azurerm\"].monitoring" produced an unexpected new value: Root resource was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own issue tracker.

2023-06-27T17:58:11.8153744Z ##[section]Finishing: Deploy: Terraform Apply "

davidsloyer commented 1 year ago

Experiencing the same issue

Resource_type: azurerm_monitor_activity_log_alert

Reproduce: Error occurs randomly when deploying Activity Log Alert Rules Resources are successfully deployed, but post-apply result fails and redeploy is not allowed because the resource already exists.

Occuring in TF version: 1.4.5, 1.4.6 and 1.5.1 (tested all)

Azurerm provider version: 3.59.0 and 3.61.0 tested

Raw Log: " 2023-06-27T17:56:27.1599272Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [20s elapsed] 2023-06-27T17:56:37.1600914Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [30s elapsed] 2023-06-27T17:56:47.1602589Z module.monitor_metric_alert["mma01"].azurerm_monitor_metric_alert.mma: Still creating... [40s elapsed] ...

Alert Rule category: VM Resource health

Scope: All Virtual Machines in Subscription

resource_type = "Microsoft.Compute/virtualMachines" operation_name = "Microsoft.Resourcehealth/healthevent/Activated/action"

Other Activity_Log_Alert_Rules deployed successfully

The Alert Rule resource for VM Resource health was deployed successfully and functional in Azure, but the task did not complete in the terraform log and was not written to the state file.

Workaround (3 successful tests on different subscriptions):

Possibly a timing issue?