Skip to content

Commit

Permalink
Bigtable: Compare column family (#6422) (#4624)
Browse files Browse the repository at this point in the history
* Compare column family when reading a GC policy

* revert column family change

* Compare column family when reading a GC policy

* Check rs.Primary.ID is not empty

* Compare Primary.Id with GCPolicy

* One GC policy per column family

Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Aug 24, 2022
1 parent 324cc9e commit 5c4e818
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/6422.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
bigtable: fixed comparing column family name when reading a GC policy.
```
3 changes: 2 additions & 1 deletion google-beta/resource_bigtable_gc_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
19 changes: 13 additions & 6 deletions google-beta/resource_bigtable_gc_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 5c4e818

Please sign in to comment.