-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
documentationforward/linkedmmv1-generatorProvider-wide changes to resource templates or other generator changesProvider-wide changes to resource templates or other generator changesservice/terraformsize/stechnical-debt
Milestone
Description
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.
- If an issue is assigned to a user, that user is claiming responsibility for the issue.
- Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.
Terraform Version & Provider Version(s)
Terraform v1.5.7
on darwin_amd64
- provider registry.terraform.io/hashicorp/google v5.23.0
Affected Resource(s)
google_monitoring_alert_policy
Terraform Configuration
resource "google_monitoring_alert_policy" "example" {
project = "example"
display_name = "example-alerts"
combiner = "OR"
conditions {
display_name = "test condition"
condition_threshold {
filter = "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" AND resource.type=\"gce_instance\""
duration = "60s"
comparison = "COMPARISON_GT"
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_RATE"
}
}
}
user_labels = {
foo = "bar"
}
}
Debug Output
No response
Expected Behavior
To be able to import these
Actual Behavior
The docs say to just use {{ name }}, which since these are project-scoped, basically cannot be correct; there must be a project ID in there, somewhere.
In gcloud, there is however a name field:
name: projects/example/alertPolicies/123456789If I attempt to use that, however,
» terraform import 'google_monitoring_alert_policy.example' 'projects/example/alertPolicies/123456789'
google_monitoring_alert_policy.example: Importing from ID "projects/example/alertPolicies/123456789"...
╷
│ Error: project: required field is not set
│
│
╵
The code seems to want a space-separated project ID; if we try that:
» terraform import 'google_monitoring_alert_policy.example' 'example 123456789'
google_monitoring_alert_policy.example: Importing from ID "restricted-ops 123456789"...
google_monitoring_alert_policy.example: Import prepared!
Prepared google_monitoring_alert_policy for import
google_monitoring_alert_policy.example: Refreshing state... [id=example 123456789]
╷
│ Error: Cannot import non-existent remote object
│
│ While attempting to import an existing object to "google_monitoring_alert_policy.example", the provider detected that no object exists with the given id. Only
│ pre-existing objects can be imported; check that the id is correct and that it is associated with the provider's configured region or endpoint, or use "terraform apply"
│ to create a new remote object for this resource.
╵
I was about to submit this bug report and tried one last permutation:
» terraform import 'google_monitoring_alert_policy.example' 'example projects/example/alertPolicies/123456789'
That worked. I think the documentation could probably be better here… and help me understand what name is referring to? (As it doesn't match the name a user supplies in the UI.)
(So, if you're reading this and wondering how to get that string, run,
gcloud alpha monitoring policies list --project $PROJECT_ID
and it's the name field.)
Steps to reproduce
terraform import google_monitoring_alert_policy.…
Important Factoids
No response
References
No response
b/368130892
Metadata
Metadata
Assignees
Labels
documentationforward/linkedmmv1-generatorProvider-wide changes to resource templates or other generator changesProvider-wide changes to resource templates or other generator changesservice/terraformsize/stechnical-debt