Skip to content

Commit 9957b96

Browse files
wiktornanoopkverma-google
authored andcommitted
Fix global_forwarding_rule labels (GoogleCloudPlatform#12737)
1 parent c430f30 commit 9957b96

File tree

3 files changed

+175
-6
lines changed

3 files changed

+175
-6
lines changed

mmv1/products/compute/GlobalForwardingRule.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ async:
4141
resource_inside_response: false
4242
collection_url_key: 'items'
4343
custom_code:
44+
pre_create: 'templates/terraform/pre_create/compute_global_forwarding_rule.go.tmpl'
4445
post_create: 'templates/terraform/post_create/labels.tmpl'
4546
legacy_long_form_project: true
4647
examples:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Labels cannot be set in a create for PSC forwarding rules, so remove it from the CREATE request.
2+
if strings.Contains(targetProp.(string), "/serviceAttachments/") ||
3+
targetProp.(string) == "all-apis" ||
4+
targetProp.(string) == "vpc-sc" {
5+
if _, ok := obj["labels"]; ok {
6+
delete(obj, "labels")
7+
}
8+
}

mmv1/third_party/terraform/services/compute/resource_compute_global_forwarding_rule_test.go.tmpl

+166-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func TestAccComputeGlobalForwardingRule_ipv6(t *testing.T) {
8787
})
8888
}
8989

90-
{{ if ne $.TargetVersionName `ga` -}}
9190
func TestAccComputeGlobalForwardingRule_labels(t *testing.T) {
9291
t.Parallel()
9392

@@ -123,7 +122,72 @@ func TestAccComputeGlobalForwardingRule_labels(t *testing.T) {
123122
},
124123
})
125124
}
126-
{{- end }}
125+
126+
func TestAccComputeGlobalForwardingRule_allApisLabels(t *testing.T) {
127+
t.Parallel()
128+
129+
fr := fmt.Sprintf("frtest%s", acctest.RandString(t, 10))
130+
address := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(t, 10))
131+
132+
acctest.VcrTest(t, resource.TestCase{
133+
PreCheck: func() { acctest.AccTestPreCheck(t) },
134+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
135+
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroyProducer(t),
136+
Steps: []resource.TestStep{
137+
{
138+
Config: testAccComputeGlobalForwardingRule_allApisLabels(fr, address),
139+
},
140+
{
141+
ResourceName: "google_compute_global_forwarding_rule.forwarding_rule",
142+
ImportState: true,
143+
ImportStateVerify: true,
144+
ImportStateVerifyIgnore: []string{"port_range", "target", "labels", "terraform_labels"},
145+
},
146+
{
147+
Config: testAccComputeGlobalForwardingRule_allApisLabelsUpdated(fr, address),
148+
},
149+
{
150+
ResourceName: "google_compute_global_forwarding_rule.forwarding_rule",
151+
ImportState: true,
152+
ImportStateVerify: true,
153+
ImportStateVerifyIgnore: []string{"port_range", "target", "labels", "terraform_labels"},
154+
},
155+
},
156+
})
157+
}
158+
159+
func TestAccComputeGlobalForwardingRule_vpcscLabels(t *testing.T) {
160+
t.Parallel()
161+
162+
fr := fmt.Sprintf("frtest%s", acctest.RandString(t, 10))
163+
address := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(t, 10))
164+
165+
acctest.VcrTest(t, resource.TestCase{
166+
PreCheck: func() { acctest.AccTestPreCheck(t) },
167+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
168+
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroyProducer(t),
169+
Steps: []resource.TestStep{
170+
{
171+
Config: testAccComputeGlobalForwardingRule_vpcscLabels(fr, address),
172+
},
173+
{
174+
ResourceName: "google_compute_global_forwarding_rule.forwarding_rule",
175+
ImportState: true,
176+
ImportStateVerify: true,
177+
ImportStateVerifyIgnore: []string{"port_range", "target", "labels", "terraform_labels"},
178+
},
179+
{
180+
Config: testAccComputeGlobalForwardingRule_vpcscLabelsUpdated(fr, address),
181+
},
182+
{
183+
ResourceName: "google_compute_global_forwarding_rule.forwarding_rule",
184+
ImportState: true,
185+
ImportStateVerify: true,
186+
ImportStateVerifyIgnore: []string{"port_range", "labels", "terraform_labels"},
187+
},
188+
},
189+
})
190+
}
127191

