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

Failed to create a resource google_monitoring_alert_policy with documentation.0.subject #18518

Open
umatare5 opened this issue Jun 21, 2024 · 1 comment

Comments

@umatare5
Copy link

umatare5 commented Jun 21, 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.8.5
on darwin_arm64
+ provider registry.terraform.io/hashicorp/google v5.34.0
+ provider registry.terraform.io/hashicorp/google-beta v5.34.0

Affected Resource(s)

google_monitoring_alert_policy

Terraform Configuration

Add documentation.0.subject = "baz" to Example Usage - Monitoring Alert Policy Basic.

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "My Alert Policy"
  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"
  }

  # Add this structure
  documentation {
    subject = "baz"
  }
}

Debug Output

No response

Expected Behavior

Create a resource successfully when run terraform apply.

Actual Behavior

terraform apply fails because API returns status code 400 as follows:

$ terraform apply
<snip>

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # google_monitoring_alert_policy.alert_policy will be created
  + resource "google_monitoring_alert_policy" "alert_policy" {
      + combiner        = "OR"
      + creation_record = (known after apply)
      + display_name    = "My Alert Policy"
      + enabled         = true
      + id              = (known after apply)
      + name            = (known after apply)
      + project         = "<masked>"

      + conditions {
          + display_name = "test condition"
          + name         = (known after apply)

          + condition_threshold {
              + comparison = "COMPARISON_GT"
              + duration   = "60s"
              + filter     = "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" AND resource.type=\"gce_instance\""

              + aggregations {
                  + alignment_period   = "60s"
                  + per_series_aligner = "ALIGN_RATE"
                }
            }
        }

      + documentation {
          + mime_type = "text/markdown"
          + subject   = "baz"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

google_monitoring_alert_policy.alert_policy: Creating...
╷
│ Error: Error creating AlertPolicy: googleapi: Error 400: Request was missing field alert_policy.documentation.mime_type: non-empty content requires non-empty MIME type and vice versa.
│ 
│   with google_monitoring_alert_policy.alert_policy,
│   on google.tf line 1, in resource "google_monitoring_alert_policy" "alert_policy":
│    1: resource "google_monitoring_alert_policy" "alert_policy" {
│ 

This error is caused by terraform completes documentation.0.mime_type = "text/markdown" automatically.

Description

From my understanding,

  • The mime_type is required for content, but not for subject.
  • There are no dependencies between content and subject.

So I think the completion is not necessary in this case.

How do you think about adding the condition that mime_type is only completed when the content is set?

Workaround

Set mime_type = "".

<snip>
  documentation {
+   mime_type = ""
    subject   = "baz"
  }
}

Steps to reproduce

  1. terraform apply

Important Factoids

No response

References

b/349152014

@umatare5 umatare5 added the bug label Jun 21, 2024
@github-actions github-actions bot added forward/review In review; remove label to forward service/monitoring-alerting labels Jun 21, 2024
@ggtisc ggtisc self-assigned this Jun 24, 2024
@ggtisc
Copy link
Collaborator

ggtisc commented Jun 24, 2024

Confirmed issue!

According to terraform registry the documentation block content, mime_type and subject are optional. But when we are attempting to create the google_monitoring_alert_policy it triggers the next error:

Error creating AlertPolicy: googleapi: Error 400: Request was missing field alert_policy.documentation.mime_type: non-empty content requires non-empty MIME type and vice versa.

@ggtisc ggtisc removed their assignment Jun 24, 2024
@ggtisc ggtisc removed the forward/review In review; remove label to forward label Jun 24, 2024
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

3 participants