Skip to content

Commit

Permalink
Check if labels field exists in customDiff function (#9043)
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 authored Sep 22, 2023
1 parent 63fe377 commit 4aa41b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions mmv1/third_party/terraform/tpgresource/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
)

func SetAnnotationsDiff(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
raw := d.Get("annotations")
if raw == nil {
return nil
}

o, n := d.GetChange("annotations")
effectiveAnnotations := d.Get("effective_annotations").(map[string]interface{})

Expand All @@ -34,6 +39,11 @@ func SetMetadataAnnotationsDiff(_ context.Context, d *schema.ResourceDiff, meta
return nil
}

raw := d.Get("metadata.0.annotations")
if raw == nil {
return nil
}

o, n := d.GetChange("metadata.0.annotations")
effectiveAnnotations := d.Get("metadata.0.effective_annotations").(map[string]interface{})

Expand Down
14 changes: 12 additions & 2 deletions mmv1/third_party/terraform/tpgresource/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ func SetLabelsDiff(_ context.Context, d *schema.ResourceDiff, meta interface{})
terraformLabels[k] = v
}

labels := d.Get("labels").(map[string]interface{})
raw := d.Get("labels")
if raw == nil {
return nil
}

labels := raw.(map[string]interface{})
for k, v := range labels {
terraformLabels[k] = v.(string)
}
Expand Down Expand Up @@ -71,6 +76,11 @@ func SetMetadataLabelsDiff(_ context.Context, d *schema.ResourceDiff, meta inter
return nil
}

raw := d.Get("metadata.0.labels")
if raw == nil {
return nil
}

config := meta.(*transport_tpg.Config)

// Merge provider default labels with the user defined labels in the resource to get terraform managed labels
Expand All @@ -79,7 +89,7 @@ func SetMetadataLabelsDiff(_ context.Context, d *schema.ResourceDiff, meta inter
terraformLabels[k] = v
}

labels := d.Get("metadata.0.labels").(map[string]interface{})
labels := raw.(map[string]interface{})
for k, v := range labels {
terraformLabels[k] = v.(string)
}
Expand Down

0 comments on commit 4aa41b7

Please sign in to comment.