-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected empty policyTags added to BigQuery tables after import, causing unintended resource changes #19485
Unexpected empty policyTags added to BigQuery tables after import, causing unintended resource changes #19485
Comments
Hi @kesompochy! I tried to replicate this issue with the following configuration similar to the one you are sharing, but the result was successful without errors. The
|
Hi @ggtisc! I believe this issue is caused by the inclusion of I'd like to note that this issue primarily affects resources created outside of Terraform. As such, it may not require immediate action. Thank you for your attention and response to this matter. |
@kesompochy could you show us how are you attaching the existing If it is possible share the full command you are using without sensitive information |
Here is my configurations and commands.
provider "google" {
project = var.project_id
region = "us-central1"
}
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "4.80.0"
}
}
}
resource "google_bigquery_dataset" "my_dataset" {
dataset_id = "my_dataset"
project = var.project_id
}
$ terraform apply
$ bq mk --table my-project:my_dataset.test_table time:TIMESTAMP
resource "google_bigquery_table" "test_table" {
dataset_id = google_bigquery_dataset.my_dataset.dataset_id
deletion_protection = true
table_id = "test_table"
expiration_time = "0"
project = var.project_id
schema = <<EOL
[
{
"name": "time",
"type": "TIMESTAMP"
}
]
EOL
}
import {
to = google_bigquery_table.test_table
id = "projects/my-project/datasets/my_dataset/tables/test_table"
}
$ terraform apply -var-file="terraform.tfvars"
$ terraform state show google_bigquery_table.test_table
resource "google_bigquery_table" "test_table" {
dataset_id = google_bigquery_dataset.my_dataset.dataset_id
deletion_protection = true # modified
table_id = "test_table"
expiration_time = "0"
project = var.project_id
schema = <<EOL
[
{
"name": "time",
"type": "TIMESTAMP"
}
]
EOL
}
$ terraform apply -var-file="terraform.tfvars"
$ terraform state show google_bigquery_table.test_table |
Hi @kesompochy! After replicating this step by step it is true that the Terraform uses the In conclusion the fact that the |
Hi @ggtisc! Thank you for replicating my steps. However, I'm still concerned about the behavior where unexpected empty Could we improve the behavior so that empty Additionally, although this is not directly related to the |
After some tries I can't reproduce this issue. It looks like it is intermittent. I'm forwarding it for a deeper review |
Yes, treating the absence of There may be some options to mitigate the side effect that causes the behavior you are reporting, but I'd like to understand more the impact of the changing table etag for your use case. Can you elaborate on how
I'm not aware of a mechanism that allows for this today, but the idea has merit and I'll bring it up for discussion. |
Thank you for explaining the purpose and details regarding the empty policy tag behavior. I'd like to share an unexpected scenario I encountered:
I understand that this is a highly specific scenario that likely affects very few users.
I appreciate your time and consideration. |
Thanks for sharing the additional details. I'm still trying to understand how the diff detection finds a case mismatch in the column name. Is it that the table created using
I happened to work on the
I just heard back and there does appear to exist a way to make this optimization today! It was added to the documentation as part of GoogleCloudPlatform/magic-modules#11330, and I'll look into applying that to |
Thank you for your investigation, @wj-chen.
However, after Terraform modifies the table configuration,
This suggests that the issue is not related to the Terraform config schema case itself.
That's excellent news! Thank you very much for your efforts on this matter. |
Updating |
Thanks @wj-chen for working on this! Really looking forward to using v6.11.0 with the improved functionality! |
Community Note
Terraform Version & Provider Version(s)
Terraform v1.9.5
on x86_64 GNU/Linux
Affected Resource(s)
google_bigquery_table
Terraform Configuration
Debug Output
Please see "Actual Behavior".
Expected Behavior
When importing a BigQuery table that was created using the bq command and then modifying an unrelated attribute (e.g., deletion_protection), the provider should not add empty policyTags to fields that didn't originally have them. The resource's eTag should remain unchanged if no actual modifications were made to the table's schema or structure.
Actual Behavior
After importing a BigQuery table and modifying an unrelated attribute, the provider sends a change request that includes policyTags: {} for fields, even when no policy tags were present initially. This causes the eTag of the resource to change unexpectedly.
Steps to reproduce
deletion_protection
)This behaviour causes unintended schema changes, including changes in the case sensitivity of field names, when using
bq query --replace
. This is likely because thebq
command refers to the eTag to decide whether the schema should change or not.Important Factoids
This behavior has been observed in several versions of v4.80.0 and above, including the latest version; it was not observed in v4.79.0 or below.
References
#15547
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/update
b/371990367
The text was updated successfully, but these errors were encountered: