@@ -65,11 +65,112 @@ resource "google_network_services_gateway" "foobar" {
6565 description = "update description"
6666 labels = {
6767 foo = "bar"
68- }
68+ }
6969}
7070` , gatewayName )
7171}
7272
73+ func TestAccNetworkServicesGateway_networkServicesGatewaySecureWebProxyWithoutAddresses (t * testing.T ) {
74+ t .Parallel ()
75+
76+ context := map [string ]interface {}{
77+ "random_suffix" : acctest .RandString (t , 10 ),
78+ }
79+
80+ acctest .VcrTest (t , resource.TestCase {
81+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
82+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
83+ CheckDestroy : testAccCheckNetworkServicesGatewayDestroyProducer (t ),
84+ Steps : []resource.TestStep {
85+ {
86+ Config : testAccNetworkServicesGateway_networkServicesGatewaySecureWebProxy (context , false ),
87+ },
88+ {
89+ ResourceName : "google_network_services_gateway.default" ,
90+ ImportState : true ,
91+ ImportStateVerify : true ,
92+ ImportStateVerifyIgnore : []string {"name" , "location" , "delete_swg_autogen_router_on_destroy" , "labels" , "terraform_labels" },
93+ },
94+ },
95+ })
96+ }
97+
98+ func testAccNetworkServicesGateway_networkServicesGatewaySecureWebProxy (context map [string ]interface {}, withAddresses bool ) string {
99+ config := ""
100+ config += acctest .Nprintf (`
101+ resource "google_certificate_manager_certificate" "default" {
102+ name = "tf-test-my-certificate-%{random_suffix}"
103+ location = "us-central1"
104+ self_managed {
105+ pem_certificate = file("test-fixtures/cert.pem")
106+ pem_private_key = file("test-fixtures/private-key.pem")
107+ }
108+ }
109+
110+ resource "google_compute_network" "default" {
111+ name = "tf-test-my-network-%{random_suffix}"
112+ routing_mode = "REGIONAL"
113+ auto_create_subnetworks = false
114+ }
115+
116+ resource "google_compute_subnetwork" "default" {
117+ name = "tf-test-my-subnetwork-name-%{random_suffix}"
118+ purpose = "PRIVATE"
119+ ip_cidr_range = "10.128.0.0/20"
120+ region = "us-central1"
121+ network = google_compute_network.default.id
122+ role = "ACTIVE"
123+ }
124+
125+ resource "google_compute_subnetwork" "proxyonlysubnet" {
126+ name = "tf-test-my-proxy-only-subnetwork-%{random_suffix}"
127+ purpose = "REGIONAL_MANAGED_PROXY"
128+ ip_cidr_range = "192.168.0.0/23"
129+ region = "us-central1"
130+ network = google_compute_network.default.id
131+ role = "ACTIVE"
132+ }
133+
134+ resource "google_network_security_gateway_security_policy" "default" {
135+ name = "tf-test-my-policy-name-%{random_suffix}"
136+ location = "us-central1"
137+ }
138+
139+ resource "google_network_security_gateway_security_policy_rule" "default" {
140+ name = "tf-test-my-policyrule-name-%{random_suffix}"
141+ location = "us-central1"
142+ gateway_security_policy = google_network_security_gateway_security_policy.default.name
143+ enabled = true
144+ priority = 1
145+ session_matcher = "host() == 'example.com'"
146+ basic_profile = "ALLOW"
147+ }
148+
149+ resource "google_network_services_gateway" "default" {
150+ name = "tf-test-my-gateway-%{random_suffix}"
151+ location = "us-central1"` , context )
152+
153+ if withAddresses {
154+ config += `
155+ addresses = ["10.128.0.99"]`
156+ }
157+
158+ config += acctest .Nprintf (`
159+ type = "SECURE_WEB_GATEWAY"
160+ ports = [443]
161+ scope = "tf-test-my-default-scope-%{random_suffix}"
162+ certificate_urls = [google_certificate_manager_certificate.default.id]
163+ gateway_security_policy = google_network_security_gateway_security_policy.default.id
164+ network = google_compute_network.default.id
165+ subnetwork = google_compute_subnetwork.default.id
166+ delete_swg_autogen_router_on_destroy = true
167+ depends_on = [google_compute_subnetwork.proxyonlysubnet]
168+ }
169+ ` , context )
170+
171+ return config
172+ }
173+
73174// TODO(#14600): Enable the test once the api allows to update the fields for secure web gateway type.
74175//func TestAccNetworkServicesGateway_updateSwp(t *testing.T) {
75176//cmName := fmt.Sprintf("tf-test-gateway-swp-cm-%s", acctest.RandString(t, 10))
@@ -361,12 +462,12 @@ resource "google_network_security_gateway_security_policy_rule" "default" {
361462 name = "%s"
362463 location = "us-west1"
363464 gateway_security_policy = google_network_security_gateway_security_policy.default.name
364- enabled = true
465+ enabled = true
365466 priority = 1
366467 session_matcher = "host() == 'example.com'"
367468 basic_profile = "ALLOW"
368469}
369-
470+
370471resource "google_network_services_gateway" "gateway1" {
371472 name = "%s"
372473 location = "us-west1"
@@ -455,12 +556,12 @@ resource "google_network_security_gateway_security_policy_rule" "default" {
455556 name = "%s"
456557 location = "us-west1"
457558 gateway_security_policy = google_network_security_gateway_security_policy.default.name
458- enabled = true
559+ enabled = true
459560 priority = 1
460561 session_matcher = "host() == 'example.com'"
461562 basic_profile = "ALLOW"
462563}
463-
564+
464565resource "google_network_services_gateway" "gateway1" {
465566 name = "%s"
466567 location = "us-west1"
@@ -577,12 +678,12 @@ resource "google_network_security_gateway_security_policy_rule" "default" {
577678 name = "%s"
578679 location = "us-west2"
579680 gateway_security_policy = google_network_security_gateway_security_policy.default.name
580- enabled = true
681+ enabled = true
581682 priority = 1
582683 session_matcher = "host() == 'example.com'"
583684 basic_profile = "ALLOW"
584685}
585-
686+
586687resource "google_network_services_gateway" "gateway1" {
587688 name = "%s"
588689 location = "us-west2"
@@ -686,12 +787,12 @@ resource "google_network_security_gateway_security_policy_rule" "default" {
686787 name = "%s"
687788 location = "us-west2"
688789 gateway_security_policy = google_network_security_gateway_security_policy.default.name
689- enabled = true
790+ enabled = true
690791 priority = 1
691792 session_matcher = "host() == 'example.com'"
692793 basic_profile = "ALLOW"
693794}
694-
795+
695796resource "google_network_services_gateway" "gateway1" {
696797 name = "%s"
697798 location = "us-west2"
0 commit comments