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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing an existing azurerm_monitor_metric_alert resource does not fetch all fields #7560

Closed
xsreality opened this issue Jul 2, 2020 · 4 comments

Comments

@xsreality
Copy link

xsreality commented Jul 2, 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.12.25

  • provider.azurerm v2.16.0

Affected Resource(s)

  • azurerm_monitor_metric_alert

Terraform Configuration Files

resource "azurerm_monitor_metric_alert" "example" {
  name = "example-alert"
  resource_group_name = azurerm_resource_group.traffic_manager_rg.name
  scopes = [azurerm_traffic_manager_profile.example.id]
  description = "Traffic Manager Endpoint Status by Endpoint"
  severity = 2

  criteria {
    aggregation = "Average"
    metric_name = "ProbeAgentCurrentEndpointStateByProfileResourceId"
    metric_namespace = "Microsoft.Network/trafficManagerProfiles"
    operator = "LessThan"
    threshold = 1
  }

  tags = {}

  action {
    action_group_id = azurerm_monitor_action_group.action_group_team.id
  }
}

Expected Behavior

When importing existing resource of type azurerm_monitor_metric_alert, all fields including name, criteria and action should be imported.

Actual Behavior

Only id, resource_group_name and tags are imported. Below is output of terraform state show ...:

resource "azurerm_monitor_metric_alert" "example" {
    id                  = "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Insights/metricalerts/example-alert"
    resource_group_name = "..."
    tags                = {}

    timeouts {}
}

Steps to Reproduce

  1. Create an Azure Monitor metric alert beforehand via Portal or Azure CLI.
  2. Import the resource in terraform.
  3. Check the imported state, many fields will be missing.
@wenesak
Copy link

wenesak commented Jul 2, 2020

same here, I was trying to import some existing "metric alerts" and got the same problem as xsreality.

@magodo magodo self-assigned this Jul 6, 2020
@magodo
Copy link
Collaborator

magodo commented Jul 6, 2020

@xsreality Thank you for submitting this!

This should be fixed by #7159.

Clarification

As the description of the PR #7159 said:

Previous code was using the SingleResourceMultipleMetricCriteria, while this is superseded by MultipleResourceMultipleMetricCriteria.

In your case the metric of the target resource azurerm_traffic_manager_profile might be a MultipleResourceMultipleMetricCriteria if you are calling via a newer API version or the criteria itself is a Dynamic criteria (you can tell via looking at the field properties.criteria.odata.type from the response body), which is omit in current code.

@magodo magodo added the bug label Jul 6, 2020
@magodo
Copy link
Collaborator

magodo commented Aug 4, 2020

I'm gonna close this issue as #7159 has been merged now. If the issue still exists, please feel free to reopen this issue.

@magodo magodo closed this as completed Aug 4, 2020
@ghost
Copy link

ghost commented Sep 3, 2020

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 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Sep 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants