2018-10-05 19:32:57 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This file is automatically generated by Magic Modules and manual
|
|
|
|
// changes will be clobbered when the file is regenerated.
|
|
|
|
//
|
|
|
|
// Please read more about how to change this file in
|
|
|
|
// .github/CONTRIBUTING.md.
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
2018-10-26 18:03:43 +00:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2018-10-05 19:32:57 +00:00
|
|
|
)
|
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func TestAccComputeVpnTunnel_vpnTunnelBasicExample(t *testing.T) {
|
2018-10-05 19:32:57 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeVpnTunnelDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2018-11-09 21:02:03 +00:00
|
|
|
Config: testAccComputeVpnTunnel_vpnTunnelBasicExample(acctest.RandString(10)),
|
2018-10-05 19:32:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_compute_vpn_tunnel.tunnel1",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"shared_secret"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func testAccComputeVpnTunnel_vpnTunnelBasicExample(val string) string {
|
2018-10-05 19:32:57 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_vpn_tunnel" "tunnel1" {
|
|
|
|
name = "tunnel1-%s"
|
|
|
|
peer_ip = "15.0.0.120"
|
|
|
|
shared_secret = "a secret message"
|
|
|
|
|
|
|
|
target_vpn_gateway = "${google_compute_vpn_gateway.target_gateway.self_link}"
|
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
"google_compute_forwarding_rule.fr_esp",
|
|
|
|
"google_compute_forwarding_rule.fr_udp500",
|
|
|
|
"google_compute_forwarding_rule.fr_udp4500",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_vpn_gateway" "target_gateway" {
|
|
|
|
name = "vpn1-%s"
|
|
|
|
network = "${google_compute_network.network1.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_network" "network1" {
|
|
|
|
name = "network1-%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_address" "vpn_static_ip" {
|
|
|
|
name = "vpn-static-ip-%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_forwarding_rule" "fr_esp" {
|
|
|
|
name = "fr-esp-%s"
|
|
|
|
ip_protocol = "ESP"
|
|
|
|
ip_address = "${google_compute_address.vpn_static_ip.address}"
|
|
|
|
target = "${google_compute_vpn_gateway.target_gateway.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_forwarding_rule" "fr_udp500" {
|
|
|
|
name = "fr-udp500-%s"
|
|
|
|
ip_protocol = "UDP"
|
|
|
|
port_range = "500"
|
|
|
|
ip_address = "${google_compute_address.vpn_static_ip.address}"
|
|
|
|
target = "${google_compute_vpn_gateway.target_gateway.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_forwarding_rule" "fr_udp4500" {
|
|
|
|
name = "fr-udp4500-%s"
|
|
|
|
ip_protocol = "UDP"
|
|
|
|
port_range = "4500"
|
|
|
|
ip_address = "${google_compute_address.vpn_static_ip.address}"
|
|
|
|
target = "${google_compute_vpn_gateway.target_gateway.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_route" "route1" {
|
|
|
|
name = "route1-%s"
|
|
|
|
network = "${google_compute_network.network1.name}"
|
|
|
|
dest_range = "15.0.0.0/24"
|
|
|
|
priority = 1000
|
|
|
|
|
|
|
|
next_hop_vpn_tunnel = "${google_compute_vpn_tunnel.tunnel1.self_link}"
|
|
|
|
}
|
|
|
|
`, val, val, val, val, val, val, val, val,
|
|
|
|
)
|
|
|
|
}
|
2018-10-26 18:03:43 +00:00
|
|
|
|
|
|
|
func testAccCheckComputeVpnTunnelDestroy(s *terraform.State) error {
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "google_compute_vpn_tunnel" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/vpnTunnels/{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = sendRequest(config, "GET", url, nil)
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("ComputeVpnTunnel still exists at %s", url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|