Skip to content

Commit

Permalink
Bigtable: Adds ignore_warning to gc policy resource (#10982) (#18492)
Browse files Browse the repository at this point in the history
[upstream:0580617eab696140a6af28763ac2575db33dca9a]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jun 20, 2024
1 parent 4caae2a commit 27fc8ec
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/10982.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
bigtable: added `ignore_warnings` field to `bigtable_gc_policy` resource
```
17 changes: 16 additions & 1 deletion google/services/bigtable/resource_bigtable_gc_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ func ResourceBigtableGCPolicy() *schema.Resource {
in a replicated instance. Possible values are: "ABANDON".`,
ValidateFunc: validation.StringInSlice([]string{"ABANDON", ""}, false),
},

"ignore_warnings": {
Type: schema.TypeBool,
Optional: true,
Description: `Allows ignoring warnings when updating the GC policy. This can be used
to increase the gc policy on replicated clusters. Doing this may make clusters be
inconsistent for a longer period of time, before using this make sure you understand
the risks listed at https://cloud.google.com/bigtable/docs/garbage-collection#increasing`,
Default: false,
},
},
UseJSONNumber: true,
}
Expand Down Expand Up @@ -255,9 +265,14 @@ func resourceBigtableGCPolicyUpsert(d *schema.ResourceData, meta interface{}) er

tableName := d.Get("table").(string)
columnFamily := d.Get("column_family").(string)
ignoreWarnings := d.Get("ignore_warnings").(bool)
updateOpts := []bigtable.GCPolicyOption{}
if ignoreWarnings {
updateOpts = append(updateOpts, bigtable.IgnoreWarnings())
}

retryFunc := func() error {
reqErr := c.SetGCPolicy(ctx, tableName, columnFamily, gcPolicy)
reqErr := c.SetGCPolicyWithOptions(ctx, tableName, columnFamily, gcPolicy, updateOpts...)
return reqErr
}
// The default create timeout is 20 minutes.
Expand Down
80 changes: 80 additions & 0 deletions google/services/bigtable/resource_bigtable_gc_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,43 @@ func TestAccBigtableGCPolicy_basic(t *testing.T) {
})
}

func TestAccBigtableGCPolicy_ignoreWarnings(t *testing.T) {
// bigtable instance does not use the shared HTTP client, this test creates an instance
acctest.SkipIfVcr(t)
t.Parallel()

instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
tableName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
familyName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
cluster1Name := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
cluster2Name := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))

gcRulesOriginal := `{"rules":[{"max_age":"10h"}]}`
gcRulesNew := `{"rules":[{"max_age":"12h"}]}`

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckBigtableGCPolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigtableGCPolicyIgnoreWarning(instanceName, tableName, familyName, cluster1Name, cluster2Name, gcRulesOriginal, false),
Check: resource.ComposeTestCheckFunc(
testAccBigtableGCPolicyExists(t, "google_bigtable_gc_policy.policy", true),
resource.TestCheckResourceAttr("google_bigtable_gc_policy.policy", "gc_rules", gcRulesOriginal),
),
},
{
Config: testAccBigtableGCPolicyIgnoreWarning(instanceName, tableName, familyName, cluster1Name, cluster2Name, gcRulesNew, true),
Check: resource.ComposeTestCheckFunc(
testAccBigtableGCPolicyExists(t, "google_bigtable_gc_policy.policy", true),
resource.TestCheckResourceAttr("google_bigtable_gc_policy.policy", "gc_rules", gcRulesNew),
),
},
},
})
}

func TestAccBigtableGCPolicy_abandoned(t *testing.T) {
// bigtable instance does not use the shared HTTP client, this test creates an instance
acctest.SkipIfVcr(t)
Expand Down Expand Up @@ -565,6 +602,49 @@ resource "google_bigtable_gc_policy" "policy" {
`, instanceName, instanceName, tableName, family, family)
}

func testAccBigtableGCPolicyIgnoreWarning(instanceName, tableName, family string, cluster1 string, cluster2 string, gcRule string, ignoreWarnings bool) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
cluster {
cluster_id = "%s"
num_nodes = 1
zone = "us-central1-b"
}
cluster {
cluster_id = "%s"
num_nodes = 1
zone = "us-central1-c"
}
deletion_protection = false
}
resource "google_bigtable_table" "table" {
name = "%s"
instance_name = google_bigtable_instance.instance.id
column_family {
family = "%s"
}
}
resource "google_bigtable_gc_policy" "policy" {
instance_name = google_bigtable_instance.instance.id
table = google_bigtable_table.table.name
column_family = "%s"
gc_rules = <<EOF
%s
EOF
ignore_warnings = %t
deletion_policy = "ABANDON"
}
`, instanceName, cluster1, cluster2, tableName, family, family, gcRule, ignoreWarnings)
}

func testAccBigtableGCPolicyToBeAbandoned(instanceName, tableName, family string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/bigtable_gc_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ The following arguments are supported:

Possible values are: `ABANDON`.

* `ignore_warnings` - (Optional) Boolean for whether to allow ignoring warnings when updating the gc policy.
Setting this to `true` allows relaxing the gc policy for replicated clusters by up to 90 days, but keep in mind this may increase how long clusters are inconsistent. Make sure
you understand the risks listed at https://cloud.google.com/bigtable/docs/garbage-collection#increasing before setting this option.
-----

`max_age` supports the following arguments:
Expand Down

0 comments on commit 27fc8ec

Please sign in to comment.