artifactregistry: fix create/update of virtual repo with empty upstream_policies - #18879
Open
bogaertg wants to merge 1 commit into
Open
Conversation
|
Googlers: For automatic test runs see go/terraform-auto-test-runs. @slevenick, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look. You can help make sure that review is quick by doing a self-review and by running impacted tests locally. |
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.
Fixes create/update of
google_artifact_registry_repositoryinVIRTUAL_REPOSITORYmode whenvirtual_repository_config.upstream_policiesis an empty list.Bug
The Artifact Registry REST API accepts and creates a virtual repository with
virtualRepositoryConfig: {upstreamPolicies: []}fine (verified directly against the API, not through Terraform). The generatedexpandforvirtual_repository_configdrops theupstreamPolicieskey from the request whenever the list is empty, which in turn makes the wholevirtualRepositoryConfigmap empty - so the surrounding create/update logic (gated on the same emptiness check) omits thevirtualRepositoryConfigfield from the request entirely, and the API rejects it with:This happens on both create (a virtual repo with no upstream configured yet) and update (removing the last upstream policy).
Fix
Added a
custom_expandforvirtual_repository_configthat includesupstreamPolicieswhenever the block was actually configured, regardless of whether the resulting list is empty - matching what the REST API accepts.Tests
Added
TestAccArtifactRegistryRepository_virtualEmpty: create with zeroupstream_policies, import verify, update to one policy, import verify, back down to zero.