providers/aws/aws_route_table: can set routes on instance_id

This commit is contained in:
Mitchell Hashimoto 2014-07-17 09:21:55 -07:00
parent 79dbd07679
commit d956880e2f
2 changed files with 69 additions and 1 deletions

View File

@ -9,7 +9,7 @@ import (
"github.com/mitchellh/goamz/ec2"
)
func TestAccAWSRouteTable(t *testing.T) {
func TestAccAWSRouteTable_normal(t *testing.T) {
var v ec2.RouteTable
testCheck := func(*terraform.State) error {
@ -81,6 +81,46 @@ func TestAccAWSRouteTable(t *testing.T) {
})
}
func TestAccAWSRouteTable_instance(t *testing.T) {
var v ec2.RouteTable
testCheck := func(*terraform.State) error {
if len(v.Routes) != 2 {
return fmt.Errorf("bad routes: %#v", v.Routes)
}
routes := make(map[string]ec2.Route)
for _, r := range v.Routes {
routes[r.DestinationCidrBlock] = r
}
if _, ok := routes["10.1.0.0/16"]; !ok {
return fmt.Errorf("bad routes: %#v", v.Routes)
}
if _, ok := routes["10.2.0.0/16"]; !ok {
return fmt.Errorf("bad routes: %#v", v.Routes)
}
return nil
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRouteTableDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRouteTableConfigInstance,
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists(
"aws_route_table.foo", &v),
testCheck,
),
},
},
})
}
func testAccCheckRouteTableDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn
@ -182,3 +222,30 @@ resource "aws_route_table" "foo" {
}
}
`
const testAccRouteTableConfigInstance = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
resource "aws_subnet" "foo" {
cidr_block = "10.1.1.0/24"
vpc_id = "${aws_vpc.foo.id}"
}
resource "aws_instance" "foo" {
# us-west-2
ami = "ami-4fccb37f"
instance_type = "m1.small"
subnet_id = "${aws_subnet.foo.id}"
}
resource "aws_route_table" "foo" {
vpc_id = "${aws_vpc.foo.id}"
route {
cidr_block = "10.2.0.0/16"
instance_id = "${aws_instance.foo.id}"
}
}
`

View File

@ -70,6 +70,7 @@ func init() {
},
Optional: []string{
"route.*.gateway_id",
"route.*.instance_id",
},
},
Create: resource_aws_route_table_create,