Skip to content

Commit

Permalink
Second stab at fixing import patch
Browse files Browse the repository at this point in the history
  • Loading branch information
guineveresaenger committed Sep 9, 2024
1 parent 61b3938 commit e19dbc1
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Venelin <venelin@pulumi.com>
Date: Wed, 24 Apr 2024 12:49:49 +0100
Subject: [PATCH] Allow for no diff on labels for Bucket imports
Subject: [PATCH] Bucket: Skip default labels for Import and Create


diff --git a/google-beta/services/storage/resource_storage_bucket.go b/google-beta/services/storage/resource_storage_bucket.go
Expand All @@ -22,14 +22,14 @@ index e4be7399d..8fbeee2ab 100644
}
if err := d.Set("effective_labels", res.Labels); err != nil {
diff --git a/google-beta/tpgresource/labels.go b/google-beta/tpgresource/labels.go
index ffb1515cf..de278a1b6 100644
index ffb1515cf..669e561c3 100644
--- a/google-beta/tpgresource/labels.go
+++ b/google-beta/tpgresource/labels.go
@@ -31,6 +31,38 @@ func SetLabels(labels map[string]string, d *schema.ResourceData, lineage string)
@@ -31,6 +31,34 @@ func SetLabels(labels map[string]string, d *schema.ResourceData, lineage string)
return d.Set(lineage, transformed)
}

+// Like SetLabels but also takes defaultLabels and skips them
+// SetLabelsNoDefaults is like SetLabels but also takes defaultLabels and skips them
+// if we are setting the labels field.
+func SetLabelsNoDefaults(labels map[string]string, d *schema.ResourceData, lineage string, defaultLabels map[string]string) error {
+ transformed := make(map[string]interface{})
Expand All @@ -38,19 +38,15 @@ index ffb1515cf..de278a1b6 100644
+ // We are reading after an update, so populate just the user defined labels.
+ if labels != nil {
+ for k := range v.(map[string]interface{}) {
+ // This label is set by the provider.
+ // It is neither a defaultLabel, nor is it user set. Skip.
+ if k == "goog-pulumi-provisioned" && lineage == "labels" {
+ continue
+ }
+ transformed[k] = labels[k]
+ }
+ }
+ } else {
+ // We are reading for an import, so populate all of the labels, except the skipped ones.
+ for k, v := range labels {
+ if _, ok := defaultLabels[k]; !ok || lineage != "labels" {
+ if k == "goog-pulumi-provisioned" {
+ if k == "goog-pulumi-provisioned" && lineage == "labels" {
+ // We do not write the provisioning label to resource label fields.
+ continue
+ }
+ transformed[k] = v
Expand Down

0 comments on commit e19dbc1

Please sign in to comment.