Skip to content

Commit

Permalink
Fix bucket patch to support goog-provisioned label
Browse files Browse the repository at this point in the history
  • Loading branch information
guineveresaenger committed Sep 6, 2024
1 parent 28f873a commit e1d4277
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 30 deletions.
3 changes: 0 additions & 3 deletions examples/examples_dotnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ func getCSBaseOptions(t *testing.T) integration.ProgramTestOptions {
Dependencies: []string{
"Pulumi.Gcp",
},
Config: map[string]string{
"gcp:addPulumiAttributionLabel": "false",
},
})

return csharpBase
Expand Down
3 changes: 0 additions & 3 deletions examples/examples_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ func getGoBaseOptions(t *testing.T) integration.ProgramTestOptions {
Dependencies: []string{
"github.com/pulumi/pulumi-gcp/sdk/v8",
},
Config: map[string]string{
"gcp:addPulumiAttributionLabel": "false",
},
})

return goBase
Expand Down
3 changes: 0 additions & 3 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ func getJSBaseOptions(t *testing.T) integration.ProgramTestOptions {
Dependencies: []string{
"@pulumi/gcp",
},
Config: map[string]string{
"gcp:addPulumiAttributionLabel": "false",
},
})

return baseJS
Expand Down
3 changes: 0 additions & 3 deletions examples/examples_py_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ func getPythonBaseOptions(t *testing.T) integration.ProgramTestOptions {
Dependencies: []string{
filepath.Join("..", "sdk", "python", "bin"),
},
Config: map[string]string{
"gcp:addPulumiAttributionLabel": "false",
},
})

return pythonBase
Expand Down
6 changes: 2 additions & 4 deletions examples/examples_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ func TestWarningsNotDuplicated(t *testing.T) {
func TestInvalidExplicitProviderProject(t *testing.T) {
gcpProject := os.Getenv("GCP_PROJECT")
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "non-existent-project"),
Config: map[string]string{
"gcpProj": gcpProject,
},
Dir: filepath.Join(getCwd(t), "non-existent-project"),
Config: map[string]string{"gcpProj": gcpProject},
})
}
3 changes: 1 addition & 2 deletions examples/labels-combinations-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func main() {
}

p, err := gcp.NewProvider(ctx, "prov", &gcp.ProviderArgs{
DefaultLabels: defaultLabelsMap,
AddPulumiAttributionLabel: pulumi.Bool(false),
DefaultLabels: defaultLabelsMap,
})
if err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions examples/labels-combinations-go/step1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func main() {
}

p, err := gcp.NewProvider(ctx, "prov", &gcp.ProviderArgs{
DefaultLabels: defaultLabelsMap,
AddPulumiAttributionLabel: pulumi.Bool(false),
DefaultLabels: defaultLabelsMap,
})
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion examples/non-existent-project/Pulumi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ resources:
type: pulumi:providers:gcp
properties:
project: an-invalid-project
addPulumiAttributionLabel: false
defaultProvider: true
b:
type: gcp:storage:Bucket
Expand Down
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 <[email protected]>
Date: Wed, 24 Apr 2024 12:49:49 +0100
Subject: [PATCH] fix label imports
Subject: [PATCH] Allow for no diff on labels for Bucket imports


diff --git a/google-beta/services/storage/resource_storage_bucket.go b/google-beta/services/storage/resource_storage_bucket.go
Expand All @@ -22,10 +22,10 @@ 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..095be91c5 100644
index ffb1515cf..de278a1b6 100644
--- a/google-beta/tpgresource/labels.go
+++ b/google-beta/tpgresource/labels.go
@@ -31,6 +31,30 @@ func SetLabels(labels map[string]string, d *schema.ResourceData, lineage string)
@@ -31,6 +31,38 @@ func SetLabels(labels map[string]string, d *schema.ResourceData, lineage string)
return d.Set(lineage, transformed)
}

Expand All @@ -38,13 +38,21 @@ index ffb1515cf..095be91c5 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" {
+ continue
+ }
+ transformed[k] = v
+ }
+ }
Expand Down
2 changes: 0 additions & 2 deletions provider/test-programs/bucket-iam-binding/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: bucket-iam-binding
runtime: yaml
config:
gcp:addPulumiAttributionLabel: false
resources:
mybucket:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ resources:
properties:
defaultLabels:
def: defaultlabel
addPulumiAttributionLabel: false
defaultProvider: true
resource:
properties:
Expand Down
2 changes: 0 additions & 2 deletions provider/test-programs/labeled-bucket/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: labeled-bucket
runtime: yaml
description: A minimal Google Cloud Pulumi YAML program
config:
gcp:addPulumiAttributionLabel: false
outputs:
resourceId: ${resource.id}
resourceUrn: ${resource.urn}
Expand Down
1 change: 0 additions & 1 deletion provider/test-programs/project-bucket/Pulumi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ runtime: yaml
description: A minimal Google Cloud Pulumi YAML program
config:
gcpProj: string
gcp:addPulumiAttributionLabel: false
resources:
# Create a GCP resource (Storage Bucket)
my-bucket:
Expand Down

0 comments on commit e1d4277

Please sign in to comment.