diff --git a/mmv1/products/compute/ServiceAttachment.yaml b/mmv1/products/compute/ServiceAttachment.yaml index 3e4254b37208..f0e27bee6dec 100644 --- a/mmv1/products/compute/ServiceAttachment.yaml +++ b/mmv1/products/compute/ServiceAttachment.yaml @@ -170,6 +170,7 @@ properties: required: true immutable: true diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName' + custom_expand: 'templates/terraform/custom_expand/service_attachment_target_service.go.tmpl' - name: 'natSubnets' type: Array description: | diff --git a/mmv1/templates/terraform/custom_expand/service_attachment_target_service.go.tmpl b/mmv1/templates/terraform/custom_expand/service_attachment_target_service.go.tmpl new file mode 100644 index 000000000000..512d7fcf22bf --- /dev/null +++ b/mmv1/templates/terraform/custom_expand/service_attachment_target_service.go.tmpl @@ -0,0 +1,15 @@ +func expand{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + resource := strings.Split(v.(string), "/") + resourceKind := resource[len(resource)-2] + resourceBound := resource[len(resource)-4] + if len(resource) < 4 { + return nil, fmt.Errorf("invalid value for target_service") + } + + _, err := tpgresource.ParseRegionalFieldValue(resourceKind, v.(string), "project", resourceBound, "zone", d, config, true) + if err != nil { + return nil, fmt.Errorf("invalid value for target_service: %w", err) + } + + return v, nil +} diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_service_attachment_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_service_attachment_test.go.tmpl index a1d62492a635..ca1cbca38a37 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_service_attachment_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_service_attachment_test.go.tmpl @@ -414,7 +414,7 @@ resource "google_compute_service_attachment" "default" { enable_proxy_protocol = false connection_preference = "ACCEPT_AUTOMATIC" nat_subnets = [google_compute_subnetwork.psc.id] - target_service = google_network_services_gateway.foobar.self_link + target_service = google_network_services_gateway.default.self_link } resource "google_certificate_manager_certificate" "default" { @@ -473,14 +473,14 @@ resource "google_network_security_gateway_security_policy_rule" "default" { basic_profile = "ALLOW" } -resource "google_network_services_gateway" "foobar" { +resource "google_network_services_gateway" "default" { name = "tf-test-sa-swp-%{random_suffix}" location = "us-east1" addresses = ["10.128.0.99"] type = "SECURE_WEB_GATEWAY" ports = [443] description = "my description" - scope = "%s" + scope = "serviceAttachment" certificate_urls = [google_certificate_manager_certificate.default.id] gateway_security_policy = google_network_security_gateway_security_policy.default.id network = google_compute_network.default.id