Skip to content

Commit 8439125

Browse files
making sure swp can be created without scope and certificateUrls (#8390) (#15273)
* making sure swp can be created without scope and certificateUrls Signed-off-by: Modular Magician <[email protected]>
1 parent 0016894 commit 8439125

File tree

4 files changed

+102
-16
lines changed

4 files changed

+102
-16
lines changed

.changelog/8390.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
network_services: removing required flags from `scope` field in `google_network_services_gateway` resource
3+
```

google/resource_network_services_gateway_test.go

+83
Original file line numberDiff line numberDiff line change
@@ -733,3 +733,86 @@ resource "google_compute_subnetwork" "proxyonlysubnet2" {
733733
734734
`, cmName, netName, subnetName, pSubnetName, policyName, ruleName, gatewayName, gatewayScope, net2Name, subnet2Name, pSubnet2Name)
735735
}
736+
737+
func TestAccNetworkServicesGateway_minimalSwp(t *testing.T) {
738+
netName := fmt.Sprintf("tf-test-gateway-swp-net-%s", acctest.RandString(t, 10))
739+
subnetName := fmt.Sprintf("tf-test-gateway-swp-subnet-%s", acctest.RandString(t, 10))
740+
pSubnetName := fmt.Sprintf("tf-test-gateway-swp-proxyonly-%s", acctest.RandString(t, 10))
741+
policyName := fmt.Sprintf("tf-test-gateway-swp-policy-%s", acctest.RandString(t, 10))
742+
ruleName := fmt.Sprintf("tf-test-gateway-swp-rule-%s", acctest.RandString(t, 10))
743+
gatewayName := fmt.Sprintf("tf-test-gateway-swp-%s", acctest.RandString(t, 10))
744+
745+
acctest.VcrTest(t, resource.TestCase{
746+
PreCheck: func() { acctest.AccTestPreCheck(t) },
747+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
748+
CheckDestroy: testAccCheckNetworkServicesGatewayDestroyProducer(t),
749+
Steps: []resource.TestStep{
750+
{
751+
Config: testAccNetworkServicesGateway_minimalSwp(netName, subnetName, pSubnetName, policyName, ruleName, gatewayName),
752+
},
753+
{
754+
ResourceName: "google_network_services_gateway.foobar",
755+
ImportState: true,
756+
ImportStateVerify: true,
757+
ImportStateVerifyIgnore: []string{"name", "location", "delete_swg_autogen_router_on_destroy"},
758+
},
759+
},
760+
})
761+
}
762+
763+
func testAccNetworkServicesGateway_minimalSwp(netName, subnetName, pSubnetName, policyName, ruleName, gatewayName string) string {
764+
return fmt.Sprintf(`
765+
resource "google_compute_network" "default" {
766+
name = "%s"
767+
routing_mode = "REGIONAL"
768+
auto_create_subnetworks = false
769+
}
770+
771+
resource "google_compute_subnetwork" "proxyonlysubnet" {
772+
name = "%s"
773+
purpose = "REGIONAL_MANAGED_PROXY"
774+
ip_cidr_range = "192.168.0.0/23"
775+
region = "us-central1"
776+
network = google_compute_network.default.id
777+
role = "ACTIVE"
778+
}
779+
780+
resource "google_compute_subnetwork" "default" {
781+
name = "%s"
782+
purpose = "PRIVATE"
783+
ip_cidr_range = "10.128.0.0/20"
784+
region = "us-central1"
785+
network = google_compute_network.default.id
786+
role = "ACTIVE"
787+
}
788+
789+
resource "google_network_security_gateway_security_policy" "default" {
790+
name = "%s"
791+
location = "us-central1"
792+
}
793+
794+
resource "google_network_security_gateway_security_policy_rule" "default" {
795+
name = "%s"
796+
location = "us-central1"
797+
gateway_security_policy = google_network_security_gateway_security_policy.default.name
798+
enabled = true
799+
priority = 1
800+
session_matcher = "host() == 'example.com'"
801+
basic_profile = "ALLOW"
802+
}
803+
804+
resource "google_network_services_gateway" "foobar" {
805+
name = "%s"
806+
location = "us-central1"
807+
addresses = ["10.128.0.99"]
808+
type = "SECURE_WEB_GATEWAY"
809+
ports = [443]
810+
description = "my description"
811+
gateway_security_policy = google_network_security_gateway_security_policy.default.id
812+
network = google_compute_network.default.id
813+
subnetwork = google_compute_subnetwork.default.id
814+
delete_swg_autogen_router_on_destroy = true
815+
depends_on = [google_compute_subnetwork.proxyonlysubnet]
816+
}
817+
`, netName, subnetName, pSubnetName, policyName, ruleName, gatewayName)
818+
}

