alloydb: add keep_extra_roles to google_alloydb_user (#17216)#17491
Open
jbbqqf wants to merge 2 commits intoGoogleCloudPlatform:mainfrom
Open
alloydb: add keep_extra_roles to google_alloydb_user (#17216)#17491jbbqqf wants to merge 2 commits intoGoogleCloudPlatform:mainfrom
jbbqqf wants to merge 2 commits intoGoogleCloudPlatform:mainfrom
Conversation
…latform#17216) Adds the keep_extra_roles input-only Boolean argument to the google_alloydb_user resource. The AlloyDB Admin API already supports the flag (see vendored google.golang.org/api/alloydb/v1/alloydb-gen.go:5525); this YAML edit makes it configurable through Terraform so operators can preserve database roles granted out-of-band (e.g. via psql GRANT) when reconciling database_roles. Defaults to false — current behaviour preserved. Marked ignore_read because the API does not echo the field back. Live BEFORE/AFTER plan-only smoke confirms the BEFORE provider (origin/main) rejects the argument and the AFTER provider plans cleanly. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Googlers: For automatic test runs see go/terraform-auto-test-runs. @trodge, 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.
Summary
Adds the
keep_extra_rolesargument togoogle_alloydb_user, exposing theexisting AlloyDB API
keepExtraRolesflag so operators can preserve databaseroles granted out-of-band (e.g. via
psql GRANT) when reconcilingdatabase_rolesthrough Terraform.Fixes hashicorp/terraform-provider-google#17216 — see hashicorp/terraform-provider-google#17216
Why
Today,
google_alloydb_user.database_rolesreconciles the user's role setexactly: any role granted out of Terraform's purview (commonly via PostgreSQL
GRANTrun by application bootstrapping or migrations) is removed on the nextapply. The AlloyDB Admin API has supported
keepExtraRolesas an input-onlyboolean to opt out of that reconciliation since at least client library
v0.278.0:
Maintainer @melinath acknowledged the tradeoff in the issue thread, and 15
reactions back the request. This PR surfaces the API capability through
Terraform without changing existing default behaviour.
GCP API reference: https://cloud.google.com/alloydb/docs/reference/rest/v1/projects.locations.clusters.users#User.FIELDS.keep_extra_roles
What changed
keepExtraRolesfield, typedBoolean,marked
ignore_read: truebecause the API does not echo it back (it is aninput-only flag, not stored on the server).
false(current behaviour preserved). Users opt in withkeep_extra_roles = true.The downstream-generated diff in
terraform-provider-googleandterraform-provider-google-betais the standard additive shape (schema +expand stub + Create/Update wiring), already validated locally — see "Test
protocol" below.
Edge cases tested
# keep_extra_roles omittedkeepExtraRoles, API reconcilesdatabase_rolesexactly as beforetruekeep_extra_roles = truekeepExtraRoles: truein the Create body and on Updateorigin/mainrejects the argument withUnsupported argument: keep_extra_rolesat plan timeBefore / After (Terraform)
Before — field not available
After — fix proven
Test protocol
go vet ./google/services/alloydb/...(TPG)go vet ./google-beta/services/alloydb/...(TPGB)go build ./...(full TPG compile)go build ./...(full TPGB compile)origin/main)Error: Unsupported argument: keep_extra_rolesThe smoke ran in
SMOKE_PLAN_ONLY=1mode because validating thekeep_extra_rolesargument is a static schema concern (does the provider accept and forward it?)
and a full apply would require a 20–30 min AlloyDB cluster + instance create,
incurring real spend without adding evidence the API contract is met. The
vendored
google.golang.org/api/alloydb/v1client (alloydb-gen.go:5525-5527)already declares the field, and the generated expand/create/update wiring
follows the same shape as the adjacent
databaseRolesfield, so no API-sidesurprises are expected.
A reviewer with apply-mode budget can rerun the smoke without the
SMOKE_PLAN_ONLY=1flag using the samemain.tf(live AlloyDB cluster +instance + user, ~25 min wall clock per phase).
Resources
google_alloydb_user.database_rolesremoves PostgreSQL granted roles hashicorp/terraform-provider-google#17216https://cloud.google.com/alloydb/docs/reference/rest/v1/projects.locations.clusters.users#User.FIELDS.keep_extra_roles
https://cloud.google.com/alloydb/docs/reference/rest/v1/projects.locations.clusters.users/create
https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/alloydb_user
Release notes
Disclosure
This PR was drafted with assistance from Claude Code as part of a focused
contribution batch on additive schema gaps. The mmv1 YAML edit was reviewed
manually against the AlloyDB v1 vendored Go API client (which already declares
KeepExtraRoles) and against the published REST documentation. The staticbuild, vet, and a live BEFORE/AFTER plan-only smoke against
gcp-masterclassesconfirmed the field is recognized by the AFTER providerand rejected by the BEFORE provider.
The author (a human) reviewed the diff and the smoke output before opening
this PR.