2015-05-04 18:21:05 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2015-05-04 18:21:05 +02:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2015-06-08 01:18:14 +02:00
|
|
|
func TestAccAwsVpnConnectionRoute_basic(t *testing.T) {
|
2015-05-04 18:21:05 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccAwsVpnConnectionRouteDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAwsVpnConnectionRouteConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccAwsVpnConnectionRoute(
|
|
|
|
"aws_vpn_gateway.vpn_gateway",
|
|
|
|
"aws_customer_gateway.customer_gateway",
|
|
|
|
"aws_vpn_connection.vpn_connection",
|
|
|
|
"aws_vpn_connection_route.foo",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAwsVpnConnectionRouteConfigUpdate,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccAwsVpnConnectionRoute(
|
|
|
|
"aws_vpn_gateway.vpn_gateway",
|
|
|
|
"aws_customer_gateway.customer_gateway",
|
|
|
|
"aws_vpn_connection.vpn_connection",
|
|
|
|
"aws_vpn_connection_route.foo",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccAwsVpnConnectionRouteDestroy(s *terraform.State) error {
|
|
|
|
if len(s.RootModule().Resources) > 0 {
|
|
|
|
return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccAwsVpnConnectionRoute(
|
|
|
|
vpnGatewayResource string,
|
|
|
|
customerGatewayResource string,
|
|
|
|
vpnConnectionResource string,
|
|
|
|
vpnConnectionRouteResource string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[vpnConnectionRouteResource]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", vpnConnectionRouteResource)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
route, ok := s.RootModule().Resources[vpnConnectionRouteResource]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", vpnConnectionRouteResource)
|
|
|
|
}
|
|
|
|
|
|
|
|
cidrBlock, vpnConnectionId := resourceAwsVpnConnectionRouteParseId(route.Primary.ID)
|
|
|
|
|
|
|
|
routeFilters := []*ec2.Filter{
|
|
|
|
&ec2.Filter{
|
|
|
|
Name: aws.String("route.destination-cidr-block"),
|
|
|
|
Values: []*string{aws.String(cidrBlock)},
|
|
|
|
},
|
|
|
|
&ec2.Filter{
|
|
|
|
Name: aws.String("vpn-connection-id"),
|
|
|
|
Values: []*string{aws.String(vpnConnectionId)},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
|
2015-08-17 20:27:16 +02:00
|
|
|
_, err := ec2conn.DescribeVpnConnections(&ec2.DescribeVpnConnectionsInput{
|
2015-05-04 18:21:05 +02:00
|
|
|
Filters: routeFilters,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccAwsVpnConnectionRouteConfig = `
|
|
|
|
resource "aws_vpn_gateway" "vpn_gateway" {
|
|
|
|
tags {
|
|
|
|
Name = "vpn_gateway"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_customer_gateway" "customer_gateway" {
|
|
|
|
bgp_asn = 60000
|
|
|
|
ip_address = "182.0.0.1"
|
|
|
|
type = "ipsec.1"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpn_connection" "vpn_connection" {
|
|
|
|
vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}"
|
|
|
|
customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}"
|
|
|
|
type = "ipsec.1"
|
|
|
|
static_routes_only = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpn_connection_route" "foo" {
|
|
|
|
destination_cidr_block = "172.168.10.0/24"
|
|
|
|
vpn_connection_id = "${aws_vpn_connection.vpn_connection.id}"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
// Change destination_cidr_block
|
|
|
|
const testAccAwsVpnConnectionRouteConfigUpdate = `
|
|
|
|
resource "aws_vpn_gateway" "vpn_gateway" {
|
|
|
|
tags {
|
|
|
|
Name = "vpn_gateway"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_customer_gateway" "customer_gateway" {
|
|
|
|
bgp_asn = 60000
|
|
|
|
ip_address = "182.0.0.1"
|
|
|
|
type = "ipsec.1"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpn_connection" "vpn_connection" {
|
|
|
|
vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}"
|
|
|
|
customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}"
|
|
|
|
type = "ipsec.1"
|
|
|
|
static_routes_only = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpn_connection_route" "foo" {
|
|
|
|
destination_cidr_block = "172.168.20.0/24"
|
|
|
|
vpn_connection_id = "${aws_vpn_connection.vpn_connection.id}"
|
|
|
|
}
|
|
|
|
`
|