github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/aws/resource_vpn_connection_route_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/service/ec2" 9 10 "github.com/hashicorp/terraform/helper/resource" 11 "github.com/hashicorp/terraform/terraform" 12 ) 13 14 func TestAccAwsVpnConnectionRoute_basic(t *testing.T) { 15 resource.Test(t, resource.TestCase{ 16 PreCheck: func() { testAccPreCheck(t) }, 17 Providers: testAccProviders, 18 CheckDestroy: testAccAwsVpnConnectionRouteDestroy, 19 Steps: []resource.TestStep{ 20 resource.TestStep{ 21 Config: testAccAwsVpnConnectionRouteConfig, 22 Check: resource.ComposeTestCheckFunc( 23 testAccAwsVpnConnectionRoute( 24 "aws_vpn_gateway.vpn_gateway", 25 "aws_customer_gateway.customer_gateway", 26 "aws_vpn_connection.vpn_connection", 27 "aws_vpn_connection_route.foo", 28 ), 29 ), 30 }, 31 resource.TestStep{ 32 Config: testAccAwsVpnConnectionRouteConfigUpdate, 33 Check: resource.ComposeTestCheckFunc( 34 testAccAwsVpnConnectionRoute( 35 "aws_vpn_gateway.vpn_gateway", 36 "aws_customer_gateway.customer_gateway", 37 "aws_vpn_connection.vpn_connection", 38 "aws_vpn_connection_route.foo", 39 ), 40 ), 41 }, 42 }, 43 }) 44 } 45 46 func testAccAwsVpnConnectionRouteDestroy(s *terraform.State) error { 47 if len(s.RootModule().Resources) > 0 { 48 return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources) 49 } 50 51 return nil 52 } 53 54 func testAccAwsVpnConnectionRoute( 55 vpnGatewayResource string, 56 customerGatewayResource string, 57 vpnConnectionResource string, 58 vpnConnectionRouteResource string) resource.TestCheckFunc { 59 return func(s *terraform.State) error { 60 rs, ok := s.RootModule().Resources[vpnConnectionRouteResource] 61 if !ok { 62 return fmt.Errorf("Not found: %s", vpnConnectionRouteResource) 63 } 64 65 if rs.Primary.ID == "" { 66 return fmt.Errorf("No ID is set") 67 } 68 route, ok := s.RootModule().Resources[vpnConnectionRouteResource] 69 if !ok { 70 return fmt.Errorf("Not found: %s", vpnConnectionRouteResource) 71 } 72 73 cidrBlock, vpnConnectionId := resourceAwsVpnConnectionRouteParseId(route.Primary.ID) 74 75 routeFilters := []*ec2.Filter{ 76 &ec2.Filter{ 77 Name: aws.String("route.destination-cidr-block"), 78 Values: []*string{aws.String(cidrBlock)}, 79 }, 80 &ec2.Filter{ 81 Name: aws.String("vpn-connection-id"), 82 Values: []*string{aws.String(vpnConnectionId)}, 83 }, 84 } 85 86 ec2conn := testAccProvider.Meta().(*AWSClient).ec2conn 87 88 _, err := ec2conn.DescribeVpnConnections(&ec2.DescribeVpnConnectionsInput{ 89 Filters: routeFilters, 90 }) 91 if err != nil { 92 return err 93 } 94 95 return nil 96 } 97 } 98 99 const testAccAwsVpnConnectionRouteConfig = ` 100 resource "aws_vpn_gateway" "vpn_gateway" { 101 tags { 102 Name = "vpn_gateway" 103 } 104 } 105 106 resource "aws_customer_gateway" "customer_gateway" { 107 bgp_asn = 60000 108 ip_address = "182.0.0.1" 109 type = "ipsec.1" 110 } 111 112 resource "aws_vpn_connection" "vpn_connection" { 113 vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" 114 customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" 115 type = "ipsec.1" 116 static_routes_only = true 117 } 118 119 resource "aws_vpn_connection_route" "foo" { 120 destination_cidr_block = "172.168.10.0/24" 121 vpn_connection_id = "${aws_vpn_connection.vpn_connection.id}" 122 } 123 ` 124 125 // Change destination_cidr_block 126 const testAccAwsVpnConnectionRouteConfigUpdate = ` 127 resource "aws_vpn_gateway" "vpn_gateway" { 128 tags { 129 Name = "vpn_gateway" 130 } 131 } 132 133 resource "aws_customer_gateway" "customer_gateway" { 134 bgp_asn = 60000 135 ip_address = "182.0.0.1" 136 type = "ipsec.1" 137 } 138 139 resource "aws_vpn_connection" "vpn_connection" { 140 vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" 141 customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" 142 type = "ipsec.1" 143 static_routes_only = true 144 } 145 146 resource "aws_vpn_connection_route" "foo" { 147 destination_cidr_block = "172.168.20.0/24" 148 vpn_connection_id = "${aws_vpn_connection.vpn_connection.id}" 149 } 150 `