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

Incorrect documentation - monitoring_monitored_project [BETA] #10691

Open
drandell opened this issue Dec 6, 2021 · 11 comments
Open

Incorrect documentation - monitoring_monitored_project [BETA] #10691

drandell opened this issue Dec 6, 2021 · 11 comments

Comments

@drandell
Copy link
Contributor

drandell commented Dec 6, 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 1.0.10
Google Beta Provider - 4.2.1

Affected Resource(s)

  • google_monitoring_monitored_project

Terraform Configuration Files

data "google_project" "proc_project" {
  project_id = var.ingest_project_id
}

data "google_project" "ops" {
  project_id = var.monitoring_project_id
}

resource "google_monitoring_monitored_project" "monitored-project" {
  provider = google-beta
  metrics_scope = var.monitoring_project_id
  name = var.ingest_project_id
}

Not sure if the correct place to put, but the documentation for the monitoring_monitored project example says to use the name of the project rather than the id/number.
However, even if i use the project_id or number it fails with the below error.
From the data object we get projects/[PROJECT_ID], my guess would be that the initial projects/ is not being handled correctly.
Using just two variables to pass in project_ids works (in the above example).

Debug Output

 {
│     "@type": "type.googleapis.com/google.rpc.ErrorInfo",
│     "domain": "googleapis.com",
│     "metadata": {
│       "consumer": "projects/projects",
│       "service": "monitoring.googleapis.com"
│     },
│     "reason": "CONSUMER_INVALID"
│   }
│ ]

Expected Behavior

It should add the metrics scope to my monitoring project.

Actual Behavior

It fails to create to add the metric scope.

b/312911546

@drandell drandell added the bug label Dec 6, 2021
@megan07
Copy link
Contributor

megan07 commented Dec 6, 2021

Hi @drandell ! Sorry you're experiencing this issue. I'm curious if you tried this:

data "google_project" "proc_project" {
  project_id = var.ingest_project_id
}

data "google_project" "ops" {
  project_id = var.monitoring_project_id
}

resource "google_monitoring_monitored_project" "monitored-project" {
  provider = google-beta
  metrics_scope = data.google_project.ops.name
  name = data.google_project.proc_project.name
}

it seemed to work for me?
Thanks!

@drandell
Copy link
Contributor Author

drandell commented Dec 6, 2021

Hi @megan07 , created with tf using just the project ids, i've deleted that

resource "google_monitoring_monitored_project" "monitored-project" {
      - create_time   = "2021-12-06T09:29:35.899276544Z" -> null
      - id            = "locations/global/metricsScopes/ops_project_id/projects/proc_project_id" -> null
      - metrics_scope = "ops_project_id" -> null
      - name          = "proc_project_id" -> null
    }

Recreating now with your snippet, the plan shows:

+ resource "google_monitoring_monitored_project" "monitored-project" {
      + create_time   = (known after apply)
      + id            = (known after apply)
      + metrics_scope = "[OPS DISPLAY NAME]"
      + name          = "[PROC DISPLAY NAME]"
    }

I get:

module.cloud_monitoring.google_monitoring_monitored_project.monitored-project: Creating...
╷
│ Error: Error creating MonitoredProject: failed to create a diff: failed to retrieve MonitoredProject resource: googleapi: Error 400: Request contains an invalid argument.
│ 
│   with module.cloud_monitoring.google_monitoring_monitored_project.monitored-project,
│   on ../modules/monitoring/main.tf line 37, in resource "google_monitoring_monitored_project" "monitored-project":
│   37: resource "google_monitoring_monitored_project" "monitored-project" {

Our project display names do contain hyphens.
If i change it to use the project id from the data object i get:

resource "google_monitoring_monitored_project" "monitored-project" {
      + create_time   = (known after apply)
      + id            = (known after apply)
      + metrics_scope = "projects/ops_project_id"
      + name          = "projects/proc_project_id"
    }

And that also fails but with that consumer_invalid error.

@megan07
Copy link
Contributor

megan07 commented Dec 6, 2021

@drandell the project names containing hyphens shouldn't matter, that should be fine. The invalid argument error is from the google side, are you able to provide debug logs?

@megan07 megan07 self-assigned this Dec 6, 2021
@drandell
Copy link
Contributor Author

drandell commented Dec 6, 2021

[removed debug log files]

Attached are the plan and apply debug logs :) @megan07

