diff --git a/.changelog/6422.txt b/.changelog/6422.txt new file mode 100644 index 00000000000..1cfcf15edcb --- /dev/null +++ b/.changelog/6422.txt @@ -0,0 +1,3 @@ +```release-note:bug +bigtable: fixed comparing column family name when reading a GC policy. +``` diff --git a/google/resource_bigtable_gc_policy.go b/google/resource_bigtable_gc_policy.go index 41a44e7a06c..64186f992aa 100644 --- a/google/resource_bigtable_gc_policy.go +++ b/google/resource_bigtable_gc_policy.go @@ -246,6 +246,7 @@ func resourceBigtableGCPolicyRead(d *schema.ResourceData, meta interface{}) erro defer c.Close() name := d.Get("table").(string) + columnFamily := d.Get("column_family").(string) ti, err := c.TableInfo(ctx, name) if err != nil { log.Printf("[WARN] Removing %s because it's gone", name) @@ -254,7 +255,7 @@ func resourceBigtableGCPolicyRead(d *schema.ResourceData, meta interface{}) erro } for _, fi := range ti.FamilyInfos { - if fi.Name == name { + if fi.Name == columnFamily { d.SetId(fi.GCPolicy) break } diff --git a/google/resource_bigtable_gc_policy_test.go b/google/resource_bigtable_gc_policy_test.go index f4604743da4..ca8a4b93f2a 100644 --- a/google/resource_bigtable_gc_policy_test.go +++ b/google/resource_bigtable_gc_policy_test.go @@ -99,6 +99,7 @@ func TestAccBigtableGCPolicy_union(t *testing.T) { }) } +// Testing multiple GC policies; one per column family. func TestAccBigtableGCPolicy_multiplePolicies(t *testing.T) { // bigtable instance does not use the shared HTTP client, this test creates an instance skipIfVcr(t) @@ -406,7 +407,7 @@ func testAccBigtableGCPolicyExists(t *testing.T, n string) resource.TestCheckFun } for _, i := range table.FamilyInfos { - if i.Name == rs.Primary.Attributes["column_family"] { + if i.Name == rs.Primary.Attributes["column_family"] && i.GCPolicy == rs.Primary.ID { return nil } } @@ -621,14 +622,20 @@ resource "google_bigtable_table" "table" { instance_name = google_bigtable_instance.instance.id column_family { - family = "%s" + family = "%sA" + } + column_family { + family = "%sB" + } + column_family { + family = "%sC" } } resource "google_bigtable_gc_policy" "policyA" { instance_name = google_bigtable_instance.instance.id table = google_bigtable_table.table.name - column_family = "%s" + column_family = "%sA" max_age { days = 30 @@ -638,7 +645,7 @@ resource "google_bigtable_gc_policy" "policyA" { resource "google_bigtable_gc_policy" "policyB" { instance_name = google_bigtable_instance.instance.id table = google_bigtable_table.table.name - column_family = "%s" + column_family = "%sB" max_version { number = 8 @@ -648,7 +655,7 @@ resource "google_bigtable_gc_policy" "policyB" { resource "google_bigtable_gc_policy" "policyC" { instance_name = google_bigtable_instance.instance.id table = google_bigtable_table.table.name - column_family = "%s" + column_family = "%sC" max_age { days = 7 @@ -660,7 +667,7 @@ resource "google_bigtable_gc_policy" "policyC" { mode = "UNION" } -`, instanceName, instanceName, tableName, family, family, family, family) +`, instanceName, instanceName, tableName, family, family, family, family, family, family) } func testAccBigtableGCPolicy_gcRulesCreate(instanceName, tableName, family string) string {