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: Error creating UptimeCheckConfig: googleapi: Error 404: Error while retrieving Metrics Scope settings for project #17964

Open
paololazzari opened this issue Apr 26, 2024 · 3 comments
Assignees

Comments

@paololazzari
Copy link

paololazzari commented Apr 26, 2024

Terraform Version

Terraform v1.7.2
on darwin_arm64

  • provider registry.terraform.io/hashicorp/google v5.25.0

Affected Resource(s)

google_monitoring_uptime_check_config

Terraform Configuration

The module:

resource "google_monitoring_uptime_check_config" "uptime_checks" {
  for_each     = { for uptime_check in var.uptime_checks : uptime_check.name => uptime_check }
  display_name = each.value.name
  timeout      = "60s"

  http_check {
    path    = each.value.path
    headers = {}
    port    = each.value.port

    dynamic "accepted_response_status_codes" {
      for_each = [
        for code in each.value.codes : code
        if startswith(tostring(code), "STATUS")
      ]
      content {
        status_class = tostring(accepted_response_status_codes.value)
      }
    }
    dynamic "accepted_response_status_codes" {
      for_each = [
        for code in each.value.codes : code
        if startswith(tostring(code), "STATUS") == false
      ]
      content {
        status_value = tonumber(accepted_response_status_codes.value)
      }
    }
  }

  monitored_resource {
    type = "uptime_url"
    labels = {
      project_id = var.project_id
      host       = var.host
    }
  }
  checker_type = "STATIC_IP_CHECKERS"
}
variable "uptime_checks" {
  type = list(object({
    name  = string
    path  = string
    port  = number
    codes = list(any)
  }))
}

variable "project_id" {
  type = string
}

variable "host" {
  type = string
}

using the module:

module "alert" {
  source = "../../modules/alert"
  uptime_checks = [
    { "name" : "foocom-root", "path" : "/", "codes" : [200], "port" : 80 },
  ]
  project_id = "myprojectid"
  host       = "foo.com"
}

Actual Behavior

Error: Error creating UptimeCheckConfig: googleapi: Error 404: Error while retrieving Metrics Scope settings for project: projects/myprojectid

Important Factoids

I can see the metric scope if I run:

$ gcloud beta monitoring metrics-scopes list projects/myprojectid

I can create uptime checks from the console and gcloud cli without any issues

@github-actions github-actions bot added forward/review In review; remove label to forward service/monitoring-uptime labels Apr 26, 2024
@ggtisc ggtisc self-assigned this Apr 29, 2024
@ggtisc
Copy link
Collaborator

ggtisc commented May 2, 2024

Hi @paololazzari!

This scenario was replicated successfully with the terraform and Google provider versions you shared without errors. I suggest you to check the next:

  • Verify how you are inserting the variable uptime_checks, for example if the value of your host is "monitoringuptime17964.com" then you need to run something like this in your terminal:

    terraform apply -var='uptime_checks=[{name="Example_Uptime_Check", path="/", port=80, codes=[200, 201, 202]}]'

  • Try to isolate this in a new project with just the basic, because maybe you are having conflicts with the paths of your modules. Usage of modules is a good practice, but to test you may create an independent project with only the necessary

@paololazzari
Copy link
Author

@ggtisc the terraform configuration is correct, as terraform plan shows the right output.

@ggtisc
Copy link
Collaborator

ggtisc commented May 7, 2024

This ticket was replicated again with the same result, you should check your variables and be sure that they are correct or simplify your code hard coding their values to test it in your environment

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

2 participants