diff --git a/third_party/terraform/resources/resource_bigtable_gc_policy.go b/third_party/terraform/resources/resource_bigtable_gc_policy.go index 57273cf72252..3c05485780af 100644 --- a/third_party/terraform/resources/resource_bigtable_gc_policy.go +++ b/third_party/terraform/resources/resource_bigtable_gc_policy.go @@ -58,12 +58,22 @@ func resourceBigtableGCPolicy() *schema.Resource { Optional: true, ForceNew: true, Description: `GC policy that applies to all cells older than the given age.`, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "days": { - Type: schema.TypeInt, - Required: true, - Description: `Number of days before applying GC policy.`, + Type: schema.TypeInt, + Optional: true, + Deprecated: "Deprecated in favor of duration", + Description: `Number of days before applying GC policy.`, + ExactlyOneOf: []string{"max_age.0.days", "max_age.0.duration"}, + }, + "duration": { + Type: schema.TypeString, + Optional: true, + Description: `Duration before applying GC policy`, + ValidateFunc: validateDuration(), + ExactlyOneOf: []string{"max_age.0.days", "max_age.0.duration"}, }, }, }, @@ -236,9 +246,12 @@ func generateBigtableGCPolicy(d *schema.ResourceData) (bigtable.GCPolicy, error) if aok { l, _ := ma.([]interface{}) - d, _ := l[0].(map[string]interface{})["days"].(int) + d, err := getMaxAgeDuration(l[0].(map[string]interface{})) + if err != nil { + return nil, err + } - policies = append(policies, bigtable.MaxAgePolicy(time.Duration(d)*time.Hour*24)) + policies = append(policies, bigtable.MaxAgePolicy(d)) } if vok { @@ -257,3 +270,14 @@ func generateBigtableGCPolicy(d *schema.ResourceData) (bigtable.GCPolicy, error) return policies[0], nil } + +func getMaxAgeDuration(values map[string]interface{}) (time.Duration, error) { + d := values["duration"].(string) + if d != "" { + return time.ParseDuration(d) + } + + days := values["days"].(int) + + return time.Hour * 24 * time.Duration(days), nil +} diff --git a/third_party/terraform/tests/resource_bigtable_gc_policy_test.go b/third_party/terraform/tests/resource_bigtable_gc_policy_test.go index 314305384904..c504ec39768f 100644 --- a/third_party/terraform/tests/resource_bigtable_gc_policy_test.go +++ b/third_party/terraform/tests/resource_bigtable_gc_policy_test.go @@ -158,7 +158,7 @@ resource "google_bigtable_gc_policy" "policy" { column_family = "%s" max_age { - days = 3 + duration = "72h" } } `, instanceName, instanceName, tableName, family, family) @@ -195,7 +195,7 @@ resource "google_bigtable_gc_policy" "policy" { mode = "UNION" max_age { - days = 3 + duration = "72h" } max_version { diff --git a/third_party/terraform/website/docs/r/bigtable_gc_policy.html.markdown b/third_party/terraform/website/docs/r/bigtable_gc_policy.html.markdown index df7d3183b3d7..7c6ff3c237cd 100644 --- a/third_party/terraform/website/docs/r/bigtable_gc_policy.html.markdown +++ b/third_party/terraform/website/docs/r/bigtable_gc_policy.html.markdown @@ -42,7 +42,7 @@ resource "google_bigtable_gc_policy" "policy" { column_family = "name" max_age { - days = 7 + duration = "168h" } } ``` @@ -58,7 +58,7 @@ resource "google_bigtable_gc_policy" "policy" { mode = "UNION" max_age { - days = 7 + duration = "168h" # 7 days } max_version { @@ -89,7 +89,9 @@ The following arguments are supported: `max_age` supports the following arguments: -* `days` - (Required) Number of days before applying GC policy. +* `days` - (Optional, Deprecated in favor of duration) Number of days before applying GC policy. + +* `duration` - (Optional) Duration before applying GC policy (ex. "8h"). This is required when `days` isn't set -----