@@ -21,13 +21,15 @@ import (
2121 "testing"
2222
2323 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
24+ "github.com/hashicorp/terraform-plugin-testing/plancheck"
2425 "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
2526 "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
2627)
2728
2829func TestAccComputeVpnTunnel_regionFromGateway (t * testing.T ) {
2930 t .Parallel ()
3031 region := "us-central1"
32+ suffix := acctest .RandString (t , 10 )
3133 if envvar .GetTestRegionFromEnv () == region {
3234 // Make sure we choose a region that isn't the provider default
3335 // in order to test getting the region from the gateway and not the
@@ -41,7 +43,7 @@ func TestAccComputeVpnTunnel_regionFromGateway(t *testing.T) {
4143 CheckDestroy : testAccCheckComputeVpnTunnelDestroyProducer (t ),
4244 Steps : []resource.TestStep {
4345 {
44- Config : testAccComputeVpnTunnel_regionFromGateway (acctest . RandString ( t , 10 ) , region ),
46+ Config : testAccComputeVpnTunnel_regionFromGateway (suffix , region ),
4547 },
4648 {
4749 ResourceName : "google_compute_vpn_tunnel.foobar" ,
@@ -56,14 +58,60 @@ func TestAccComputeVpnTunnel_regionFromGateway(t *testing.T) {
5658func TestAccComputeVpnTunnel_router (t * testing.T ) {
5759 t .Parallel ()
5860
61+ suffix := acctest .RandString (t , 10 )
5962 router := fmt .Sprintf ("tf-test-tunnel-%s" , acctest .RandString (t , 10 ))
6063 acctest .VcrTest (t , resource.TestCase {
6164 PreCheck : func () { acctest .AccTestPreCheck (t ) },
6265 ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
6366 CheckDestroy : testAccCheckComputeVpnTunnelDestroyProducer (t ),
6467 Steps : []resource.TestStep {
6568 {
66- Config : testAccComputeVpnTunnelRouter (acctest .RandString (t , 10 ), router ),
69+ Config : testAccComputeVpnTunnelRouter (suffix , router ),
70+ },
71+ {
72+ ResourceName : "google_compute_vpn_tunnel.foobar" ,
73+ ImportState : true ,
74+ ImportStateVerify : true ,
75+ ImportStateVerifyIgnore : []string {"shared_secret" , "detailed_status" },
76+ },
77+ },
78+ })
79+ }
80+
81+ func TestAccComputeVpnTunnel_routerWithSharedSecretWo_update (t * testing.T ) {
82+ t .Parallel ()
83+
84+ router := fmt .Sprintf ("tf-test-tunnel-%s" , acctest .RandString (t , 10 ))
85+ suffix := acctest .RandString (t , 10 )
86+ acctest .VcrTest (t , resource.TestCase {
87+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
88+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
89+ CheckDestroy : testAccCheckComputeVpnTunnelDestroyProducer (t ),
90+ Steps : []resource.TestStep {
91+ {
92+ Config : testAccComputeVpnTunnelRouterWithSharedSecretWo (suffix , router ),
93+ Check : resource .ComposeTestCheckFunc (
94+ resource .TestCheckNoResourceAttr ("google_compute_vpn_tunnel.foobar" , "shared_secret_wo" ),
95+ resource .TestCheckResourceAttr ("google_compute_vpn_tunnel.foobar" , "shared_secret_wo_version" , "1" ),
96+ ),
97+ },
98+ {
99+ ResourceName : "google_compute_vpn_tunnel.foobar" ,
100+ ImportState : true ,
101+ ImportStateVerify : true ,
102+ ImportStateVerifyIgnore : []string {"shared_secret" , "detailed_status" },
103+ },
104+ {
105+ Config : testAccComputeVpnTunnelRouterWithSharedSecretWo_update (suffix , router ),
106+ ConfigPlanChecks : resource.ConfigPlanChecks {
107+ PreApply : []plancheck.PlanCheck {
108+ plancheck .ExpectResourceAction ("google_compute_vpn_tunnel.foobar" , plancheck .ResourceActionDestroyBeforeCreate ),
109+ },
110+ },
111+ Check : resource .ComposeTestCheckFunc (
112+ resource .TestCheckNoResourceAttr ("google_compute_vpn_tunnel.foobar" , "shared_secret_wo" ),
113+ resource .TestCheckResourceAttr ("google_compute_vpn_tunnel.foobar" , "shared_secret_wo_version" , "2" ),
114+ ),
67115 },
68116 {
69117 ResourceName : "google_compute_vpn_tunnel.foobar" ,
@@ -78,13 +126,14 @@ func TestAccComputeVpnTunnel_router(t *testing.T) {
78126func TestAccComputeVpnTunnel_defaultTrafficSelectors (t * testing.T ) {
79127 t .Parallel ()
80128
129+ suffix := acctest .RandString (t , 10 )
81130 acctest .VcrTest (t , resource.TestCase {
82131 PreCheck : func () { acctest .AccTestPreCheck (t ) },
83132 ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
84133 CheckDestroy : testAccCheckComputeVpnTunnelDestroyProducer (t ),
85134 Steps : []resource.TestStep {
86135 {
87- Config : testAccComputeVpnTunnelDefaultTrafficSelectors (acctest . RandString ( t , 10 ) ),
136+ Config : testAccComputeVpnTunnelDefaultTrafficSelectors (suffix ),
88137 },
89138 {
90139 ResourceName : "google_compute_vpn_tunnel.foobar" ,
@@ -217,6 +266,122 @@ resource "google_compute_vpn_tunnel" "foobar" {
217266` , suffix , router )
218267}
219268
269+ func testAccComputeVpnTunnelRouterWithSharedSecretWo (suffix , router string ) string {
270+ return fmt .Sprintf (`
271+ resource "google_compute_network" "foobar" {
272+ name = "tf-test-%[1]s"
273+ auto_create_subnetworks = false
274+ }
275+
276+ resource "google_compute_subnetwork" "foobar" {
277+ name = "tf-test-subnetwork-%[1]s"
278+ network = google_compute_network.foobar.self_link
279+ ip_cidr_range = "10.0.0.0/16"
280+ region = "us-central1"
281+ }
282+
283+ resource "google_compute_address" "foobar" {
284+ name = "tf-test-%[1]s"
285+ region = google_compute_subnetwork.foobar.region
286+ }
287+
288+ resource "google_compute_ha_vpn_gateway" "foobar" {
289+ name = "tf-test-%[1]s"
290+ network = google_compute_network.foobar.self_link
291+ region = google_compute_subnetwork.foobar.region
292+ }
293+
294+ resource "google_compute_external_vpn_gateway" "external_gateway" {
295+ name = "external-gateway-%[1]s"
296+ redundancy_type = "SINGLE_IP_INTERNALLY_REDUNDANT"
297+ description = "An externally managed VPN gateway"
298+ interface {
299+ id = 0
300+ ip_address = "8.8.8.8"
301+ }
302+ }
303+
304+ resource "google_compute_router" "foobar" {
305+ name = "%[2]s"
306+ region = google_compute_subnetwork.foobar.region
307+ network = google_compute_network.foobar.self_link
308+ bgp {
309+ asn = 64514
310+ }
311+ }
312+
313+ resource "google_compute_vpn_tunnel" "foobar" {
314+ name = "tf-test-%[1]s"
315+ region = google_compute_subnetwork.foobar.region
316+ vpn_gateway = google_compute_ha_vpn_gateway.foobar.id
317+ peer_external_gateway = google_compute_external_vpn_gateway.external_gateway.id
318+ peer_external_gateway_interface = 0
319+ shared_secret_wo = "I am write only, and should not be written to state"
320+ shared_secret_wo_version = 1
321+ router = google_compute_router.foobar.self_link
322+ vpn_gateway_interface = 0
323+ }
324+ ` , suffix , router )
325+ }
326+
327+ func testAccComputeVpnTunnelRouterWithSharedSecretWo_update (suffix , router string ) string {
328+ return fmt .Sprintf (`
329+ resource "google_compute_network" "foobar" {
330+ name = "tf-test-%[1]s"
331+ auto_create_subnetworks = false
332+ }
333+
334+ resource "google_compute_subnetwork" "foobar" {
335+ name = "tf-test-subnetwork-%[1]s"
336+ network = google_compute_network.foobar.self_link
337+ ip_cidr_range = "10.0.0.0/16"
338+ region = "us-central1"
339+ }
340+
341+ resource "google_compute_address" "foobar" {
342+ name = "tf-test-%[1]s"
343+ region = google_compute_subnetwork.foobar.region
344+ }
345+
346+ resource "google_compute_ha_vpn_gateway" "foobar" {
347+ name = "tf-test-%[1]s"
348+ network = google_compute_network.foobar.self_link
349+ region = google_compute_subnetwork.foobar.region
350+ }
351+
352+ resource "google_compute_external_vpn_gateway" "external_gateway" {
353+ name = "external-gateway-%[1]s"
354+ redundancy_type = "SINGLE_IP_INTERNALLY_REDUNDANT"
355+ description = "An externally managed VPN gateway"
356+ interface {
357+ id = 0
358+ ip_address = "8.8.8.8"
359+ }
360+ }
361+
362+ resource "google_compute_router" "foobar" {
363+ name = "%[2]s"
364+ region = google_compute_subnetwork.foobar.region
365+ network = google_compute_network.foobar.self_link
366+ bgp {
367+ asn = 64514
368+ }
369+ }
370+
371+ resource "google_compute_vpn_tunnel" "foobar" {
372+ name = "tf-test-%[1]s"
373+ region = google_compute_subnetwork.foobar.region
374+ vpn_gateway = google_compute_ha_vpn_gateway.foobar.id
375+ peer_external_gateway = google_compute_external_vpn_gateway.external_gateway.id
376+ peer_external_gateway_interface = 0
377+ shared_secret_wo = "This is another secret, but still write only"
378+ shared_secret_wo_version = 2
379+ router = google_compute_router.foobar.self_link
380+ vpn_gateway_interface = 0
381+ }
382+ ` , suffix , router )
383+ }
384+
220385func testAccComputeVpnTunnelDefaultTrafficSelectors (suffix string ) string {
221386 return fmt .Sprintf (`
222387resource "google_compute_network" "foobar" {
0 commit comments