-
Notifications
You must be signed in to change notification settings - Fork 52
/
0009-Bucket-Skip-default-labels-for-Import-and-Create.patch
62 lines (59 loc) · 2.91 KB
/
0009-Bucket-Skip-default-labels-for-Import-and-Create.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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] 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
index e4be7399d..8fbeee2ab 100644
--- a/google-beta/services/storage/resource_storage_bucket.go
+++ b/google-beta/services/storage/resource_storage_bucket.go
@@ -1858,10 +1858,10 @@ func setStorageBucket(d *schema.ResourceData, config *transport_tpg.Config, res
if err := d.Set("lifecycle_rule", flattenBucketLifecycle(d, res.Lifecycle)); err != nil {
return fmt.Errorf("Error setting lifecycle_rule: %s", err)
}
- if err := tpgresource.SetLabels(res.Labels, d, "labels"); err != nil {
+ if err := tpgresource.SetLabelsNoDefaults(res.Labels, d, "labels", config.DefaultLabels); err != nil {
return fmt.Errorf("Error setting labels: %s", err)
}
- if err := tpgresource.SetLabels(res.Labels, d, "terraform_labels"); err != nil {
+ if err := tpgresource.SetLabelsNoDefaults(res.Labels, d, "terraform_labels", config.DefaultLabels); err != nil {
return fmt.Errorf("Error setting terraform_labels: %s", err)
}
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..669e561c3 100644
--- a/google-beta/tpgresource/labels.go
+++ b/google-beta/tpgresource/labels.go
@@ -31,6 +31,34 @@ func SetLabels(labels map[string]string, d *schema.ResourceData, lineage string)
return d.Set(lineage, transformed)
}
+// 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{})
+
+ if v, ok := d.GetOk(lineage); ok {
+ // We are reading after an update, so populate just the user defined labels.
+ if labels != nil {
+ for k := range v.(map[string]interface{}) {
+ 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" && lineage == "labels" {
+ // We do not write the provisioning label to resource label fields.
+ continue
+ }
+ transformed[k] = v
+ }
+ }
+ }
+
+ return d.Set(lineage, transformed)
+}
+
// Sets the "labels" field and "terraform_labels" with the value of the field "effective_labels" for data sources.
// When reading data source, as the labels field is unavailable in the configuration of the data source,
// the "labels" field will be empty. With this funciton, the labels "field" will have all of labels in the resource.