128192
{{ if ne $.TargetVersionName `ga` -}}
129193
func TestAccComputeGlobalForwardingRule_internalLoadBalancing(t *testing.T) {
@@ -361,7 +425,6 @@ resource "google_compute_url_map" "url_map" {
361425
`, fr, targetProxy, proxy, proxy2, backend, hc, urlmap)
362426
}
363427

364-
{{ if ne $.TargetVersionName `ga` -}}
365428
func testAccComputeGlobalForwardingRule_labels(fr, proxy, backend, hc, urlmap string) string {
366429
return fmt.Sprintf(`
367430
resource "google_compute_global_forwarding_rule" "forwarding_rule" {
@@ -416,9 +479,7 @@ resource "google_compute_url_map" "urlmap" {
416479
}
417480
`, fr, proxy, backend, hc, urlmap)
418481
}
419-
{{- end }}
420482

421-
{{ if ne $.TargetVersionName `ga` -}}
422483
func testAccComputeGlobalForwardingRule_labelsUpdated(fr, proxy, backend, hc, urlmap string) string {
423484
return fmt.Sprintf(`
424485
resource "google_compute_global_forwarding_rule" "forwarding_rule" {
@@ -473,7 +534,106 @@ resource "google_compute_url_map" "urlmap" {
473534
}
474535
`, fr, proxy, backend, hc, urlmap)
475536
}
476-
{{- end }}
537+
538+
func testAccComputeGlobalForwardingRule_allApisLabels(fr, address string) string {
539+
return fmt.Sprintf(`
540+
resource "google_compute_global_forwarding_rule" "forwarding_rule" {
541+
name = "%s"
542+
network = "default"
543+
target = "all-apis"
544+
ip_address = google_compute_global_address.default.id
545+
load_balancing_scheme = ""
546+
labels = {
547+
my-label = "a-value"
548+
a-different-label = "my-second-label-value"
549+
}
550+
}
551+
552+
resource "google_compute_global_address" "default" {
553+
name = "%s"
554+
address_type = "INTERNAL"
555+
purpose = "PRIVATE_SERVICE_CONNECT"
556+
network = "default"
557+
address = "100.100.100.105"
558+
}
559+
560+
`, fr, address)
561+
}
562+
563+
func testAccComputeGlobalForwardingRule_allApisLabelsUpdated(fr, address string) string {
564+
return fmt.Sprintf(`
565+
resource "google_compute_global_forwarding_rule" "forwarding_rule" {
566+
name = "%s"
567+
network = "default"
568+
target = "all-apis"
569+
ip_address = google_compute_global_address.default.id
570+
load_balancing_scheme = ""
571+
labels = {
572+
my-label = "a-value"
573+
a-different-label = "my-third-label-value"
574+
}
575+
}
576+
577+
resource "google_compute_global_address" "default" {
578+
name = "%s"
579+
address_type = "INTERNAL"
580+
purpose = "PRIVATE_SERVICE_CONNECT"
581+
network = "default"
582+
address = "100.100.100.105"
583+
}
584+
585+
`, fr, address)
586+
}
587+
588+
func testAccComputeGlobalForwardingRule_vpcscLabels(fr, address string) string {
589+
return fmt.Sprintf(`
590+
resource "google_compute_global_forwarding_rule" "forwarding_rule" {
591+
name = "%s"
592+
network = "default"
593+
target = "vpc-sc"
594+
ip_address = google_compute_global_address.default.id
595+
load_balancing_scheme = ""
596+
labels = {
597+
my-label = "a-value"
598+
a-different-label = "my-second-label-value"
599+
}
600+
}
601+
602+
resource "google_compute_global_address" "default" {
603+
name = "%s"
604+
address_type = "INTERNAL"
605+
purpose = "PRIVATE_SERVICE_CONNECT"
606+
network = "default"
607+
address = "100.100.100.106"
608+
}
609+
610+
`, fr, address)
611+
}
612+
613+
func testAccComputeGlobalForwardingRule_vpcscLabelsUpdated(fr, address string) string {
614+
return fmt.Sprintf(`
615+
resource "google_compute_global_forwarding_rule" "forwarding_rule" {
616+
name = "%s"
617+
network = "default"
618+
target = "vpc-sc"
619+
ip_address = google_compute_global_address.default.id
620+
load_balancing_scheme = ""
621+
labels = {
622+
my-label = "a-value"
623+
a-different-label = "my-third-label-value"
624+
}
625+
}
626+
627+
resource "google_compute_global_address" "default" {
628+
name = "%s"
629+
address_type = "INTERNAL"
630+
purpose = "PRIVATE_SERVICE_CONNECT"
631+
network = "default"
632+
address = "100.100.100.106"
633+
}
634+
635+
`, fr, address)
636+
}
477637

478638
func testAccComputeGlobalForwardingRule_ipv6(fr, proxy, backend, hc, urlmap string) string {
479639
return fmt.Sprintf(`

0 commit comments

Comments
 (0)