Skip to content

Commit 0a79583

Browse files
rickard-von-essenDawid212
authored andcommitted
spanner: fixed applying default_labels changes (GoogleCloudPlatform#13269)
1 parent dedde86 commit 0a79583

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

mmv1/templates/terraform/encoders/spanner_instance_update.go.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if d.HasChange("num_nodes") {
1818
if d.HasChange("display_name") {
1919
updateMask = append(updateMask, "displayName")
2020
}
21-
if d.HasChange("labels") {
21+
if d.HasChange("labels") || d.HasChange("terraform_labels") {
2222
updateMask = append(updateMask, "labels")
2323
}
2424
if d.HasChange("processing_units") {

mmv1/third_party/terraform/services/spanner/resource_spanner_instance_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,43 @@ func TestAccSpannerInstance_basic(t *testing.T) {
3636
})
3737
}
3838

39+
func TestAccSpannerInstance_basicUpdateWithProviderDefaultLabels(t *testing.T) {
40+
t.Parallel()
41+
42+
idName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
43+
acctest.VcrTest(t, resource.TestCase{
44+
PreCheck: func() { acctest.AccTestPreCheck(t) },
45+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
46+
CheckDestroy: testAccCheckSpannerInstanceDestroyProducer(t),
47+
Steps: []resource.TestStep{
48+
{
49+
Config: testAccSpannerInstance_basicWithProviderLabel(idName, false),
50+
Check: resource.ComposeTestCheckFunc(
51+
resource.TestCheckResourceAttrSet("google_spanner_instance.basic", "state"),
52+
),
53+
},
54+
{
55+
ResourceName: "google_spanner_instance.basic",
56+
ImportState: true,
57+
ImportStateVerify: true,
58+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
59+
},
60+
{
61+
Config: testAccSpannerInstance_basicWithProviderLabel(idName, true),
62+
Check: resource.ComposeTestCheckFunc(
63+
resource.TestCheckResourceAttrSet("google_spanner_instance.basic", "state"),
64+
),
65+
},
66+
{
67+
ResourceName: "google_spanner_instance.basic",
68+
ImportState: true,
69+
ImportStateVerify: true,
70+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
71+
},
72+
},
73+
})
74+
}
75+
3976
func TestAccSpannerInstance_noNodeCountSpecified(t *testing.T) {
4077
t.Parallel()
4178

@@ -502,6 +539,34 @@ resource "google_spanner_instance" "basic" {
502539
`, name, name, processingUnits)
503540
}
504541

542+
func testAccSpannerInstance_basicWithProviderLabel(name string, addLabel bool) string {
543+
extraLabel := ""
544+
if addLabel {
545+
extraLabel = "\"key2\" = \"value2\""
546+
}
547+
return fmt.Sprintf(`
548+
provider "google" {
549+
alias = "with-labels"
550+
default_labels = {
551+
%s
552+
}
553+
}
554+
555+
resource "google_spanner_instance" "basic" {
556+
provider = google.with-labels
557+
config = "regional-us-central1"
558+
name = "%s"
559+
display_name = "%s"
560+
561+
processing_units = 100
562+
563+
labels = {
564+
"key1" = "value1"
565+
}
566+
}
567+
`, extraLabel, name, name)
568+
}
569+
505570
func testAccSpannerInstance_noNodeCountSpecified(name string) string {
506571
return fmt.Sprintf(`
507572
resource "google_spanner_instance" "basic" {

0 commit comments

Comments
 (0)