Skip to content

Commit

Permalink
Fix service_attachment.target_service validation (GoogleCloudPlatform…
Browse files Browse the repository at this point in the history
  • Loading branch information
Samir-Cit authored Dec 17, 2024
1 parent 1707d50 commit 3da6915
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions mmv1/products/compute/ServiceAttachment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3da6915

Please sign in to comment.