2015-05-01 18:23:16 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/awslabs/aws-sdk-go/aws"
|
|
|
|
"github.com/awslabs/aws-sdk-go/service/ec2"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAwsVpnConnection(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccAwsVpnConnectionDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAwsVpnConnectionConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccAwsVpnConnection(
|
|
|
|
"aws_vpc.vpc",
|
|
|
|
"aws_vpn_gateway.vpn_gateway",
|
|
|
|
"aws_customer_gateway.customer_gateway",
|
|
|
|
"aws_vpn_connection.foo",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAwsVpnConnectionConfigUpdate,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccAwsVpnConnection(
|
|
|
|
"aws_vpc.vpc",
|
|
|
|
"aws_vpn_gateway.vpn_gateway",
|
|
|
|
"aws_customer_gateway.customer_gateway",
|
2015-05-04 00:40:10 +02:00
|
|
|
"aws_vpn_connection.foo",
|
2015-05-01 18:23:16 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccAwsVpnConnectionDestroy(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 testAccAwsVpnConnection(
|
|
|
|
vpcResource string,
|
|
|
|
vpnGatewayResource string,
|
|
|
|
customerGatewayResource string,
|
|
|
|
vpnConnectionResource string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[vpnConnectionResource]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", vpnConnectionResource)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
connection, ok := s.RootModule().Resources[vpnConnectionResource]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", vpnConnectionResource)
|
|
|
|
}
|
|
|
|
|
|
|
|
ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
|
|
|
|
_, err := ec2conn.DescribeVPNConnections(&ec2.DescribeVPNConnectionsInput{
|
|
|
|
VPNConnectionIDs: []*string{aws.String(connection.Primary.ID)},
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccAwsVpnConnectionConfig = `
|
|
|
|
resource "aws_vpn_gateway" "vpn_gateway" {
|
2015-05-04 00:40:10 +02:00
|
|
|
tags {
|
|
|
|
Name = "vpn_gateway"
|
|
|
|
}
|
2015-05-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_customer_gateway" "customer_gateway" {
|
|
|
|
bgp_asn = 60000
|
2015-05-04 00:40:10 +02:00
|
|
|
ip_address = "178.0.0.1"
|
|
|
|
type = "ipsec.1"
|
2015-05-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpn_connection" "foo" {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2015-05-04 00:40:10 +02:00
|
|
|
// Change static_routes_only to be false, forcing a refresh.
|
2015-05-01 18:23:16 +02:00
|
|
|
const testAccAwsVpnConnectionConfigUpdate = `
|
|
|
|
resource "aws_vpn_gateway" "vpn_gateway" {
|
2015-05-04 00:40:10 +02:00
|
|
|
tags {
|
|
|
|
Name = "vpn_gateway"
|
|
|
|
}
|
2015-05-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_customer_gateway" "customer_gateway" {
|
|
|
|
bgp_asn = 60000
|
2015-05-04 00:40:10 +02:00
|
|
|
ip_address = "178.0.0.1"
|
2015-05-01 18:23:16 +02:00
|
|
|
type = "ipsec.1"
|
|
|
|
}
|
|
|
|
|
2015-05-04 00:40:10 +02:00
|
|
|
resource "aws_vpn_connection" "foo" {
|
2015-05-01 18:23:16 +02:00
|
|
|
vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}"
|
|
|
|
customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}"
|
|
|
|
type = "ipsec.1"
|
|
|
|
static_routes_only = false
|
|
|
|
}
|
|
|
|
`
|