Skip to content

Commit 27fc8ec

Browse files
Bigtable: Adds ignore_warning to gc policy resource (#10982) (#18492)
[upstream:0580617eab696140a6af28763ac2575db33dca9a] Signed-off-by: Modular Magician <[email protected]>
1 parent 4caae2a commit 27fc8ec

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed

.changelog/10982.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigtable: added `ignore_warnings` field to `bigtable_gc_policy` resource
3+
```

google/services/bigtable/resource_bigtable_gc_policy.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ func ResourceBigtableGCPolicy() *schema.Resource {
218218
in a replicated instance. Possible values are: "ABANDON".`,
219219
ValidateFunc: validation.StringInSlice([]string{"ABANDON", ""}, false),
220220
},
221+
222+
"ignore_warnings": {
223+
Type: schema.TypeBool,
224+
Optional: true,
225+
Description: `Allows ignoring warnings when updating the GC policy. This can be used
226+
to increase the gc policy on replicated clusters. Doing this may make clusters be
227+
inconsistent for a longer period of time, before using this make sure you understand
228+
the risks listed at https://cloud.google.com/bigtable/docs/garbage-collection#increasing`,
229+
Default: false,
230+
},
221231
},
222232
UseJSONNumber: true,
223233
}
@@ -255,9 +265,14 @@ func resourceBigtableGCPolicyUpsert(d *schema.ResourceData, meta interface{}) er
255265

256266
tableName := d.Get("table").(string)
257267
columnFamily := d.Get("column_family").(string)
268+
ignoreWarnings := d.Get("ignore_warnings").(bool)
269+
updateOpts := []bigtable.GCPolicyOption{}
270+
if ignoreWarnings {
271+
updateOpts = append(updateOpts, bigtable.IgnoreWarnings())
272+
}
258273

259274
retryFunc := func() error {
260-
reqErr := c.SetGCPolicy(ctx, tableName, columnFamily, gcPolicy)
275+
reqErr := c.SetGCPolicyWithOptions(ctx, tableName, columnFamily, gcPolicy, updateOpts...)
261276
return reqErr
262277
}
263278
// The default create timeout is 20 minutes.

google/services/bigtable/resource_bigtable_gc_policy_test.go

+80
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,43 @@ func TestAccBigtableGCPolicy_basic(t *testing.T) {
4141
})
4242
}
4343

44+
func TestAccBigtableGCPolicy_ignoreWarnings(t *testing.T) {
45+
// bigtable instance does not use the shared HTTP client, this test creates an instance
46+
acctest.SkipIfVcr(t)
47+
t.Parallel()
48+
49+
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
50+
tableName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
51+
familyName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
52+
cluster1Name := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
53+
cluster2Name := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
54+
55+
gcRulesOriginal := `{"rules":[{"max_age":"10h"}]}`
56+
gcRulesNew := `{"rules":[{"max_age":"12h"}]}`
57+
58+
acctest.VcrTest(t, resource.TestCase{
59+
PreCheck: func() { acctest.AccTestPreCheck(t) },
60+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
61+
CheckDestroy: testAccCheckBigtableGCPolicyDestroyProducer(t),
62+
Steps: []resource.TestStep{
63+
{
64+
Config: testAccBigtableGCPolicyIgnoreWarning(instanceName, tableName, familyName, cluster1Name, cluster2Name, gcRulesOriginal, false),
65+
Check: resource.ComposeTestCheckFunc(
66+
testAccBigtableGCPolicyExists(t, "google_bigtable_gc_policy.policy", true),
67+
resource.TestCheckResourceAttr("google_bigtable_gc_policy.policy", "gc_rules", gcRulesOriginal),
68+
),
69+
},
70+
{
71+
Config: testAccBigtableGCPolicyIgnoreWarning(instanceName, tableName, familyName, cluster1Name, cluster2Name, gcRulesNew, true),
72+
Check: resource.ComposeTestCheckFunc(
73+
testAccBigtableGCPolicyExists(t, "google_bigtable_gc_policy.policy", true),
74+
resource.TestCheckResourceAttr("google_bigtable_gc_policy.policy", "gc_rules", gcRulesNew),
75+
),
76+
},
77+
},
78+
})
79+
}
80+
4481
func TestAccBigtableGCPolicy_abandoned(t *testing.T) {
4582
// bigtable instance does not use the shared HTTP client, this test creates an instance
4683
acctest.SkipIfVcr(t)
@@ -565,6 +602,49 @@ resource "google_bigtable_gc_policy" "policy" {
565602
`, instanceName, instanceName, tableName, family, family)
566603
}
567604

605+
func testAccBigtableGCPolicyIgnoreWarning(instanceName, tableName, family string, cluster1 string, cluster2 string, gcRule string, ignoreWarnings bool) string {
606+
return fmt.Sprintf(`
607+
resource "google_bigtable_instance" "instance" {
608+
name = "%s"
609+
610+
cluster {
611+
cluster_id = "%s"
612+
num_nodes = 1
613+
zone = "us-central1-b"
614+
}
615+
616+
cluster {
617+
cluster_id = "%s"
618+
num_nodes = 1
619+
zone = "us-central1-c"
620+
}
621+
622+
deletion_protection = false
623+
}
624+
625+
resource "google_bigtable_table" "table" {
626+
name = "%s"
627+
instance_name = google_bigtable_instance.instance.id
628+
629+
column_family {
630+
family = "%s"
631+
}
632+
}
633+
634+
resource "google_bigtable_gc_policy" "policy" {
635+
instance_name = google_bigtable_instance.instance.id
636+
table = google_bigtable_table.table.name
637+
column_family = "%s"
638+
gc_rules = <<EOF
639+
%s
640+
EOF
641+
642+
ignore_warnings = %t
643+
deletion_policy = "ABANDON"
644+
}
645+
`, instanceName, cluster1, cluster2, tableName, family, family, gcRule, ignoreWarnings)
646+
}
647+
568648
func testAccBigtableGCPolicyToBeAbandoned(instanceName, tableName, family string) string {
569649
return fmt.Sprintf(`
570650
resource "google_bigtable_instance" "instance" {

website/docs/r/bigtable_gc_policy.html.markdown

+3
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ The following arguments are supported:
166166

167167
Possible values are: `ABANDON`.
168168

169+
* `ignore_warnings` - (Optional) Boolean for whether to allow ignoring warnings when updating the gc policy.
170+
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
171+
you understand the risks listed at https://cloud.google.com/bigtable/docs/garbage-collection#increasing before setting this option.
169172
-----
170173

171174
`max_age` supports the following arguments:

0 commit comments

Comments
 (0)