@@ -1554,6 +1554,56 @@ func TestAccBigQueryTable_TableReplicationInfo_WithReplicationInterval(t *testin
15541554 })
15551555}
15561556
1557+ func TestAccBigQueryTable_ResourceTags (t * testing.T ) {
1558+ t .Parallel ()
1559+
1560+ context := map [string ]interface {}{
1561+ "project_id" : envvar .GetTestProjectFromEnv (),
1562+ "dataset_id" : fmt .Sprintf ("tf_test_dataset_%s" , acctest .RandString (t , 10 )),
1563+ "table_id" : fmt .Sprintf ("tf_test_table_%s" , acctest .RandString (t , 10 )),
1564+ "tag_key_name1" : fmt .Sprintf ("tf_test_tag_key1_%s" , acctest .RandString (t , 10 )),
1565+ "tag_value_name1" : fmt .Sprintf ("tf_test_tag_value1_%s" , acctest .RandString (t , 10 )),
1566+ "tag_key_name2" : fmt .Sprintf ("tf_test_tag_key2_%s" , acctest .RandString (t , 10 )),
1567+ "tag_value_name2" : fmt .Sprintf ("tf_test_tag_value2_%s" , acctest .RandString (t , 10 )),
1568+ }
1569+
1570+ acctest .VcrTest (t , resource.TestCase {
1571+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
1572+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderBetaFactories (t ),
1573+ CheckDestroy : testAccCheckBigQueryTableDestroyProducer (t ),
1574+ Steps : []resource.TestStep {
1575+ {
1576+ Config : testAccBigQueryTableWithResourceTags (context ),
1577+ },
1578+ {
1579+ ResourceName : "google_bigquery_table.test" ,
1580+ ImportState : true ,
1581+ ImportStateVerify : true ,
1582+ ImportStateVerifyIgnore : []string {"deletion_protection" },
1583+ },
1584+ {
1585+ Config : testAccBigQueryTableWithResourceTagsUpdate (context ),
1586+ },
1587+ {
1588+ ResourceName : "google_bigquery_table.test" ,
1589+ ImportState : true ,
1590+ ImportStateVerify : true ,
1591+ ImportStateVerifyIgnore : []string {"deletion_protection" },
1592+ },
1593+ // testAccBigQueryTableWithResourceTagsDestroy must be called at the end of this test to clear the resource tag bindings of the table before deletion.
1594+ {
1595+ Config : testAccBigQueryTableWithResourceTagsDestroy (context ),
1596+ },
1597+ {
1598+ ResourceName : "google_bigquery_table.test" ,
1599+ ImportState : true ,
1600+ ImportStateVerify : true ,
1601+ ImportStateVerifyIgnore : []string {"deletion_protection" },
1602+ },
1603+ },
1604+ })
1605+ }
1606+
15571607func testAccCheckBigQueryExtData (t * testing.T , expectedQuoteChar string ) resource.TestCheckFunc {
15581608 return func (s * terraform.State ) error {
15591609 for _ , rs := range s .RootModule ().Resources {
@@ -3923,6 +3973,138 @@ resource "time_sleep" "wait_10_seconds_last" {
39233973` , sourceDatasetID , sourceTableID , sourceMVJobID , sourceDatasetID , sourceMVID , sourceDatasetID , sourceTableID , projectID , sourceMVID , replicaDatasetID , replicaMVID , projectID , sourceMVID , replicationIntervalExpr , dropMVJobID , sourceDatasetID , sourceMVID )
39243974}
39253975
3976+ func testAccBigQueryTableWithResourceTags (context map [string ]interface {}) string {
3977+ return acctest .Nprintf (`
3978+ resource "google_tags_tag_key" "key1" {
3979+ provider = google-beta
3980+
3981+ parent = "projects/%{project_id}"
3982+ short_name = "%{tag_key_name1}"
3983+ }
3984+
3985+ resource "google_tags_tag_value" "value1" {
3986+ provider = google-beta
3987+
3988+ parent = "tagKeys/${google_tags_tag_key.key1.name}"
3989+ short_name = "%{tag_value_name1}"
3990+ }
3991+
3992+ resource "google_bigquery_dataset" "test" {
3993+ provider = google-beta
3994+
3995+ dataset_id = "%{dataset_id}"
3996+ }
3997+
3998+ resource "google_bigquery_table" "test" {
3999+ provider = google-beta
4000+
4001+ deletion_protection = false
4002+ dataset_id = "${google_bigquery_dataset.test.dataset_id}"
4003+ table_id = "%{table_id}"
4004+ resource_tags = {
4005+ "%{project_id}/${google_tags_tag_key.key1.short_name}" = "${google_tags_tag_value.value1.short_name}"
4006+ }
4007+ }
4008+ ` , context )
4009+ }
4010+
4011+ func testAccBigQueryTableWithResourceTagsUpdate (context map [string ]interface {}) string {
4012+ return acctest .Nprintf (`
4013+ resource "google_tags_tag_key" "key1" {
4014+ provider = google-beta
4015+
4016+ parent = "projects/%{project_id}"
4017+ short_name = "%{tag_key_name1}"
4018+ }
4019+
4020+ resource "google_tags_tag_value" "value1" {
4021+ provider = google-beta
4022+
4023+ parent = "tagKeys/${google_tags_tag_key.key1.name}"
4024+ short_name = "%{tag_value_name1}"
4025+ }
4026+
4027+ resource "google_tags_tag_key" "key2" {
4028+ provider = google-beta
4029+
4030+ parent = "projects/%{project_id}"
4031+ short_name = "%{tag_key_name2}"
4032+ }
4033+
4034+ resource "google_tags_tag_value" "value2" {
4035+ provider = google-beta
4036+
4037+ parent = "tagKeys/${google_tags_tag_key.key2.name}"
4038+ short_name = "%{tag_value_name2}"
4039+ }
4040+
4041+ resource "google_bigquery_dataset" "test" {
4042+ provider = google-beta
4043+
4044+ dataset_id = "%{dataset_id}"
4045+ }
4046+
4047+ resource "google_bigquery_table" "test" {
4048+ provider = google-beta
4049+
4050+ deletion_protection = false
4051+ dataset_id = "${google_bigquery_dataset.test.dataset_id}"
4052+ table_id = "%{table_id}"
4053+ resource_tags = {
4054+ "%{project_id}/${google_tags_tag_key.key1.short_name}" = "${google_tags_tag_value.value1.short_name}"
4055+ "%{project_id}/${google_tags_tag_key.key2.short_name}" = "${google_tags_tag_value.value2.short_name}"
4056+ }
4057+ }
4058+ ` , context )
4059+ }
4060+
4061+ func testAccBigQueryTableWithResourceTagsDestroy (context map [string ]interface {}) string {
4062+ return acctest .Nprintf (`
4063+ resource "google_tags_tag_key" "key1" {
4064+ provider = google-beta
4065+
4066+ parent = "projects/%{project_id}"
4067+ short_name = "%{tag_key_name1}"
4068+ }
4069+
4070+ resource "google_tags_tag_value" "value1" {
4071+ provider = google-beta
4072+
4073+ parent = "tagKeys/${google_tags_tag_key.key1.name}"
4074+ short_name = "%{tag_value_name1}"
4075+ }
4076+
4077+ resource "google_tags_tag_key" "key2" {
4078+ provider = google-beta
4079+
4080+ parent = "projects/%{project_id}"
4081+ short_name = "%{tag_key_name2}"
4082+ }
4083+
4084+ resource "google_tags_tag_value" "value2" {
4085+ provider = google-beta
4086+
4087+ parent = "tagKeys/${google_tags_tag_key.key2.name}"
4088+ short_name = "%{tag_value_name2}"
4089+ }
4090+
4091+ resource "google_bigquery_dataset" "test" {
4092+ provider = google-beta
4093+
4094+ dataset_id = "%{dataset_id}"
4095+ }
4096+
4097+ resource "google_bigquery_table" "test" {
4098+ provider = google-beta
4099+
4100+ deletion_protection = false
4101+ dataset_id = "${google_bigquery_dataset.test.dataset_id}"
4102+ table_id = "%{table_id}"
4103+ resource_tags = {}
4104+ }
4105+ ` , context )
4106+ }
4107+
39264108var TEST_CSV = `lifelock,LifeLock,,web,Tempe,AZ,1-May-07,6850000,USD,b
39274109lifelock,LifeLock,,web,Tempe,AZ,1-Oct-06,6000000,USD,a
39284110lifelock,LifeLock,,web,Tempe,AZ,1-Jan-08,25000000,USD,c
0 commit comments