wip: review changes:
- test arguments - set region, project in state - fix import error messages - get rid of peerFound - linkDiffSuppress
This commit is contained in:
parent
50f8b9407e
commit
6ab9d82cc5
|
@ -1,7 +1,6 @@
|
||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
|
@ -10,23 +9,13 @@ import (
|
||||||
|
|
||||||
func TestAccComputeRouterInterface_import(t *testing.T) {
|
func TestAccComputeRouterInterface_import(t *testing.T) {
|
||||||
resourceName := "google_compute_router_interface.foobar"
|
resourceName := "google_compute_router_interface.foobar"
|
||||||
network := fmt.Sprintf("router-interface-import-test-%s", acctest.RandString(10))
|
testId := acctest.RandString(10)
|
||||||
subnet := fmt.Sprintf("router-interface-import-test-%s", acctest.RandString(10))
|
|
||||||
address := fmt.Sprintf("router-interface-import-test-%s", acctest.RandString(10))
|
|
||||||
gateway := fmt.Sprintf("router-interface-import-test-%s", acctest.RandString(10))
|
|
||||||
espRule := fmt.Sprintf("router-interface-import-test-%s", acctest.RandString(10))
|
|
||||||
udp500Rule := fmt.Sprintf("router-interface-import-test-%s", acctest.RandString(10))
|
|
||||||
udp4500Rule := fmt.Sprintf("router-interface-import-test-%s", acctest.RandString(10))
|
|
||||||
router := fmt.Sprintf("router-interface-import-test-%s", acctest.RandString(10))
|
|
||||||
tunnel := fmt.Sprintf("router-interface-import-test-%s", acctest.RandString(10))
|
|
||||||
iface := fmt.Sprintf("router-interface-import-test-%s", acctest.RandString(10))
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeRouterInterfaceBasic(network, subnet, address, gateway, espRule, udp500Rule,
|
Config: testAccComputeRouterInterfaceBasic(testId),
|
||||||
udp4500Rule, router, tunnel, iface),
|
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
|
@ -10,24 +9,13 @@ import (
|
||||||
|
|
||||||
func TestAccComputeRouterPeer_import(t *testing.T) {
|
func TestAccComputeRouterPeer_import(t *testing.T) {
|
||||||
resourceName := "google_compute_router_peer.foobar"
|
resourceName := "google_compute_router_peer.foobar"
|
||||||
network := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
testId := acctest.RandString(10)
|
||||||
subnet := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
|
||||||
address := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
|
||||||
gateway := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
|
||||||
espRule := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
|
||||||
udp500Rule := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
|
||||||
udp4500Rule := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
|
||||||
router := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
|
||||||
tunnel := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
|
||||||
iface := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
|
||||||
peer := fmt.Sprintf("router-peer-import-test-%s", acctest.RandString(10))
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeRouterPeerBasic(network, subnet, address, gateway, espRule, udp500Rule,
|
Config: testAccComputeRouterPeerBasic(testId),
|
||||||
udp4500Rule, router, tunnel, iface, peer),
|
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
|
|
@ -1,25 +1,21 @@
|
||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeRouter_import(t *testing.T) {
|
func TestAccComputeRouter_import(t *testing.T) {
|
||||||
resourceName := "google_compute_router.foobar"
|
resourceName := "google_compute_router.foobar"
|
||||||
network := fmt.Sprintf("router-import-test-%s", acctest.RandString(10))
|
resourceRegion := "europe-west1"
|
||||||
subnet := fmt.Sprintf("router-import-test-%s", acctest.RandString(10))
|
|
||||||
router := fmt.Sprintf("router-import-test-%s", acctest.RandString(10))
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckComputeRouterDestroy,
|
CheckDestroy: testAccCheckComputeRouterDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeRouterNetworkLink(network, subnet, router),
|
Config: testAccComputeRouterBasic(resourceRegion),
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
|
|
@ -275,3 +275,11 @@ func handleNotFoundError(err error, d *schema.ResourceData, resource string) err
|
||||||
|
|
||||||
return fmt.Errorf("Error reading %s: %s", resource, err)
|
return fmt.Errorf("Error reading %s: %s", resource, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func linkDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
|
||||||
|
parts := strings.Split(old, "/")
|
||||||
|
if parts[len(parts)-1] == new {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -28,9 +28,10 @@ func resourceComputeRouter() *schema.Resource {
|
||||||
},
|
},
|
||||||
|
|
||||||
"network": &schema.Schema{
|
"network": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
|
DiffSuppressFunc: linkDiffSuppress,
|
||||||
},
|
},
|
||||||
|
|
||||||
"description": &schema.Schema{
|
"description": &schema.Schema{
|
||||||
|
@ -42,6 +43,7 @@ func resourceComputeRouter() *schema.Resource {
|
||||||
"project": &schema.Schema{
|
"project": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -167,15 +169,12 @@ func resourceComputeRouterRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("self_link", router.SelfLink)
|
d.Set("self_link", router.SelfLink)
|
||||||
|
d.Set("network", router.Network)
|
||||||
// if we don't have a network (when importing), set it to the URI returned from the server
|
|
||||||
if _, ok := d.GetOk("network"); !ok {
|
|
||||||
d.Set("network", router.Network)
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("name", router.Name)
|
d.Set("name", router.Name)
|
||||||
d.Set("description", router.Description)
|
d.Set("description", router.Description)
|
||||||
d.Set("region", region)
|
d.Set("region", region)
|
||||||
|
d.Set("project", project)
|
||||||
d.Set("bgp", flattenAsn(router.Bgp.Asn))
|
d.Set("bgp", flattenAsn(router.Bgp.Asn))
|
||||||
d.SetId(fmt.Sprintf("%s/%s", region, name))
|
d.SetId(fmt.Sprintf("%s/%s", region, name))
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,10 @@ func resourceComputeRouterInterface() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
"vpn_tunnel": &schema.Schema{
|
"vpn_tunnel": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
|
DiffSuppressFunc: linkDiffSuppress,
|
||||||
},
|
},
|
||||||
|
|
||||||
"ip_range": &schema.Schema{
|
"ip_range": &schema.Schema{
|
||||||
|
@ -45,6 +46,7 @@ func resourceComputeRouterInterface() *schema.Resource {
|
||||||
"project": &schema.Schema{
|
"project": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -167,15 +169,10 @@ func resourceComputeRouterInterfaceRead(d *schema.ResourceData, meta interface{}
|
||||||
|
|
||||||
if iface.Name == ifaceName {
|
if iface.Name == ifaceName {
|
||||||
d.SetId(fmt.Sprintf("%s/%s/%s", region, routerName, ifaceName))
|
d.SetId(fmt.Sprintf("%s/%s/%s", region, routerName, ifaceName))
|
||||||
// if we don't have a tunnel (when importing), set it to the URI returned from the server
|
d.Set("vpn_tunnel", iface.LinkedVpnTunnel)
|
||||||
if _, ok := d.GetOk("vpn_tunnel"); !ok {
|
|
||||||
vpnTunnelName, err := getVpnTunnelName(iface.LinkedVpnTunnel)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
d.Set("vpn_tunnel", vpnTunnelName)
|
|
||||||
}
|
|
||||||
d.Set("ip_range", iface.IpRange)
|
d.Set("ip_range", iface.IpRange)
|
||||||
|
d.Set("region", region)
|
||||||
|
d.Set("project", project)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +258,7 @@ func resourceComputeRouterInterfaceDelete(d *schema.ResourceData, meta interface
|
||||||
func resourceComputeRouterInterfaceImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
func resourceComputeRouterInterfaceImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
||||||
parts := strings.Split(d.Id(), "/")
|
parts := strings.Split(d.Id(), "/")
|
||||||
if len(parts) != 3 {
|
if len(parts) != 3 {
|
||||||
return nil, fmt.Errorf("Invalid router specifier. Expecting {region}/{router}")
|
return nil, fmt.Errorf("Invalid router interface specifier. Expecting {region}/{router}/{interface}")
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("region", parts[0])
|
d.Set("region", parts[0])
|
||||||
|
|
|
@ -10,30 +10,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeRouterInterface_basic(t *testing.T) {
|
func TestAccComputeRouterInterface_basic(t *testing.T) {
|
||||||
network := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
testId := acctest.RandString(10)
|
||||||
subnet := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
address := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
gateway := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
espRule := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
udp500Rule := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
udp4500Rule := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
router := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
tunnel := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
iface := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckComputeRouterInterfaceDestroy,
|
CheckDestroy: testAccCheckComputeRouterInterfaceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeRouterInterfaceBasic(network, subnet, address, gateway, espRule, udp500Rule,
|
Config: testAccComputeRouterInterfaceBasic(testId),
|
||||||
udp4500Rule, router, tunnel, iface),
|
|
||||||
Check: testAccCheckComputeRouterInterfaceExists(
|
Check: testAccCheckComputeRouterInterfaceExists(
|
||||||
"google_compute_router_interface.foobar"),
|
"google_compute_router_interface.foobar"),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeRouterInterfaceKeepRouter(network, subnet, address, gateway, espRule, udp500Rule,
|
Config: testAccComputeRouterInterfaceKeepRouter(testId),
|
||||||
udp4500Rule, router, tunnel),
|
|
||||||
Check: testAccCheckComputeRouterInterfaceDelete(
|
Check: testAccCheckComputeRouterInterfaceDelete(
|
||||||
"google_compute_router_interface.foobar"),
|
"google_compute_router_interface.foobar"),
|
||||||
},
|
},
|
||||||
|
@ -161,35 +150,35 @@ func testAccCheckComputeRouterInterfaceExists(n string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccComputeRouterInterfaceBasic(network, subnet, address, gateway, espFwRule, udp500FwRule, udp4500FwRule, router, tunnel, iface string) string {
|
func testAccComputeRouterInterfaceBasic(testId string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_network" "foobar" {
|
resource "google_compute_network" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
}
|
}
|
||||||
resource "google_compute_subnetwork" "foobar" {
|
resource "google_compute_subnetwork" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
ip_cidr_range = "10.0.0.0/16"
|
ip_cidr_range = "10.0.0.0/16"
|
||||||
region = "us-central1"
|
region = "us-central1"
|
||||||
}
|
}
|
||||||
resource "google_compute_address" "foobar" {
|
resource "google_compute_address" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
}
|
}
|
||||||
resource "google_compute_vpn_gateway" "foobar" {
|
resource "google_compute_vpn_gateway" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_esp" {
|
resource "google_compute_forwarding_rule" "foobar_esp" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s-1"
|
||||||
region = "${google_compute_vpn_gateway.foobar.region}"
|
region = "${google_compute_vpn_gateway.foobar.region}"
|
||||||
ip_protocol = "ESP"
|
ip_protocol = "ESP"
|
||||||
ip_address = "${google_compute_address.foobar.address}"
|
ip_address = "${google_compute_address.foobar.address}"
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_udp500" {
|
resource "google_compute_forwarding_rule" "foobar_udp500" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s-2"
|
||||||
region = "${google_compute_forwarding_rule.foobar_esp.region}"
|
region = "${google_compute_forwarding_rule.foobar_esp.region}"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
port_range = "500-500"
|
port_range = "500-500"
|
||||||
|
@ -197,7 +186,7 @@ func testAccComputeRouterInterfaceBasic(network, subnet, address, gateway, espFw
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_udp4500" {
|
resource "google_compute_forwarding_rule" "foobar_udp4500" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s-3"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
port_range = "4500-4500"
|
port_range = "4500-4500"
|
||||||
|
@ -205,7 +194,7 @@ func testAccComputeRouterInterfaceBasic(network, subnet, address, gateway, espFw
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_router" "foobar"{
|
resource "google_compute_router" "foobar"{
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
bgp {
|
bgp {
|
||||||
|
@ -213,7 +202,7 @@ func testAccComputeRouterInterfaceBasic(network, subnet, address, gateway, espFw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resource "google_compute_vpn_tunnel" "foobar" {
|
resource "google_compute_vpn_tunnel" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp4500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp4500.region}"
|
||||||
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
|
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
shared_secret = "unguessable"
|
shared_secret = "unguessable"
|
||||||
|
@ -221,44 +210,44 @@ func testAccComputeRouterInterfaceBasic(network, subnet, address, gateway, espFw
|
||||||
router = "${google_compute_router.foobar.name}"
|
router = "${google_compute_router.foobar.name}"
|
||||||
}
|
}
|
||||||
resource "google_compute_router_interface" "foobar" {
|
resource "google_compute_router_interface" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
router = "${google_compute_router.foobar.name}"
|
router = "${google_compute_router.foobar.name}"
|
||||||
region = "${google_compute_router.foobar.region}"
|
region = "${google_compute_router.foobar.region}"
|
||||||
ip_range = "169.254.3.1/30"
|
ip_range = "169.254.3.1/30"
|
||||||
vpn_tunnel = "${google_compute_vpn_tunnel.foobar.name}"
|
vpn_tunnel = "${google_compute_vpn_tunnel.foobar.name}"
|
||||||
}
|
}
|
||||||
`, network, subnet, address, gateway, espFwRule, udp500FwRule, udp4500FwRule, router, tunnel, iface)
|
`, testId, testId, testId, testId, testId, testId, testId, testId, testId, testId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccComputeRouterInterfaceKeepRouter(network, subnet, address, gateway, espFwRule, udp500FwRule, udp4500FwRule, router, tunnel string) string {
|
func testAccComputeRouterInterfaceKeepRouter(testId string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_network" "foobar" {
|
resource "google_compute_network" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
}
|
}
|
||||||
resource "google_compute_subnetwork" "foobar" {
|
resource "google_compute_subnetwork" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
ip_cidr_range = "10.0.0.0/16"
|
ip_cidr_range = "10.0.0.0/16"
|
||||||
region = "us-central1"
|
region = "us-central1"
|
||||||
}
|
}
|
||||||
resource "google_compute_address" "foobar" {
|
resource "google_compute_address" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
}
|
}
|
||||||
resource "google_compute_vpn_gateway" "foobar" {
|
resource "google_compute_vpn_gateway" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_esp" {
|
resource "google_compute_forwarding_rule" "foobar_esp" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s-1"
|
||||||
region = "${google_compute_vpn_gateway.foobar.region}"
|
region = "${google_compute_vpn_gateway.foobar.region}"
|
||||||
ip_protocol = "ESP"
|
ip_protocol = "ESP"
|
||||||
ip_address = "${google_compute_address.foobar.address}"
|
ip_address = "${google_compute_address.foobar.address}"
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_udp500" {
|
resource "google_compute_forwarding_rule" "foobar_udp500" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s-2"
|
||||||
region = "${google_compute_forwarding_rule.foobar_esp.region}"
|
region = "${google_compute_forwarding_rule.foobar_esp.region}"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
port_range = "500-500"
|
port_range = "500-500"
|
||||||
|
@ -266,7 +255,7 @@ func testAccComputeRouterInterfaceKeepRouter(network, subnet, address, gateway,
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_udp4500" {
|
resource "google_compute_forwarding_rule" "foobar_udp4500" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s-3"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
port_range = "4500-4500"
|
port_range = "4500-4500"
|
||||||
|
@ -274,7 +263,7 @@ func testAccComputeRouterInterfaceKeepRouter(network, subnet, address, gateway,
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_router" "foobar"{
|
resource "google_compute_router" "foobar"{
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
bgp {
|
bgp {
|
||||||
|
@ -282,12 +271,12 @@ func testAccComputeRouterInterfaceKeepRouter(network, subnet, address, gateway,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resource "google_compute_vpn_tunnel" "foobar" {
|
resource "google_compute_vpn_tunnel" "foobar" {
|
||||||
name = "%s"
|
name = "router-interface-test-%s"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp4500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp4500.region}"
|
||||||
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
|
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
shared_secret = "unguessable"
|
shared_secret = "unguessable"
|
||||||
peer_ip = "8.8.8.8"
|
peer_ip = "8.8.8.8"
|
||||||
router = "${google_compute_router.foobar.name}"
|
router = "${google_compute_router.foobar.name}"
|
||||||
}
|
}
|
||||||
`, network, subnet, address, gateway, espFwRule, udp500FwRule, udp4500FwRule, router, tunnel)
|
`, testId, testId, testId, testId, testId, testId, testId, testId, testId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ func resourceComputeRouterPeer() *schema.Resource {
|
||||||
"project": &schema.Schema{
|
"project": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -195,6 +196,8 @@ func resourceComputeRouterPeerRead(d *schema.ResourceData, meta interface{}) err
|
||||||
d.Set("peer_asn", peer.PeerAsn)
|
d.Set("peer_asn", peer.PeerAsn)
|
||||||
d.Set("advertised_route_priority", peer.AdvertisedRoutePriority)
|
d.Set("advertised_route_priority", peer.AdvertisedRoutePriority)
|
||||||
d.Set("ip_address", peer.IpAddress)
|
d.Set("ip_address", peer.IpAddress)
|
||||||
|
d.Set("region", region)
|
||||||
|
d.Set("project", project)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,20 +240,16 @@ func resourceComputeRouterPeerDelete(d *schema.ResourceData, meta interface{}) e
|
||||||
return fmt.Errorf("Error Reading Router %s: %s", routerName, err)
|
return fmt.Errorf("Error Reading Router %s: %s", routerName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var peerFound bool
|
|
||||||
|
|
||||||
var newPeers []*compute.RouterBgpPeer = make([]*compute.RouterBgpPeer, 0, len(router.BgpPeers))
|
var newPeers []*compute.RouterBgpPeer = make([]*compute.RouterBgpPeer, 0, len(router.BgpPeers))
|
||||||
for _, peer := range router.BgpPeers {
|
for _, peer := range router.BgpPeers {
|
||||||
|
|
||||||
if peer.Name == peerName {
|
if peer.Name == peerName {
|
||||||
peerFound = true
|
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
newPeers = append(newPeers, peer)
|
newPeers = append(newPeers, peer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !peerFound {
|
if len(newPeers) == len(router.BgpPeers) {
|
||||||
log.Printf("[DEBUG] Router %s/%s had no peer %s already", region, routerName, peerName)
|
log.Printf("[DEBUG] Router %s/%s had no peer %s already", region, routerName, peerName)
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return nil
|
return nil
|
||||||
|
@ -280,7 +279,7 @@ func resourceComputeRouterPeerDelete(d *schema.ResourceData, meta interface{}) e
|
||||||
func resourceComputeRouterPeerImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
func resourceComputeRouterPeerImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
||||||
parts := strings.Split(d.Id(), "/")
|
parts := strings.Split(d.Id(), "/")
|
||||||
if len(parts) != 3 {
|
if len(parts) != 3 {
|
||||||
return nil, fmt.Errorf("Invalid router specifier. Expecting {region}/{router}")
|
return nil, fmt.Errorf("Invalid router peer specifier. Expecting {region}/{router}/{peer}")
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("region", parts[0])
|
d.Set("region", parts[0])
|
||||||
|
|
|
@ -10,31 +10,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeRouterPeer_basic(t *testing.T) {
|
func TestAccComputeRouterPeer_basic(t *testing.T) {
|
||||||
network := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
testId := acctest.RandString(10)
|
||||||
subnet := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
|
||||||
address := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
|
||||||
gateway := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
|
||||||
espRule := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
|
||||||
udp500Rule := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
|
||||||
udp4500Rule := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
|
||||||
router := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
|
||||||
tunnel := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
|
||||||
iface := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
|
||||||
peer := fmt.Sprintf("router-peer-test-%s", acctest.RandString(10))
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckComputeRouterPeerDestroy,
|
CheckDestroy: testAccCheckComputeRouterPeerDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeRouterPeerBasic(network, subnet, address, gateway, espRule, udp500Rule,
|
Config: testAccComputeRouterPeerBasic(testId),
|
||||||
udp4500Rule, router, tunnel, iface, peer),
|
|
||||||
Check: testAccCheckComputeRouterPeerExists(
|
Check: testAccCheckComputeRouterPeerExists(
|
||||||
"google_compute_router_peer.foobar"),
|
"google_compute_router_peer.foobar"),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeRouterPeerKeepRouter(network, subnet, address, gateway, espRule, udp500Rule,
|
Config: testAccComputeRouterPeerKeepRouter(testId),
|
||||||
udp4500Rule, router, tunnel, iface),
|
|
||||||
Check: testAccCheckComputeRouterPeerDelete(
|
Check: testAccCheckComputeRouterPeerDelete(
|
||||||
"google_compute_router_peer.foobar"),
|
"google_compute_router_peer.foobar"),
|
||||||
},
|
},
|
||||||
|
@ -162,35 +150,35 @@ func testAccCheckComputeRouterPeerExists(n string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccComputeRouterPeerBasic(network, subnet, address, gateway, espFwRule, udp500FwRule, udp4500FwRule, router, tunnel, iface, peer string) string {
|
func testAccComputeRouterPeerBasic(testId string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_network" "foobar" {
|
resource "google_compute_network" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
}
|
}
|
||||||
resource "google_compute_subnetwork" "foobar" {
|
resource "google_compute_subnetwork" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
ip_cidr_range = "10.0.0.0/16"
|
ip_cidr_range = "10.0.0.0/16"
|
||||||
region = "us-central1"
|
region = "us-central1"
|
||||||
}
|
}
|
||||||
resource "google_compute_address" "foobar" {
|
resource "google_compute_address" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
}
|
}
|
||||||
resource "google_compute_vpn_gateway" "foobar" {
|
resource "google_compute_vpn_gateway" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_esp" {
|
resource "google_compute_forwarding_rule" "foobar_esp" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s-1"
|
||||||
region = "${google_compute_vpn_gateway.foobar.region}"
|
region = "${google_compute_vpn_gateway.foobar.region}"
|
||||||
ip_protocol = "ESP"
|
ip_protocol = "ESP"
|
||||||
ip_address = "${google_compute_address.foobar.address}"
|
ip_address = "${google_compute_address.foobar.address}"
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_udp500" {
|
resource "google_compute_forwarding_rule" "foobar_udp500" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s-2"
|
||||||
region = "${google_compute_forwarding_rule.foobar_esp.region}"
|
region = "${google_compute_forwarding_rule.foobar_esp.region}"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
port_range = "500-500"
|
port_range = "500-500"
|
||||||
|
@ -198,7 +186,7 @@ func testAccComputeRouterPeerBasic(network, subnet, address, gateway, espFwRule,
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_udp4500" {
|
resource "google_compute_forwarding_rule" "foobar_udp4500" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s-3"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
port_range = "4500-4500"
|
port_range = "4500-4500"
|
||||||
|
@ -206,7 +194,7 @@ func testAccComputeRouterPeerBasic(network, subnet, address, gateway, espFwRule,
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_router" "foobar"{
|
resource "google_compute_router" "foobar"{
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
bgp {
|
bgp {
|
||||||
|
@ -214,7 +202,7 @@ func testAccComputeRouterPeerBasic(network, subnet, address, gateway, espFwRule,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resource "google_compute_vpn_tunnel" "foobar" {
|
resource "google_compute_vpn_tunnel" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp4500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp4500.region}"
|
||||||
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
|
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
shared_secret = "unguessable"
|
shared_secret = "unguessable"
|
||||||
|
@ -222,14 +210,14 @@ func testAccComputeRouterPeerBasic(network, subnet, address, gateway, espFwRule,
|
||||||
router = "${google_compute_router.foobar.name}"
|
router = "${google_compute_router.foobar.name}"
|
||||||
}
|
}
|
||||||
resource "google_compute_router_interface" "foobar" {
|
resource "google_compute_router_interface" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
router = "${google_compute_router.foobar.name}"
|
router = "${google_compute_router.foobar.name}"
|
||||||
region = "${google_compute_router.foobar.region}"
|
region = "${google_compute_router.foobar.region}"
|
||||||
ip_range = "169.254.3.1/30"
|
ip_range = "169.254.3.1/30"
|
||||||
vpn_tunnel = "${google_compute_vpn_tunnel.foobar.name}"
|
vpn_tunnel = "${google_compute_vpn_tunnel.foobar.name}"
|
||||||
}
|
}
|
||||||
resource "google_compute_router_peer" "foobar" {
|
resource "google_compute_router_peer" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
router = "${google_compute_router.foobar.name}"
|
router = "${google_compute_router.foobar.name}"
|
||||||
region = "${google_compute_router.foobar.region}"
|
region = "${google_compute_router.foobar.region}"
|
||||||
peer_ip_address = "169.254.3.2"
|
peer_ip_address = "169.254.3.2"
|
||||||
|
@ -237,38 +225,38 @@ func testAccComputeRouterPeerBasic(network, subnet, address, gateway, espFwRule,
|
||||||
advertised_route_priority = 100
|
advertised_route_priority = 100
|
||||||
interface = "${google_compute_router_interface.foobar.name}"
|
interface = "${google_compute_router_interface.foobar.name}"
|
||||||
}
|
}
|
||||||
`, network, subnet, address, gateway, espFwRule, udp500FwRule, udp4500FwRule, router, tunnel, iface, peer)
|
`, testId, testId, testId, testId, testId, testId, testId, testId, testId, testId, testId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccComputeRouterPeerKeepRouter(network, subnet, address, gateway, espFwRule, udp500FwRule, udp4500FwRule, router, tunnel, iface string) string {
|
func testAccComputeRouterPeerKeepRouter(testId string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_network" "foobar" {
|
resource "google_compute_network" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
}
|
}
|
||||||
resource "google_compute_subnetwork" "foobar" {
|
resource "google_compute_subnetwork" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
ip_cidr_range = "10.0.0.0/16"
|
ip_cidr_range = "10.0.0.0/16"
|
||||||
region = "us-central1"
|
region = "us-central1"
|
||||||
}
|
}
|
||||||
resource "google_compute_address" "foobar" {
|
resource "google_compute_address" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
}
|
}
|
||||||
resource "google_compute_vpn_gateway" "foobar" {
|
resource "google_compute_vpn_gateway" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_esp" {
|
resource "google_compute_forwarding_rule" "foobar_esp" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s-1"
|
||||||
region = "${google_compute_vpn_gateway.foobar.region}"
|
region = "${google_compute_vpn_gateway.foobar.region}"
|
||||||
ip_protocol = "ESP"
|
ip_protocol = "ESP"
|
||||||
ip_address = "${google_compute_address.foobar.address}"
|
ip_address = "${google_compute_address.foobar.address}"
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_udp500" {
|
resource "google_compute_forwarding_rule" "foobar_udp500" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s-2"
|
||||||
region = "${google_compute_forwarding_rule.foobar_esp.region}"
|
region = "${google_compute_forwarding_rule.foobar_esp.region}"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
port_range = "500-500"
|
port_range = "500-500"
|
||||||
|
@ -276,7 +264,7 @@ func testAccComputeRouterPeerKeepRouter(network, subnet, address, gateway, espFw
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_udp4500" {
|
resource "google_compute_forwarding_rule" "foobar_udp4500" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s-3"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
port_range = "4500-4500"
|
port_range = "4500-4500"
|
||||||
|
@ -284,7 +272,7 @@ func testAccComputeRouterPeerKeepRouter(network, subnet, address, gateway, espFw
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_router" "foobar"{
|
resource "google_compute_router" "foobar"{
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
bgp {
|
bgp {
|
||||||
|
@ -292,7 +280,7 @@ func testAccComputeRouterPeerKeepRouter(network, subnet, address, gateway, espFw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resource "google_compute_vpn_tunnel" "foobar" {
|
resource "google_compute_vpn_tunnel" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp4500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp4500.region}"
|
||||||
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
|
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
shared_secret = "unguessable"
|
shared_secret = "unguessable"
|
||||||
|
@ -300,11 +288,11 @@ func testAccComputeRouterPeerKeepRouter(network, subnet, address, gateway, espFw
|
||||||
router = "${google_compute_router.foobar.name}"
|
router = "${google_compute_router.foobar.name}"
|
||||||
}
|
}
|
||||||
resource "google_compute_router_interface" "foobar" {
|
resource "google_compute_router_interface" "foobar" {
|
||||||
name = "%s"
|
name = "router-peer-test-%s"
|
||||||
router = "${google_compute_router.foobar.name}"
|
router = "${google_compute_router.foobar.name}"
|
||||||
region = "${google_compute_router.foobar.region}"
|
region = "${google_compute_router.foobar.region}"
|
||||||
ip_range = "169.254.3.1/30"
|
ip_range = "169.254.3.1/30"
|
||||||
vpn_tunnel = "${google_compute_vpn_tunnel.foobar.name}"
|
vpn_tunnel = "${google_compute_vpn_tunnel.foobar.name}"
|
||||||
}
|
}
|
||||||
`, network, subnet, address, gateway, espFwRule, udp500FwRule, udp4500FwRule, router, tunnel, iface)
|
`, testId, testId, testId, testId, testId, testId, testId, testId, testId, testId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,21 +10,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeRouter_basic(t *testing.T) {
|
func TestAccComputeRouter_basic(t *testing.T) {
|
||||||
network := fmt.Sprintf("router-test-%s", acctest.RandString(10))
|
resourceRegion := "europe-west1"
|
||||||
subnet := fmt.Sprintf("router-test-%s", acctest.RandString(10))
|
|
||||||
router := fmt.Sprintf("router-test-%s", acctest.RandString(10))
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckComputeRouterDestroy,
|
CheckDestroy: testAccCheckComputeRouterDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeRouterBasic(network, subnet, router),
|
Config: testAccComputeRouterBasic(resourceRegion),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckComputeRouterExists(
|
testAccCheckComputeRouterExists(
|
||||||
"google_compute_router.foobar"),
|
"google_compute_router.foobar"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"google_compute_router.foobar", "region", "europe-west1"),
|
"google_compute_router.foobar", "region", resourceRegion),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -32,21 +30,19 @@ func TestAccComputeRouter_basic(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccComputeRouter_noRegion(t *testing.T) {
|
func TestAccComputeRouter_noRegion(t *testing.T) {
|
||||||
network := fmt.Sprintf("router-test-%s", acctest.RandString(10))
|
providerRegion := "us-central1"
|
||||||
subnet := fmt.Sprintf("router-test-%s", acctest.RandString(10))
|
|
||||||
router := fmt.Sprintf("router-test-%s", acctest.RandString(10))
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckComputeRouterDestroy,
|
CheckDestroy: testAccCheckComputeRouterDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeRouterNoRegion(network, subnet, router),
|
Config: testAccComputeRouterNoRegion(providerRegion),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckComputeRouterExists(
|
testAccCheckComputeRouterExists(
|
||||||
"google_compute_router.foobar"),
|
"google_compute_router.foobar"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"google_compute_router.foobar", "region", "us-central1"),
|
"google_compute_router.foobar", "region", providerRegion),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -54,16 +50,13 @@ func TestAccComputeRouter_noRegion(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccComputeRouter_networkLink(t *testing.T) {
|
func TestAccComputeRouter_networkLink(t *testing.T) {
|
||||||
network := fmt.Sprintf("router-test-%s", acctest.RandString(10))
|
|
||||||
subnet := fmt.Sprintf("router-test-%s", acctest.RandString(10))
|
|
||||||
router := fmt.Sprintf("router-test-%s", acctest.RandString(10))
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckComputeRouterDestroy,
|
CheckDestroy: testAccCheckComputeRouterDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeRouterNetworkLink(network, subnet, router),
|
Config: testAccComputeRouterNetworkLink(),
|
||||||
Check: testAccCheckComputeRouterExists(
|
Check: testAccCheckComputeRouterExists(
|
||||||
"google_compute_router.foobar"),
|
"google_compute_router.foobar"),
|
||||||
},
|
},
|
||||||
|
@ -140,67 +133,70 @@ func testAccCheckComputeRouterExists(n string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccComputeRouterBasic(network, subnet, router string) string {
|
func testAccComputeRouterBasic(resourceRegion string) string {
|
||||||
|
testId := acctest.RandString(10)
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_network" "foobar" {
|
resource "google_compute_network" "foobar" {
|
||||||
name = "%s"
|
name = "router-test-%s"
|
||||||
}
|
}
|
||||||
resource "google_compute_subnetwork" "foobar" {
|
resource "google_compute_subnetwork" "foobar" {
|
||||||
name = "%s"
|
name = "router-test-%s"
|
||||||
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
|
ip_cidr_range = "10.0.0.0/16"
|
||||||
|
region = "%s"
|
||||||
|
}
|
||||||
|
resource "google_compute_router" "foobar" {
|
||||||
|
name = "router-test-%s"
|
||||||
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
|
network = "${google_compute_network.foobar.name}"
|
||||||
|
bgp {
|
||||||
|
asn = 64514
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, testId, testId, resourceRegion, testId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccComputeRouterNoRegion(providerRegion string) string {
|
||||||
|
testId := acctest.RandString(10)
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_compute_network" "foobar" {
|
||||||
|
name = "router-test-%s"
|
||||||
|
}
|
||||||
|
resource "google_compute_subnetwork" "foobar" {
|
||||||
|
name = "router-test-%s"
|
||||||
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
|
ip_cidr_range = "10.0.0.0/16"
|
||||||
|
region = "%s"
|
||||||
|
}
|
||||||
|
resource "google_compute_router" "foobar" {
|
||||||
|
name = "router-test-%s"
|
||||||
|
network = "${google_compute_network.foobar.name}"
|
||||||
|
bgp {
|
||||||
|
asn = 64514
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, testId, testId, providerRegion, testId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccComputeRouterNetworkLink() string {
|
||||||
|
testId := acctest.RandString(10)
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_compute_network" "foobar" {
|
||||||
|
name = "router-test-%s"
|
||||||
|
}
|
||||||
|
resource "google_compute_subnetwork" "foobar" {
|
||||||
|
name = "router-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
ip_cidr_range = "10.0.0.0/16"
|
ip_cidr_range = "10.0.0.0/16"
|
||||||
region = "europe-west1"
|
region = "europe-west1"
|
||||||
}
|
}
|
||||||
resource "google_compute_router" "foobar" {
|
resource "google_compute_router" "foobar" {
|
||||||
name = "%s"
|
name = "router-test-%s"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
|
||||||
network = "${google_compute_network.foobar.name}"
|
|
||||||
bgp {
|
|
||||||
asn = 64514
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`, network, subnet, router)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccComputeRouterNoRegion(network, subnet, router string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "google_compute_network" "foobar" {
|
|
||||||
name = "%s"
|
|
||||||
}
|
|
||||||
resource "google_compute_subnetwork" "foobar" {
|
|
||||||
name = "%s"
|
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
|
||||||
ip_cidr_range = "10.0.0.0/16"
|
|
||||||
region = "us-central1"
|
|
||||||
}
|
|
||||||
resource "google_compute_router" "foobar" {
|
|
||||||
name = "%s"
|
|
||||||
network = "${google_compute_network.foobar.name}"
|
|
||||||
bgp {
|
|
||||||
asn = 64514
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`, network, subnet, router)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccComputeRouterNetworkLink(network, subnet, router string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "google_compute_network" "foobar" {
|
|
||||||
name = "%s"
|
|
||||||
}
|
|
||||||
resource "google_compute_subnetwork" "foobar" {
|
|
||||||
name = "%s"
|
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
|
||||||
ip_cidr_range = "10.0.0.0/16"
|
|
||||||
region = "us-central1"
|
|
||||||
}
|
|
||||||
resource "google_compute_router" "foobar" {
|
|
||||||
name = "%s"
|
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
bgp {
|
bgp {
|
||||||
asn = 64514
|
asn = 64514
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, network, subnet, router)
|
`, testId, testId, testId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,23 +33,14 @@ func TestAccComputeVpnTunnel_basic(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccComputeVpnTunnel_router(t *testing.T) {
|
func TestAccComputeVpnTunnel_router(t *testing.T) {
|
||||||
network := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
router := fmt.Sprintf("tunnel-test-router-%s", acctest.RandString(10))
|
||||||
subnet := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
address := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
gateway := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
espRule := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
udp500Rule := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
udp4500Rule := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
router := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
tunnel := fmt.Sprintf("router-interface-test-%s", acctest.RandString(10))
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckComputeVpnTunnelDestroy,
|
CheckDestroy: testAccCheckComputeVpnTunnelDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeVpnTunnelRouter(network, subnet, address, gateway, espRule, udp500Rule,
|
Config: testAccComputeVpnTunnelRouter(router),
|
||||||
udp4500Rule, router, tunnel),
|
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckComputeVpnTunnelExists(
|
testAccCheckComputeVpnTunnelExists(
|
||||||
"google_compute_vpn_tunnel.foobar"),
|
"google_compute_vpn_tunnel.foobar"),
|
||||||
|
@ -183,35 +174,36 @@ resource "google_compute_vpn_tunnel" "foobar" {
|
||||||
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), acctest.RandString(10))
|
||||||
|
|
||||||
func testAccComputeVpnTunnelRouter(network, subnet, address, gateway, espFwRule, udp500FwRule, udp4500FwRule, router, tunnel string) string {
|
func testAccComputeVpnTunnelRouter(router string) string {
|
||||||
|
testId := acctest.RandString(10)
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_network" "foobar" {
|
resource "google_compute_network" "foobar" {
|
||||||
name = "%s"
|
name = "tunnel-test-%s"
|
||||||
}
|
}
|
||||||
resource "google_compute_subnetwork" "foobar" {
|
resource "google_compute_subnetwork" "foobar" {
|
||||||
name = "%s"
|
name = "tunnel-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
ip_cidr_range = "10.0.0.0/16"
|
ip_cidr_range = "10.0.0.0/16"
|
||||||
region = "us-central1"
|
region = "us-central1"
|
||||||
}
|
}
|
||||||
resource "google_compute_address" "foobar" {
|
resource "google_compute_address" "foobar" {
|
||||||
name = "%s"
|
name = "tunnel-test-%s"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
}
|
}
|
||||||
resource "google_compute_vpn_gateway" "foobar" {
|
resource "google_compute_vpn_gateway" "foobar" {
|
||||||
name = "%s"
|
name = "tunnel-test-%s"
|
||||||
network = "${google_compute_network.foobar.self_link}"
|
network = "${google_compute_network.foobar.self_link}"
|
||||||
region = "${google_compute_subnetwork.foobar.region}"
|
region = "${google_compute_subnetwork.foobar.region}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_esp" {
|
resource "google_compute_forwarding_rule" "foobar_esp" {
|
||||||
name = "%s"
|
name = "tunnel-test-%s-1"
|
||||||
region = "${google_compute_vpn_gateway.foobar.region}"
|
region = "${google_compute_vpn_gateway.foobar.region}"
|
||||||
ip_protocol = "ESP"
|
ip_protocol = "ESP"
|
||||||
ip_address = "${google_compute_address.foobar.address}"
|
ip_address = "${google_compute_address.foobar.address}"
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_udp500" {
|
resource "google_compute_forwarding_rule" "foobar_udp500" {
|
||||||
name = "%s"
|
name = "tunnel-test-%s-2"
|
||||||
region = "${google_compute_forwarding_rule.foobar_esp.region}"
|
region = "${google_compute_forwarding_rule.foobar_esp.region}"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
port_range = "500-500"
|
port_range = "500-500"
|
||||||
|
@ -219,7 +211,7 @@ func testAccComputeVpnTunnelRouter(network, subnet, address, gateway, espFwRule,
|
||||||
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
target = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
}
|
}
|
||||||
resource "google_compute_forwarding_rule" "foobar_udp4500" {
|
resource "google_compute_forwarding_rule" "foobar_udp4500" {
|
||||||
name = "%s"
|
name = "tunnel-test-%s-3"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp500.region}"
|
||||||
ip_protocol = "UDP"
|
ip_protocol = "UDP"
|
||||||
port_range = "4500-4500"
|
port_range = "4500-4500"
|
||||||
|
@ -235,14 +227,14 @@ func testAccComputeVpnTunnelRouter(network, subnet, address, gateway, espFwRule,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resource "google_compute_vpn_tunnel" "foobar" {
|
resource "google_compute_vpn_tunnel" "foobar" {
|
||||||
name = "%s"
|
name = "tunnel-test-%s"
|
||||||
region = "${google_compute_forwarding_rule.foobar_udp4500.region}"
|
region = "${google_compute_forwarding_rule.foobar_udp4500.region}"
|
||||||
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
|
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
|
||||||
shared_secret = "unguessable"
|
shared_secret = "unguessable"
|
||||||
peer_ip = "8.8.8.8"
|
peer_ip = "8.8.8.8"
|
||||||
router = "${google_compute_router.foobar.name}"
|
router = "${google_compute_router.foobar.name}"
|
||||||
}
|
}
|
||||||
`, network, subnet, address, gateway, espFwRule, udp500FwRule, udp4500FwRule, router, tunnel)
|
`, testId, testId, testId, testId, testId, testId, testId, router, testId)
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccComputeVpnTunnelDefaultTrafficSelectors = fmt.Sprintf(`
|
var testAccComputeVpnTunnelDefaultTrafficSelectors = fmt.Sprintf(`
|
||||||
|
|
Loading…
Reference in New Issue