provider/google: acceptance tests for traffic selectors

This commit is contained in:
Roberto Jung Drebes 2017-01-28 00:43:45 +01:00
parent b41efe7dc7
commit 4dc9007e8e
3 changed files with 40 additions and 6 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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",