Skip to content

Commit dc0ad55

Browse files
Fix issue due to Secure Web Proxy recreation due to not setting addresses field (#9771) (#6871)
* added default_from_api to addresses field * added bug integration test * fixed test name [upstream:cb9e3ed179edc64b4b0021e4966680259914a29e] Signed-off-by: Modular Magician <[email protected]>
1 parent 9deadb0 commit dc0ad55

File tree

3 files changed

+114
-9
lines changed

3 files changed

+114
-9
lines changed

.changelog/9771.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
networkservices: fixed a perma-diff on `addresses` in `google_network_services_gateway`
3+
```

google-beta/services/networkservices/resource_network_services_gateway.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ limited to 1 port. Gateways of type 'OPEN_MESH' listen on 0.0.0.0 and support mu
195195
},
196196
"addresses": {
197197
Type: schema.TypeList,
198+
Computed: true,
198199
Optional: true,
199200
ForceNew: true,
200201
Description: `Zero or one IPv4-address on which the Gateway will receive the traffic. When no address is provided,

google-beta/services/networkservices/resource_network_services_gateway_test.go

Lines changed: 110 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
370471
resource "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+
464565
resource "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+
586687
resource "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+
695796
resource "google_network_services_gateway" "gateway1" {
696797
name = "%s"
697798
location = "us-west2"

0 commit comments

Comments
 (0)