resourcemanager: data.google_project.project_id should be canonical ID, not number (#19732)#73
Open
jbbqqf wants to merge 11 commits into
Open
resourcemanager: data.google_project.project_id should be canonical ID, not number (#19732)#73jbbqqf wants to merge 11 commits into
jbbqqf wants to merge 11 commits into
Conversation
…D, not project number (#19732) When data "google_project" is queried via a project number, the resulting state's project_id stored the number too. Use the API-canonical Project.projectId from the Cloud Resource Manager response. Falls back to the original lookup key only if the API response is empty. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where
data.google_project.project_idis set to the project number instead of the canonical string project ID whenever the data source is queried by number (either viaproject_id = "<number>"or implicitly throughprovider.project = "<number>").Fixes hashicorp/terraform-provider-google#19732 — see hashicorp/terraform-provider-google#19732
Why
The Cloud Resource Manager
ProjectAPI resource has two distinct fields:projectId— the unique string ID (e.g.gcp-masterclasses)projectNumber— the numeric ID (e.g.922462624752)The
data.google_projectschema documentsproject_idas the string ID and exposesnumberseparately. ButresourceGoogleProjectRead(shared with the data source) setsproject_idfrompid, which is the trailing segment ofd.Id(). When the data source is looked up by number,pidis the number, soproject_idends up being the number too — silently misleading anyone who uses the field downstream.GCP API reference: https://cloud.google.com/resource-manager/reference/rest/v1/projects/get
What changed
This change is to a hand-written Terraform resource (not magic-modules-generated). Files touched in
terraform-provider-google[-beta]:Use the API-canonical
Project.projectIdfrom the response when populating state. Falls back topidonly if the API response is empty (defensive — the field is required by the API contract).Edge cases tested
provider.project = "<number>"data "google_project" "by_number" {}project_id= canonical string IDproject_id = "<number>"data "google_project" "n" { project_id = "922462624752" }project_id= canonical string IDproject_id = "<canonical_id>"data "google_project" "i" { project_id = "gcp-masterclasses" }project_id= same canonical string ID (sanity)Test protocol
go build ./...(full provider compile)origin/main)project_idreturned the numberproject_idreturned the canonical string IDVerdict: 🟢 GREEN.
Disclosure
This PR was implemented with assistance from Claude Code as part of a focused contribution batch on hand-written resources. The diff was reviewed manually against the Cloud Resource Manager v1 API documentation linked above. The live before/after smoke harness exercised the data source against the author's sandbox project; both phases destroyed cleanly.