Skip to content

Commit 44b24f5

Browse files
Fix service_attachment.target_service validation (#12571) (#8924)
[upstream:3da69150b3f378d0df0be20ce2dcf9b243445783] Signed-off-by: Modular Magician <[email protected]>
1 parent 2043f1b commit 44b24f5

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

.changelog/12571.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: add back the validation for `target_service` field on the `google_compute_service_attachment` resource to validade a `ForwardingRule` or `Gateway` URL.
3+
```

google-beta/services/compute/resource_compute_service_attachment.go

+13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"log"
2424
"net/http"
2525
"reflect"
26+
"strings"
2627
"time"
2728

2829
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
@@ -887,6 +888,18 @@ func expandComputeServiceAttachmentConnectionPreference(v interface{}, d tpgreso
887888
}
888889

889890
func expandComputeServiceAttachmentTargetService(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
891+
resource := strings.Split(v.(string), "/")
892+
resourceKind := resource[len(resource)-2]
893+
resourceBound := resource[len(resource)-4]
894+
if len(resource) < 4 {
895+
return nil, fmt.Errorf("invalid value for target_service")
896+
}
897+
898+
_, err := tpgresource.ParseRegionalFieldValue(resourceKind, v.(string), "project", resourceBound, "zone", d, config, true)
899+
if err != nil {
900+
return nil, fmt.Errorf("invalid value for target_service: %w", err)
901+
}
902+
890903
return v, nil
891904
}
892905

google-beta/services/compute/resource_compute_service_attachment_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ resource "google_compute_service_attachment" "default" {
416416
enable_proxy_protocol = false
417417
connection_preference = "ACCEPT_AUTOMATIC"
418418
nat_subnets = [google_compute_subnetwork.psc.id]
419-
target_service = google_network_services_gateway.foobar.self_link
419+
target_service = google_network_services_gateway.default.self_link
420420
}
421421
422422
resource "google_certificate_manager_certificate" "default" {
@@ -475,14 +475,14 @@ resource "google_network_security_gateway_security_policy_rule" "default" {
475475
basic_profile = "ALLOW"
476476
}
477477
478-
resource "google_network_services_gateway" "foobar" {
478+
resource "google_network_services_gateway" "default" {
479479
name = "tf-test-sa-swp-%{random_suffix}"
480480
location = "us-east1"
481481
addresses = ["10.128.0.99"]
482482
type = "SECURE_WEB_GATEWAY"
483483
ports = [443]
484484
description = "my description"
485-
scope = "%s"
485+
scope = "serviceAttachment"
486486
certificate_urls = [google_certificate_manager_certificate.default.id]
487487
gateway_security_policy = google_network_security_gateway_security_policy.default.id
488488
network = google_compute_network.default.id

0 commit comments

Comments
 (0)