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

Error creating Monitoring Alert Policy - Expected type 'Duration' but got 'String' #9576

Open
Luke-Scott opened this issue Jul 16, 2021 · 1 comment

Comments

@Luke-Scott
Copy link

Luke-Scott commented Jul 16, 2021

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 the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v1.0.2
provider registry.terraform.io/hashicorp/google v3.75.0

Affected Resource(s)

resource "google_monitoring_alert_policy"

Terraform Configuration Files

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "test_alert"
  combiner     = "OR"
  conditions {
    display_name = "condition"
    condition_monitoring_query_language {
      query    = <<EOT
      fetch cloud_run_revision
| metric 'run.googleapis.com/request_count'
| filter
    resource.project_id == 'luke-test-project-291019'
    &&
    (resource.location == 'europe-west2'
      && resource.service_name == 'github-event-handler-production')
      && (metric.response_code_class == '2xx')
| align rate("300s")
| every "300s"
| group_by [metric.response_code_class],
    [value_request_count_percentile: percentile(value.request_count, 99)]
| condition val() > 0 '1/s'
      EOT 
      duration = "300s"
    }
  }
  user_labels = {
    owner = "sre"
  }
}

Expected Behavior

As you can see from the Terraform Plan output it will create one resource - an alerting policy within GCP's Monitoring.

Screenshot 2021-07-16 at 16 34 17

Actual Behavior

Screenshot 2021-07-16 at 16 31 33

Expected type 'Duration' but got 'String'.

It complains that the duration argument needs to be in the data type 'Duration' and not a string. Is it possible to cast a Duration data type? However, if I then remove the string and make it an integer I get the following error.

Screenshot 2021-07-16 at 16 40 42

Illegal duration format; duration must end with 's'

Doesn't that then mean it has to be a string? It seems to contradict itself.

Here is what's on the Terraform Docs for Duration:

Screenshot 2021-07-16 at 16 42 19

Steps to Reproduce

terraform apply

  • b/275110564
@Luke-Scott Luke-Scott added the bug label Jul 16, 2021
@edwardmedia edwardmedia self-assigned this Jul 16, 2021
@edwardmedia
Copy link
Contributor

This appears to be an API bug. Duration in below request is working

{
 "combiner": "OR",
 "conditions": [
  {
   "conditionThreshold": {
    "aggregations": [
     {
      "alignmentPeriod": "60s",
      "perSeriesAligner": "ALIGN_RATE"
     }
    ],
    "comparison": "COMPARISON_GT",
    "duration": "60s",
    "filter": "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" AND resource.type=\"gce_instance\""
   },
   "displayName": "test condition"
  }
 ],
 "displayName": "issue9576_alert2",
 "enabled": true,
 "userLabels": {
  "foo": "bar"
 }
}

@edwardmedia edwardmedia removed their assignment Nov 19, 2021
modular-magician added a commit to modular-magician/terraform-provider-google that referenced this issue Dec 4, 2023
…ashicorp#9576)

[upstream:3a85747d20f2e7f4be3cba8e428073f70fe7be2b]

Signed-off-by: Modular Magician <[email protected]>
modular-magician added a commit that referenced this issue Dec 4, 2023
…9576) (#16672)

[upstream:3a85747d20f2e7f4be3cba8e428073f70fe7be2b]

Signed-off-by: Modular Magician <[email protected]>
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