Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bigtable_gc_policy: Adding support for duration lower than day #7879

Merged
merged 7 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions google/resource_bigtable_gc_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@ func resourceBigtableGCPolicy() *schema.Resource {
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"},
},
},
},
Expand All @@ -77,9 +86,10 @@ func resourceBigtableGCPolicy() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"number": {
Type: schema.TypeInt,
Required: true,
Description: `Number of version before applying the GC policy.`,
Type: schema.TypeInt,
Required: true,
Description: `Number of version before applying the GC policy.`,
ValidateFunc: validation.IntAtLeast(1),
},
},
},
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions google/resource_bigtable_gc_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ resource "google_bigtable_gc_policy" "policy" {
column_family = "%s"

max_age {
days = 3
duration = "72h"
}
}
`, instanceName, instanceName, tableName, family, family)
Expand Down Expand Up @@ -195,7 +195,7 @@ resource "google_bigtable_gc_policy" "policy" {
mode = "UNION"

max_age {
days = 3
duration = "72h"
}

max_version {
Expand Down
8 changes: 5 additions & 3 deletions website/docs/r/bigtable_gc_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ resource "google_bigtable_gc_policy" "policy" {
column_family = "name"

max_age {
days = 7
duration = "168h" # 7 days
}
}
```
Expand All @@ -58,7 +58,7 @@ resource "google_bigtable_gc_policy" "policy" {
mode = "UNION"

max_age {
days = 7
duration = "168h" # 7 days
}

max_version {
Expand Down Expand Up @@ -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` - (Deprecated) Number of days before applying GC policy.

* `duration` - (Required) Duration before applying GC policy (ex. "8h"). This is required when `days` isn't set

-----

Expand Down