Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_monitor_metric_alert failing to update action block in tfstate file #9891

Open
maonat opened this issue Dec 16, 2020 · 7 comments
Open

Comments

@maonat
Copy link
Contributor

maonat commented Dec 16, 2020

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Terraform v0.14.2
+ provider registry.terraform.io/hashicorp/azuread v1.0.0
+ provider registry.terraform.io/hashicorp/azurerm v2.34.0

Affected Resource(s)

  • azurerm_monitor_metric_alert

Terraform Configuration Files

resource "azurerm_resource_group" "main" {
  name     = "example-resources"
  location = "West US"
}

resource "azurerm_storage_account" "to_monitor" {
  name                     = "examplestorageaccount"
  resource_group_name      = azurerm_resource_group.main.name
  location                 = azurerm_resource_group.main.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_monitor_action_group" "main" {
  name                = "example-actiongroup"
  resource_group_name = azurerm_resource_group.main.name
  short_name          = "exampleact"

  webhook_receiver {
    name        = "callmyapi"
    service_uri = "http://example.com/alert"
  }
}

resource "azurerm_monitor_action_group" "main_second" {
  name                = "example-actiongroup-second"
  resource_group_name = azurerm_resource_group.main.name
  short_name          = "exampleactsec"

  webhook_receiver {
    name        = "callmyapi"
    service_uri = "http://example.com/alert"
  }
}

resource "azurerm_monitor_metric_alert" "example" {
  name                = "example-metricalert"
  resource_group_name = azurerm_resource_group.main.name
  scopes              = [azurerm_storage_account.to_monitor.id]
  description         = "Action will be triggered when Transactions count is greater than 50."

  criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "Transactions"
    aggregation      = "Total"
    operator         = "GreaterThan"
    threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["*"]
    }
  }

  action {
    action_group_id = azurerm_monitor_action_group.main.id
  }

Expected Behaviour

The tfstate file should've been updated with the ID of the secondary action group.

Actual Behaviour

Even if we apply the changes to the .tf main file by setting the secondary action group as "action_group" for the azurerm_monitor_metric_alert resource, tfstate is not being updated in the azurerm_monitor_metric_alert object state in "action" block.

Steps to Reproduce

  1. Create the resource with the first action group set.
  2. Set secondary action group instead of the first one.
  3. terraform apply
  4. Check tfstate file

If this cannot be reproduced:

  1. Create the resource with the first action group set.
  2. Create a third action group and add it through AZ CLI to the alert rule
  3. In tf file, apply changes and replace the first action group with the secondary one
  4. terraform apply

If this cannot be reproduced:

  1. Create the resource with the first action group set.
  2. Delete the action group manually from az cli or azure portal
  3. Replace in main.tf file the action group with the second one
  4. terraform apply (will go in error during apply like below)

Error: Error creating or updating metric alert "name_metric" (resource group "***"): insights.MetricAlertsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="Action Group /subscriptions/***/resourceGroups/... Not found

Important Factoids

I've found this issue because in one of my azurerm_monitor_metric_alert I've got an error while applying changes to it because in the tfstate file it had a very old action group that doesn't exist anymore. I've resolved by setting another existing action group manually in the tfstate file but after changing it to another target action group, the tfstate file wasn't edited at all.

References

@maonat
Copy link
Contributor Author

maonat commented Dec 21, 2020

Hello? Anyone here? The issue is open since 5 days already but nothing has been done yet. Could you please guys support on this?

@maonat
Copy link
Contributor Author

maonat commented Dec 31, 2020

Hello there? This is really something that should be resolved guys, why anyone is taking a look at all to this ticket?

@jonhadfield
Copy link

Issue still exists in 2.61.0 with terraform 1.0.0.
It happily removes and creates, but does not recognise modifications.

@mklettner
Copy link

Issue still exists in 2.69.0 with terraform 1.03
We are using the webhook_properties in the action block and changes are not recognized.
Therefore, we need to recreate all alerts when changing the properties.

@chadmccormick
Copy link

still exists in 2.80.0 with tf 1.0.9. need to be able to update webhook_properties as tags are updated to pass through on raised alert

@upstream-dmahlberg
Copy link

Hi there, it's September 2022, and this issue still exists.

@balcsida
Copy link

FYI, we observe this with version 3.99.0, our plan doesn't contain the new webhook_properties that we added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants