2015-02-12 03:45:29 -06:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-04-09 12:18:50 -05:00
|
|
|
"os"
|
2015-02-12 03:45:29 -06:00
|
|
|
"testing"
|
|
|
|
|
2015-04-14 11:23:26 -05:00
|
|
|
"github.com/awslabs/aws-sdk-go/aws"
|
|
|
|
"github.com/awslabs/aws-sdk-go/service/ec2"
|
2015-02-12 03:45:29 -06:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAWSVPCPeeringConnection_normal(t *testing.T) {
|
|
|
|
var conf ec2.Address
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
2015-04-09 12:18:50 -05:00
|
|
|
PreCheck: func() {
|
|
|
|
testAccPreCheck(t)
|
|
|
|
if os.Getenv("AWS_ACCOUNT_ID") == "" {
|
|
|
|
t.Fatal("AWS_ACCOUNT_ID must be set")
|
|
|
|
}
|
|
|
|
},
|
2015-02-12 03:45:29 -06:00
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSVpcPeeringConnectionDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccVpcPeeringConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSVpcPeeringConnectionExists("aws_vpc_peering_connection.foo", &conf),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error {
|
2015-04-14 11:23:26 -05:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
|
2015-02-12 03:45:29 -06:00
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_vpc_peering_connection" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-03-10 15:18:30 -05:00
|
|
|
describe, err := conn.DescribeVPCPeeringConnections(
|
2015-04-14 11:23:26 -05:00
|
|
|
&ec2.DescribeVPCPeeringConnectionsInput{
|
|
|
|
VPCPeeringConnectionIDs: []*string{aws.String(rs.Primary.ID)},
|
2015-03-10 15:18:30 -05:00
|
|
|
})
|
2015-02-12 03:45:29 -06:00
|
|
|
|
|
|
|
if err == nil {
|
2015-03-10 15:18:30 -05:00
|
|
|
if len(describe.VPCPeeringConnections) != 0 {
|
2015-02-12 03:45:29 -06:00
|
|
|
return fmt.Errorf("vpc peering connection still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSVpcPeeringConnectionExists(n string, res *ec2.Address) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No vpc peering connection id is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccVpcPeeringConfig = `
|
|
|
|
resource "aws_vpc" "foo" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpc" "bar" {
|
2015-03-10 14:44:07 -05:00
|
|
|
cidr_block = "10.1.0.0/16"
|
2015-02-12 03:45:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpc_peering_connection" "foo" {
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
peer_vpc_id = "${aws_vpc.bar.id}"
|
|
|
|
}
|
|
|
|
`
|