hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.28k stars 1.72k forks source link

terraform google_bigquery_table "max_staleness" does not work #16578

Open fortnox13 opened 9 months ago

fortnox13 commented 9 months ago

I want to create a table with "max_staleness"

resource "google_bigquery_table" "default" {
  dataset_id = "my_dataset"
  table_id   = "my_table"
  project    = "my_project"
  schema = jsonencode([
    { "name" : "country", "type" : "STRING" },
    { "name" : "product", "type" : "STRING" },
    { "name" : "price", "type" : "INT64" }
  ])
  max_staleness = "0-0 0 10:0:0"
  deletion_protection = false

}

terraform {
  required_version = "~> 1.4.2"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "4.83.0"
    }
  }
}

Output:

google_bigquery_table.default: Creating...
google_bigquery_table.default: Creation complete after 1s [id=projects/my_project/datasets/my_dataset/tables/my_table]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

But the table does not have Option "max_staleness"

After retry terraform plan output:

Terraform will perform the following actions:

  # google_bigquery_table.default will be updated in-place
  ~ resource "google_bigquery_table" "default" {
        id                       = "projects/my_project/datasets/my_dataset/tables/my_table"
      + max_staleness            = "0-0 0 10:0:0"
        # (19 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

The same issue with hashicorp/google = 5.7.0

If add max_staleness manually to the table I see max_staleness option in Google Console, but Terraform also has the output:

Terraform will perform the following actions:

  # google_bigquery_table.default will be updated in-place
  ~ resource "google_bigquery_table" "default" {
        id                       = "projects/my_project/datasets/my_dataset/tables/my_table"
      + max_staleness            = "0-0 0 10:0:0"
        # (19 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

terraform version Terraform v1.4.2 on darwin_amd64

b/312697213

edwardmedia commented 9 months ago

I can repro this. maxStaleness is included in the request payload, but not in the response. Likely it is an upper stream issue

fortnox13 commented 9 months ago

This is Bigquery CDC. Google support said: "Currently, there is only a SQL query option to perform this action." As workaround I use null_resource with local-exec:

resource "null_resource" "max_staleness" {

  provisioner "local-exec" {
    when = create
    command = "bq query --use_legacy_sql=false --project_id my_project 'ALTER TABLE `my_project.my_dataset_my_table` SET OPTIONS ( max_staleness = INTERVAL 10 MINUTE} );'"
  }

  provisioner "local-exec" {
    when = destroy
    command = "bq query --use_legacy_sql=false --project_id my_project 'ALTER TABLE `my_project.my_dataset_my_table` SET OPTIONS ( max_staleness = NULL );'"
  }

  depends_on = [google_bigquery_table.default]
}
spartan-khale commented 3 months ago

is this issue still persisting?

marketaflorianova commented 3 months ago

Hi, in our team we also have a problem with this. Is it still an ongoing issue?

fortnox13 commented 3 months ago

The problem was in Google API. They have not supported this. It is better to open Google issue to fix this and ask them about the situation. I think they still have not fixed this.

choonge commented 2 months ago

Can confirm this is not fixed