Skip to content

artifactregistry: fix create/update of virtual repo with empty upstream_policies - #18879

Open
bogaertg wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
bogaertg:fix-artifact-registry-empty-virtual-repository-config
Open

artifactregistry: fix create/update of virtual repo with empty upstream_policies#18879
bogaertg wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
bogaertg:fix-artifact-registry-empty-virtual-repository-config

Conversation

@bogaertg

@bogaertg bogaertg commented Sep 3, 2026

Copy link
Copy Markdown

Fixes create/update of google_artifact_registry_repository in VIRTUAL_REPOSITORY mode when virtual_repository_config.upstream_policies is 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 generated expand for virtual_repository_config drops the upstreamPolicies key from the request whenever the list is empty, which in turn makes the whole virtualRepositoryConfig map empty - so the surrounding create/update logic (gated on the same emptiness check) omits the virtualRepositoryConfig field from the request entirely, and the API rejects it with:

Error 400: Virtual repository config is not specified

This happens on both create (a virtual repo with no upstream configured yet) and update (removing the last upstream policy).

Fix

Added a custom_expand for virtual_repository_config that includes upstreamPolicies whenever 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 zero upstream_policies, import verify, update to one policy, import verify, back down to zero.

artifactregistry: fixed `google_artifact_registry_repository` failing to create or update a `VIRTUAL_REPOSITORY`-mode repository with an empty `virtual_repository_config.upstream_policies` list

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Sep 3, 2026
@github-actions
github-actions Bot requested a review from slevenick September 3, 2026 07:33
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-approval Pull requests that need reviewer's approval to run presubmit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants