Skip to content

Commit 8db8acd

Browse files
authored
Add Service Attachment support for Secure Web Proxy (#11107)
1 parent af5c70f commit 8db8acd

File tree

3 files changed

+118
-12
lines changed

3 files changed

+118
-12
lines changed

mmv1/products/compute/ServiceAttachment.yaml

+3-6
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,13 @@ properties:
156156
description: |
157157
The status of the connection from the consumer forwarding rule to
158158
this service attachment.
159-
- !ruby/object:Api::Type::ResourceRef
159+
- !ruby/object:Api::Type::String
160160
name: targetService
161161
required: true
162162
immutable: true
163-
resource: 'ForwardingRule'
164-
imports: 'selfLink'
163+
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
165164
description: |
166-
The URL of a forwarding rule that represents the service identified by
167-
this service attachment.
168-
custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.erb'
165+
The URL of a service serving the endpoint identified by this service attachment.
169166
- !ruby/object:Api::Type::Array
170167
name: 'natSubnets'
171168
required: true

mmv1/products/compute/go_ServiceAttachment.yaml

+3-6
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,12 @@ properties:
157157
this service attachment.
158158
output: true
159159
- name: 'targetService'
160-
type: ResourceRef
160+
type: String
161161
description: |
162-
The URL of a forwarding rule that represents the service identified by
163-
this service attachment.
162+
The URL of a service serving the endpoint identified by this service attachment.
164163
required: true
165164
immutable: true
166-
custom_expand: 'templates/terraform/custom_expand/go/resourceref_with_validation.go.tmpl'
167-
resource: 'ForwardingRule'
168-
imports: 'selfLink'
165+
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
169166
- name: 'natSubnets'
170167
type: Array
171168
description: |

mmv1/third_party/terraform/services/compute/resource_compute_service_attachment_test.go

+112
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,115 @@ resource "google_compute_subnetwork" "psc_ilb_nat" {
231231
}
232232
`, context)
233233
}
234+
235+
func TestAccComputeServiceAttachment_serviceAttachmentBasicExampleGateway(t *testing.T) {
236+
t.Parallel()
237+
238+
context := map[string]interface{}{
239+
"random_suffix": acctest.RandString(t, 10),
240+
}
241+
242+
acctest.VcrTest(t, resource.TestCase{
243+
PreCheck: func() { acctest.AccTestPreCheck(t) },
244+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
245+
CheckDestroy: testAccCheckComputeServiceAttachmentDestroyProducer(t),
246+
Steps: []resource.TestStep{
247+
{
248+
Config: testAccComputeServiceAttachment_serviceAttachmentBasicExampleGateway(context),
249+
},
250+
{
251+
ResourceName: "google_compute_service_attachment.default",
252+
ImportState: true,
253+
ImportStateVerify: true,
254+
ImportStateVerifyIgnore: []string{"target_service", "region"},
255+
},
256+
},
257+
})
258+
}
259+
260+
func testAccComputeServiceAttachment_serviceAttachmentBasicExampleGateway(context map[string]interface{}) string {
261+
return acctest.Nprintf(`
262+
resource "google_compute_service_attachment" "default" {
263+
name = "tf-test-sa-%{random_suffix}"
264+
region = "us-east1"
265+
description = "A service attachment configured with Terraform"
266+
267+
enable_proxy_protocol = false
268+
connection_preference = "ACCEPT_AUTOMATIC"
269+
nat_subnets = [google_compute_subnetwork.psc.id]
270+
target_service = google_network_services_gateway.foobar.self_link
271+
}
272+
273+
resource "google_certificate_manager_certificate" "default" {
274+
name = "tf-test-sa-certificate-%{random_suffix}"
275+
location = "us-east1"
276+
self_managed {
277+
pem_certificate = file("test-fixtures/cert.pem")
278+
pem_private_key = file("test-fixtures/private-key.pem")
279+
}
280+
}
281+
282+
resource "google_compute_network" "default" {
283+
name = "tf-test-sa-network-%{random_suffix}"
284+
auto_create_subnetworks = false
285+
}
286+
287+
resource "google_compute_subnetwork" "psc" {
288+
name = "tf-test-sa-psc-subnet-%{random_suffix}"
289+
region = "us-east1"
290+
291+
network = google_compute_network.default.id
292+
purpose = "PRIVATE_SERVICE_CONNECT"
293+
ip_cidr_range = "10.1.0.0/16"
294+
}
295+
296+
resource "google_compute_subnetwork" "proxyonly" {
297+
name = "tf-test-sa-proxyonly-subnet-%{random_suffix}"
298+
purpose = "REGIONAL_MANAGED_PROXY"
299+
ip_cidr_range = "192.168.0.0/23"
300+
region = "us-east1"
301+
network = google_compute_network.default.id
302+
role = "ACTIVE"
303+
}
304+
305+
resource "google_compute_subnetwork" "default" {
306+
name = "tf-test-sa-default-subnet-%{random_suffix}"
307+
purpose = "PRIVATE"
308+
ip_cidr_range = "10.128.0.0/20"
309+
region = "us-east1"
310+
network = google_compute_network.default.id
311+
role = "ACTIVE"
312+
}
313+
314+
resource "google_network_security_gateway_security_policy" "default" {
315+
name = "tf-test-sa-swp-policy-%{random_suffix}"
316+
location = "us-east1"
317+
}
318+
319+
resource "google_network_security_gateway_security_policy_rule" "default" {
320+
name = "tf-test-sa-swp-rule-%{random_suffix}"
321+
location = "us-east1"
322+
gateway_security_policy = google_network_security_gateway_security_policy.default.name
323+
enabled = true
324+
priority = 1
325+
session_matcher = "host() == 'example.com'"
326+
basic_profile = "ALLOW"
327+
}
328+
329+
resource "google_network_services_gateway" "foobar" {
330+
name = "tf-test-sa-swp-%{random_suffix}"
331+
location = "us-east1"
332+
addresses = ["10.128.0.99"]
333+
type = "SECURE_WEB_GATEWAY"
334+
ports = [443]
335+
description = "my description"
336+
scope = "%s"
337+
certificate_urls = [google_certificate_manager_certificate.default.id]
338+
gateway_security_policy = google_network_security_gateway_security_policy.default.id
339+
network = google_compute_network.default.id
340+
subnetwork = google_compute_subnetwork.default.id
341+
delete_swg_autogen_router_on_destroy = true
342+
depends_on = [google_compute_subnetwork.proxyonly]
343+
}
344+
`, context)
345+
}

0 commit comments

Comments
 (0)