@megan07
Copy link
Contributor

megan07 commented Dec 6, 2021

Got it! Thank you for that! So I would guess it's the spaces in the name that aren't working for you, and that makes sense. Looking into this more, the name returned is the projects "display name", and, in my test, our name and id is the same, which is why it works for me :). I will update these docs. I have tried project_id and number and both have worked for me.

To clarify, even if you use project_id or number this also fails with the consumer invalid error?

data "google_project" "proc_project" {
  project_id = var.ingest_project_id
}

data "google_project" "ops" {
  project_id = var.monitoring_project_id
}

resource "google_monitoring_monitored_project" "monitored-project" {
  provider = google-beta
  metrics_scope = data.google_project.ops.[project_id|number]
  name = data.google_project.proc_project.[project_id|number]
}

If these also fail, could you please send me the debug logs for these as well? (Sorry about that!)

@drandell
Copy link
Contributor Author

drandell commented Dec 6, 2021

No, I think you are probably right on that, I was using data.google_project.ops.id and not .project_id. Will confirm shortly

Edit:
Yup, project_id on the data resource works fine :) @megan07

Edit again:
To be honest, I feel the data resource should do a better job at specifying its outputs (my assumption was id was an alias of project_id)
https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/project

@drandell drandell changed the title Incorrect documentation & bug - monitoring_monitored_project [BETA] Incorrect documentation - monitoring_monitored_project [BETA] Dec 6, 2021
@megan07 megan07 removed the bug label Dec 6, 2021
@megan07 megan07 removed their assignment Dec 10, 2021
@nat-henderson nat-henderson removed their assignment Jan 7, 2022
@kmunongonganyu
Copy link

kmunongonganyu commented Apr 1, 2022

Hello @megan07 ,
I am facing this issue too. The error message says

Error: project: required field is not set
  on main.tf line 78, in data "google_project" "metric_scoping_project":
  78: data "google_project" "metric_scoping_project" {

Error: project: required field is not set
  on main.tf line 82, in data "google_project" "monitored_project":
  82: data "google_project" "monitored_project" {

this is my code here

resource "google_monitoring_monitored_project" "monitored_project" {
  metrics_scope = data.google_project.metric_scoping_project.project_id
  name          = data.google_project.monitored_project.project_id
  provider      = google-beta
}

data "google_project" "metric_scoping_project" {
  project_id     = var.metric_scoping_project_id
}

data "google_project" "monitored_project" {
  project_id     = var.monitored_project_id
}

@paulinaMorenoA
Copy link

Hello, I was facing same issue due to the documentation error on : https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/monitoring_monitored_project

Under Argument Reference you can still see the reference to project name and no to project ID

[name] - (Required) Immutable. The resource name of the MonitoredProject

@rileykarson
Copy link
Collaborator

Note: https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/monitoring_monitored_project is misconfigured and works because the project's name and project_id match.

name = google_project.basic.name should be name = google_project.basic.project_id

@rileykarson rileykarson added this to the Goals milestone Feb 27, 2023
@fancybear-dev
Copy link

@rileykarson thanks for the suggestion, had weird permission issues that shouldn't exist - your suggestion fixed the issue... Documentation should be updated.

@github-actions github-actions bot added service/monitoring-services forward/review In review; remove label to forward labels Aug 17, 2023
@roaks3
Copy link
Collaborator

roaks3 commented Nov 22, 2023

It looks like the example was updated correctly, but the name field documentation at https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/monitoring_monitored_project still does not mention the short form options. It should be explicit that a project_id or project_number is allowed.

@roaks3 roaks3 removed the forward/review In review; remove label to forward label Nov 22, 2023
modular-magician added a commit to modular-magician/terraform-provider-google that referenced this issue May 16, 2024
…oogle_container_cluster resource (hashicorp#10691)

[upstream:432c55f6cacb487e8bf9a17a9460f6a1bc17af48]

Signed-off-by: Modular Magician <[email protected]>
modular-magician added a commit that referenced this issue May 16, 2024
…oogle_container_cluster resource (#10691) (#18166)

[upstream:432c55f6cacb487e8bf9a17a9460f6a1bc17af48]

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

10 participants