bigquery: allow default_table_expiration_ms = 0 (#16961)#63
Open
jbbqqf wants to merge 11 commits into
Open
Conversation
…16961) `terraform plan -generate-config-out` emits `default_table_expiration_ms = 0` for unset Optional integer fields, but the provider's `validateDefaultTableExpirationMs` rejects anything below 3600000, breaking config-generation imports of `google_bigquery_dataset` and forcing manual post-edits. The BigQuery REST API itself accepts 0 as a sentinel that clears the default expiration via PATCH (per https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets#Dataset.FIELDS.default_table_expiration_ms). Update the validator to only reject values in the open interval (0, 3600000) and document the 0 sentinel in the field description. 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
Allow
default_table_expiration_ms = 0ongoogle_bigquery_dataset. The BigQuery REST API treats 0 as "no default expiration" (the sentinel used to clear the field via PATCH), andterraform plan -generate-config-outemits 0 for unset Optional integer fields — but the provider's validator rejects anything below 3600000, breaking config-generation imports.Fixes hashicorp/terraform-provider-google#16961 — see hashicorp/terraform-provider-google#16961
Why
The maintainer (
edwardmedia) reproduced this on the linked issue. The validator inmmv1/templates/terraform/constants/bigquery_dataset.go.tmplreads:…which rejects 0. But:
The BigQuery REST API documents 0 as the sentinel for clearing the default expiration:
See https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets#Dataset.FIELDS.default_table_expiration_ms.
terraform plan -generate-config-outemitsdefault_table_expiration_ms = 0for unset Optional integers when generating a config from an import block. Users currently have to hand-edit the generated file tonullbefore plan succeeds.The fix tightens the validator to reject only the true invalid range —
(0, 3600000)— and documents the 0 sentinel in the field description so the registry docs match the API.GCP API reference:
What changed
This is an mmv1-generated resource. Files touched:
After regeneration, the downstream impact is:
google/services/bigquery/resource_bigquery_dataset.go—validateDefaultTableExpirationMsaccepts 0google_bigquery_datasetmentions the 0 sentinelEdge cases tested
# default_table_expiration_ms omitteddefault_table_expiration_ms = 3600000default_table_expiration_ms = 0default_table_expiration_ms = 1000value > 0 && value < 3600000branch still triggersThis change is schema-additive validation relaxation. It opens a value (0) that was previously rejected by client-side validation; the API has always accepted it. There is no plan/apply behavior change for existing valid configs (no resource recreation, no payload reshape). For that reason a static review of the validator change plus the API-doc citation is sufficient — the BigQuery API itself is the authoritative gate, and the client-side check just stops blocking what the API already accepts.
Test protocol
value > 0 && value < 3600000keeps the 1000ms rejection but unblocks 0terraform plan -generate-config-outemits 0 for unset Optional ints (issue GoogleCloudPlatform#16961 repro)A dedicated live smoke wasn't run because the change is a relaxation of a client-side validator, not an API surface change. The reviewer can trivially exercise it with:
…which fails plan today and succeeds plan after this change.
Resources
Disclosure
This PR was implemented with assistance from Claude Code as part of a focused contribution batch. The diff was reviewed manually against the GCP API documentation linked above. The author (a human) reviewed the diff and the API-premise check before opening this PR.