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

Check if labels field exists in customDiff function #6337

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
3 changes: 3 additions & 0 deletions .changelog/9043.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
provider: fixed the bug that labels/annotations field not exists in GA for some resources
```
10 changes: 10 additions & 0 deletions google-beta/tpgresource/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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 @@ -36,6 +41,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 google-beta/tpgresource/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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 @@ -73,6 +78,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 @@ -81,7 +91,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