Skip to content

fix(bigqueryconnection): flatten authentication fields from API response#17341

Merged
shuyama1 merged 1 commit into
GoogleCloudPlatform:mainfrom
ota2000:fix-bigqueryconnection-configuration-import
May 8, 2026
Merged

fix(bigqueryconnection): flatten authentication fields from API response#17341
shuyama1 merged 1 commit into
GoogleCloudPlatform:mainfrom
ota2000:fix-bigqueryconnection-configuration-import

Conversation

@ota2000
Copy link
Copy Markdown
Contributor

@ota2000 ota2000 commented Apr 30, 2026

Description

The custom flatten function for the username_password block in google_bigquery_connection.configuration.authentication, introduced in #17083, was returning values from state via d.Get(...) instead of the API response. This caused two visible bugs:

  1. After importing an existing connection, terraform plan always reported + username = "..." because the imported state was empty (d.Get returned "").
  2. secret_type (output-only) was never populated, leaving it permanently null in state.

Fix

  • Read username and password.secret_type from the API response (v).
  • Keep password.plaintext from state because the API redacts it on read (avoids a permadiff).
  • Drop configuration.0.authentication.0.username_password.0.username from the example test's ignore_read_extra. It is no longer needed now that the field round-trips through state correctly.

Behavior change

Limited to drift detection: external changes to username on the API side are now reflected on the next terraform plan, which matches Terraform's expected drift-detection semantics. Newly-created or already-applied resources see no diff (state and API agree).

Reproduction

Before the fix, with a connection created out-of-band and imported into state:

import {
  to = google_bigquery_connection.example
  id = "projects/my-project/locations/us-central1/connections/my-connection"
}

resource "google_bigquery_connection" "example" {
  configuration {
    connector_id = "google-alloydb"
    authentication {
      username_password {
        username = "dbuser"
        password { plaintext = "..." }
      }
    }
    # ...
  }
}

terraform plan reports + username = "dbuser" even though the API already has the correct value.

Release Note

bigqueryconnection: fixed an issue where `configuration.authentication.username_password.password.secret_type` is not populated and a diff on `configuration.authentication.username_password.username` after import in `google_bigquery_connection` resource

The custom flatten function for `username_password` was returning
values from state (`d.Get`) instead of the API response. As a result:

1. After importing a connection, `terraform plan` always showed
   `+ username = "..."` because the imported state was empty.
2. `secret_type` (output-only) was never populated and remained `null`
   in state.

Read `username` and `password.secret_type` from the API response
(`v`). Keep `password.plaintext` from state because the API redacts it
on read.

Also drop `username` from the example's `ignore_read_extra` since the
field now round-trips through state correctly.

Behavior change is limited to drift detection: external changes to
`username` on the API side are now reflected on the next plan, which
matches Terraform's expected semantics.
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 30, 2026
@ota2000 ota2000 marked this pull request as ready for review April 30, 2026 04:48
@github-actions github-actions Bot requested a review from shuyama1 April 30, 2026 04:48
@github-actions
Copy link
Copy Markdown

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@shuyama1, 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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

@shuyama1 This PR has been waiting for review for 3 weekdays. Please take a look! Use the label disable-review-reminders to disable these notifications.

@modular-magician modular-magician added service/bigquery and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels May 4, 2026
@modular-magician
Copy link
Copy Markdown
Collaborator

modular-magician commented May 4, 2026

Hi there, I'm the Modular magician. I've detected the following information about your changes for commit af125d1:

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 2 files changed, 22 insertions(+), 7 deletions(-)
google-beta provider View Diff 2 files changed, 22 insertions(+), 7 deletions(-)

Test report

Analytics

Total Tests Passed Skipped Affected
17 13 4 0
Affected Service Packages
  • bigqueryconnection

Learn how VCR tests work


Step 1: Replaying Mode

🟢 All tests passed in Replaying mode! No Recording was needed.

View the build log

@ota2000, @sachinpro, @shuyama1 VCR tests complete for af125d1!

@modular-magician modular-magician requested a review from sachinpro May 4, 2026 23:20
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

@GoogleCloudPlatform/terraform-team @shuyama1 This PR has been waiting for review for 1 week. Please take a look! Use the label disable-review-reminders to disable these notifications.

@shuyama1
Copy link
Copy Markdown
Member

shuyama1 commented May 6, 2026

Running some tests on TC

Copy link
Copy Markdown
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants