terraform-provider-google
terraform-provider-google copied to clipboard
Error: Error creating UptimeCheckConfig: googleapi: Error 404: Error while retrieving Metrics Scope settings for project
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
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 yourhost
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
@ggtisc the terraform configuration is correct, as terraform plan
shows the right output.
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