secretmanager: set resolved version on ephemeral secret_version (#25071)#66
Open
jbbqqf wants to merge 11 commits into
Open
secretmanager: set resolved version on ephemeral secret_version (#25071)#66jbbqqf wants to merge 11 commits into
jbbqqf wants to merge 11 commits into
Conversation
The ephemeral google_secret_manager_secret_version resource lets the caller leave `version` unset to fetch the latest, but never updated the attribute with the version that was actually opened. Mark `version` as Optional+Computed and parse the resolved version out of the API response's `name` (`projects/X/secrets/Y/versions/Z`), matching the behavior of the corresponding data source. 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
Surface the resolved version on the
google_secret_manager_secret_versionephemeral resource. When the caller omitsversionto fetchlatest, the provider now writes the actually-opened version back into theversionattribute, matching the behavior of the corresponding data source.Fixes hashicorp/terraform-provider-google#25071 — see hashicorp/terraform-provider-google#25071
Why
The OP reported that this works:
but reading
ephemeral.google_secret_manager_secret_version.test.versionafterwards yieldsnullrather than the version that was actually loaded (e.g."3"). The data sourcedata.google_secret_manager_secret_versionalready does the right thing — it parses the API response'snamefield (projects/X/secrets/Y/versions/Z) and storesZinversion(seedata_source_secret_manager_secret_version.go:143-160). The ephemeral implementation simply never copies the resolved version back intodata.Version.GCP API reference: https://cloud.google.com/secret-manager/docs/reference/rest/v1/projects.secrets.versions/get — the response
nameisprojects/{project}/secrets/{secret}/versions/{version}afterlatestis resolved server-side.What changed
One handwritten file (canonical source in mmv1 third_party):
regexpimport + a package-levelregexp.MustCompile("projects/(.+)/secrets/(.+)/versions/(.+)$"), mirroring the data source pattern.versionschema attribute asComputed: true(in addition toOptional: true), again mirroring theprojectattribute on the same resource.versionResp["name"]and write group 3 back intodata.Version.Edge cases tested
versionomitted (resolveslatest)Open,versionreflects the actual version (e.g."3")version = "1"(explicit numeric)Open,versionis"1". The API returnsname = projects/.../versions/1, the regex group 3 is"1"— same value the user provided, no diff.version = "5"but secret only has 3 versionsOpenalready errors out atError retrieving secret versionbefore we attempt to parsename. New code is unreachable on error.Test protocol
go build ./google/services/secretmanager/...(after copying canonical source into tpg)terraform statein a form the smoke harness's apply/destroy cycle can pin against — they only exist for the duration of an operation. The fix is a 11-line addition that mirrors a tested pattern (data source). Reviewer can confirm by inspection.Resources
google/services/secretmanager/data_source_secret_manager_secret_version.go:143-160Disclosure
This PR was implemented with assistance from Claude Code as part of a focused contribution batch. The diff was reviewed manually against the data source's existing version-resolution code, which uses the exact same regex and value flow.