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

Docs make importing google_monitoring_alert_policy … hard #19453

Open
roy-work opened this issue Sep 12, 2024 · 2 comments · May be fixed by GoogleCloudPlatform/magic-modules#11831
Open

Docs make importing google_monitoring_alert_policy … hard #19453

roy-work opened this issue Sep 12, 2024 · 2 comments · May be fixed by GoogleCloudPlatform/magic-modules#11831

Comments

@roy-work
Copy link

roy-work commented Sep 12, 2024

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/123456789

If 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

  1. terraform import google_monitoring_alert_policy.…

Important Factoids

No response

References

No response

b/368130892

@roy-work roy-work added the bug label Sep 12, 2024
@github-actions github-actions bot added forward/review In review; remove label to forward service/monitoring-alerting labels Sep 12, 2024
@ggtisc ggtisc self-assigned this Sep 18, 2024
@hao-nan-li
Copy link
Collaborator

@ggtisc
Copy link
Collaborator

ggtisc commented Sep 18, 2024

Confirmed issue!

After following the steps and checking out in the documentation and in the @hao-nan-li shared link results very complicated to import this resource and the terraform registry documentation doesn't help so much.

@ggtisc ggtisc removed their assignment Sep 18, 2024
@ggtisc ggtisc added documentation and removed bug forward/review In review; remove label to forward labels Sep 18, 2024
z-nand added a commit to z-nand/magic-modules that referenced this issue Sep 26, 2024
Adds support for severity options in AlertPolicy.

I acknowledge that I have:

Searched through the issue tracker for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
Ensured that all new fields I added that can be set by a user appear in at least one example (for generated resources) or third_party test (for handwritten resources or update tests).
Generated Terraform providers, and ran make test and make lint in the generated providers to ensure it passes unit and linter tests.
Ran relevant acceptance tests using my own Google Cloud project and credentials (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
Read the Release Notes Guide before writing my release note below.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants