From 4dc9007e8e80740465525c6564c3a99bc4f3025e Mon Sep 17 00:00:00 2001 From: Roberto Jung Drebes Date: Sat, 28 Jan 2017 00:43:45 +0100 Subject: [PATCH] provider/google: acceptance tests for traffic selectors --- .../google/resource_compute_vpn_tunnel.go | 12 ++++++++++++ .../resource_compute_vpn_tunnel_test.go | 19 +++++++++++++++---- .../google/r/compute_vpn_tunnel.html.markdown | 15 +++++++++++++-- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/builtin/providers/google/resource_compute_vpn_tunnel.go b/builtin/providers/google/resource_compute_vpn_tunnel.go index 7f78688c5..7989035d4 100644 --- a/builtin/providers/google/resource_compute_vpn_tunnel.go +++ b/builtin/providers/google/resource_compute_vpn_tunnel.go @@ -199,6 +199,18 @@ func resourceComputeVpnTunnelRead(d *schema.ResourceData, meta interface{}) erro return fmt.Errorf("Error Reading VPN Tunnel %s: %s", name, err) } + localTrafficSelectors := []string{} + for _, lts := range vpnTunnel.LocalTrafficSelector { + localTrafficSelectors = append(localTrafficSelectors, lts) + } + d.Set("local_traffic_selector", localTrafficSelectors) + + remoteTrafficSelectors := []string{} + for _, rts := range vpnTunnel.RemoteTrafficSelector { + remoteTrafficSelectors = append(remoteTrafficSelectors, rts) + } + d.Set("remote_traffic_selector", remoteTrafficSelectors) + d.Set("detailed_status", vpnTunnel.DetailedStatus) d.Set("self_link", vpnTunnel.SelfLink) diff --git a/builtin/providers/google/resource_compute_vpn_tunnel_test.go b/builtin/providers/google/resource_compute_vpn_tunnel_test.go index 896c94c41..c863fce68 100644 --- a/builtin/providers/google/resource_compute_vpn_tunnel_test.go +++ b/builtin/providers/google/resource_compute_vpn_tunnel_test.go @@ -22,6 +22,10 @@ func TestAccComputeVpnTunnel_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckComputeVpnTunnelExists( "google_compute_vpn_tunnel.foobar"), + resource.TestCheckResourceAttr( + "google_compute_vpn_tunnel.foobar", "local_traffic_selector.#", "1"), + resource.TestCheckResourceAttr( + "google_compute_vpn_tunnel.foobar", "remote_traffic_selector.#", "2"), ), }, }, @@ -83,16 +87,21 @@ func testAccCheckComputeVpnTunnelExists(n string) resource.TestCheckFunc { var testAccComputeVpnTunnel_basic = fmt.Sprintf(` resource "google_compute_network" "foobar" { name = "tunnel-test-%s" - ipv4_range = "10.0.0.0/16" +} +resource "google_compute_subnetwork" "foobar" { + name = "tunnel-test-%s" + network = "${google_compute_network.foobar.self_link}" + ip_cidr_range = "10.0.0.0/16" + region = "us-central1" } resource "google_compute_address" "foobar" { name = "tunnel-test-%s" - region = "us-central1" + region = "${google_compute_subnetwork.foobar.region}" } resource "google_compute_vpn_gateway" "foobar" { name = "tunnel-test-%s" network = "${google_compute_network.foobar.self_link}" - region = "${google_compute_address.foobar.region}" + region = "${google_compute_subnetwork.foobar.region}" } resource "google_compute_forwarding_rule" "foobar_esp" { name = "tunnel-test-%s" @@ -123,6 +132,8 @@ resource "google_compute_vpn_tunnel" "foobar" { target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}" shared_secret = "unguessable" peer_ip = "8.8.8.8" + local_traffic_selector = ["${google_compute_subnetwork.foobar.ip_cidr_range}"] + remote_traffic_selector = ["192.168.0.0/24", "192.168.1.0/24"] }`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), - acctest.RandString(10)) + acctest.RandString(10), acctest.RandString(10)) diff --git a/website/source/docs/providers/google/r/compute_vpn_tunnel.html.markdown b/website/source/docs/providers/google/r/compute_vpn_tunnel.html.markdown index b4e84094d..142d6c5a3 100644 --- a/website/source/docs/providers/google/r/compute_vpn_tunnel.html.markdown +++ b/website/source/docs/providers/google/r/compute_vpn_tunnel.html.markdown @@ -15,17 +15,25 @@ Manages a VPN Tunnel to the GCE network. For more info, read the ```js resource "google_compute_network" "network1" { - name = "network1" - ipv4_range = "10.120.0.0/16" + name = "network1" +} + +resource "google_compute_subnetwork" "subnet1" { + name = "subnet1" + network = "${google_compute_network.network1.self_link}" + ip_cidr_range = "10.120.0.0/16" + region = "us-central1" } resource "google_compute_vpn_gateway" "target_gateway" { name = "vpn1" network = "${google_compute_network.network1.self_link}" + region = "${google_compute_subnetwork.subnet1.region}" } resource "google_compute_address" "vpn_static_ip" { name = "vpn-static-ip" + region = "${google_compute_subnetwork.subnet1.region}" } resource "google_compute_forwarding_rule" "fr_esp" { @@ -58,6 +66,9 @@ resource "google_compute_vpn_tunnel" "tunnel1" { target_vpn_gateway = "${google_compute_vpn_gateway.target_gateway.self_link}" + local_traffic_selector = ["${google_compute_subnetwork.subnet1.ip_cidr_range}"] + remote_traffic_selector = ["172.16.0.0/12"] + depends_on = [ "google_compute_forwarding_rule.fr_esp", "google_compute_forwarding_rule.fr_udp500",