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: Update local gc_rules on read #6526

Merged
merged 4 commits into from
Sep 15, 2022
Merged
Changes from 1 commit
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
31 changes: 17 additions & 14 deletions mmv1/third_party/terraform/resources/resource_bigtable_gc_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,24 @@ func resourceBigtableGCPolicyRead(d *schema.ResourceData, meta interface{}) erro
}

for _, fi := range ti.FamilyInfos {
if fi.Name == columnFamily {
d.SetId(fi.GCPolicy)
// Only set `gc_rules`` when the legacy fields are not set. We are not planning to support legacy fields.
if d.Get("mode") == "" && d.Get("max_age") == "" && d.Get("max_version") == "" {
gcRuleString, err := gcPolicyToGCRuleString(fi.FullGCPolicy, true)
if err != nil {
return err
}
gcRuleJsonString, err := json.Marshal(gcRuleString)
if err != nil {
return fmt.Errorf("Error marshaling GC policy to json: %s", err)
}
d.Set("gc_rules", string(gcRuleJsonString))
if fi.Name != columnFamily {
continue
}

d.SetId(fi.GCPolicy)
// Only set `gc_rules`` when the legacy fields are not set. We are not planning to support legacy fields.
if d.Get("mode") == "" && d.Get("max_age") == "" && d.Get("max_version") == "" {
kevinsi4508 marked this conversation as resolved.
Show resolved Hide resolved
gcRuleString, err := gcPolicyToGCRuleString(fi.FullGCPolicy, true)
if err != nil {
return err
}
break
gcRuleJsonString, err := json.Marshal(gcRuleString)
if err != nil {
return fmt.Errorf("Error marshaling GC policy to json: %s", err)
}
d.Set("gc_rules", string(gcRuleJsonString))
}
break
}

if err := d.Set("project", project); err != nil {
Expand All @@ -280,6 +282,7 @@ func resourceBigtableGCPolicyRead(d *schema.ResourceData, meta interface{}) erro
return nil
}

// Recursively convert Bigtable GC policy to JSON format in a map.
func gcPolicyToGCRuleString(gc bigtable.GCPolicy, topLevel bool) (map[string]interface{}, error) {
result := make(map[string]interface{})
switch bigtable.GetPolicyType(gc) {
Expand Down