google/services/networkservices/resource_network_services_gateway.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,6 @@ limited to 1 port. Gateways of type 'OPEN_MESH' listen on 0.0.0.0 and support mu
180180
Type: schema.TypeInt,
181181
},
182182
},
183-
"scope": {
184-
Type: schema.TypeString,
185-
Required: true,
186-
ForceNew: true,
187-
Description: `Immutable. Scope determines how configuration across multiple Gateway instances are merged.
188-
The configuration for multiple Gateway instances with the same scope will be merged as presented as
189-
a single coniguration to the proxy/load balancer.
190-
Max length 64 characters. Scope should start with a letter and can only have letters, numbers, hyphens.`,
191-
},
192183
"type": {
193184
Type: schema.TypeString,
194185
Required: true,
@@ -250,6 +241,15 @@ The default value is 'global'.`,
250241
Description: `The relative resource name identifying the VPC network that is using this configuration.
251242
For example: 'projects/*/global/networks/network-1'.
252243
Currently, this field is specific to gateways of type 'SECURE_WEB_GATEWAY'.`,
244+
},
245+
"scope": {
246+
Type: schema.TypeString,
247+
Optional: true,
248+
ForceNew: true,
249+
Description: `Immutable. Scope determines how configuration across multiple Gateway instances are merged.
250+
The configuration for multiple Gateway instances with the same scope will be merged as presented as
251+
a single coniguration to the proxy/load balancer.
252+
Max length 64 characters. Scope should start with a letter and can only have letters, numbers, hyphens.`,
253253
},
254254
"server_tls_policy": {
255255
Type: schema.TypeString,

website/docs/r/network_services_gateway.html.markdown

+7-7
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,6 @@ The following arguments are supported:
241241
The proxy binds to the specified ports. Gateways of type 'SECURE_WEB_GATEWAY' are
242242
limited to 1 port. Gateways of type 'OPEN_MESH' listen on 0.0.0.0 and support multiple ports.
243243

244-
* `scope` -
245-
(Required)
246-
Immutable. Scope determines how configuration across multiple Gateway instances are merged.
247-
The configuration for multiple Gateway instances with the same scope will be merged as presented as
248-
a single coniguration to the proxy/load balancer.
249-
Max length 64 characters. Scope should start with a letter and can only have letters, numbers, hyphens.
250-
251244
* `name` -
252245
(Required)
253246
Short name of the Gateway resource to be created.
@@ -264,6 +257,13 @@ The following arguments are supported:
264257
(Optional)
265258
A free-text description of the resource. Max length 1024 characters.
266259

260+
* `scope` -
261+
(Optional)
262+
Immutable. Scope determines how configuration across multiple Gateway instances are merged.
263+
The configuration for multiple Gateway instances with the same scope will be merged as presented as
264+
a single coniguration to the proxy/load balancer.
265+
Max length 64 characters. Scope should start with a letter and can only have letters, numbers, hyphens.
266+
267267
* `server_tls_policy` -
268268
(Optional)
269269
A fully-qualified ServerTLSPolicy URL reference. Specifies how TLS traffic is terminated.

0 commit comments

Comments
 (0)