allow vpc_peering_connection_id in aws_route_table
This commit is contained in:
parent
3b5ee93f73
commit
3b0b41c9a1
|
@ -47,6 +47,11 @@ func resourceAwsRouteTable() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"vpc_peering_connection_id": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Set: resourceAwsRouteTableHash,
|
Set: resourceAwsRouteTableHash,
|
||||||
|
@ -125,6 +130,7 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
m["gateway_id"] = r.GatewayId
|
m["gateway_id"] = r.GatewayId
|
||||||
m["instance_id"] = r.InstanceId
|
m["instance_id"] = r.InstanceId
|
||||||
|
m["vpc_peering_connection_id"] = r.VpcPeeringConnectionId
|
||||||
|
|
||||||
route.Add(m)
|
route.Add(m)
|
||||||
}
|
}
|
||||||
|
@ -166,10 +172,11 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
|
||||||
m := route.(map[string]interface{})
|
m := route.(map[string]interface{})
|
||||||
|
|
||||||
opts := ec2.CreateRoute{
|
opts := ec2.CreateRoute{
|
||||||
RouteTableId: d.Id(),
|
RouteTableId: d.Id(),
|
||||||
DestinationCidrBlock: m["cidr_block"].(string),
|
DestinationCidrBlock: m["cidr_block"].(string),
|
||||||
GatewayId: m["gateway_id"].(string),
|
GatewayId: m["gateway_id"].(string),
|
||||||
InstanceId: m["instance_id"].(string),
|
InstanceId: m["instance_id"].(string),
|
||||||
|
VpcPeeringConnectionId: m["vpc_peering_connection_id"].(string),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := ec2conn.CreateRoute(&opts)
|
_, err := ec2conn.CreateRoute(&opts)
|
||||||
|
@ -257,6 +264,10 @@ func resourceAwsRouteTableHash(v interface{}) int {
|
||||||
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
|
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v, ok := m["vpc_peering_connection_id"]; ok {
|
||||||
|
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
|
||||||
|
}
|
||||||
|
|
||||||
return hashcode.String(buf.String())
|
return hashcode.String(buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,27 +129,26 @@ func TestAccAWSRouteTable_tags(t *testing.T) {
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckRouteTableDestroy,
|
CheckDestroy: testAccCheckRouteTableDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccRouteTableConfigTags,
|
Config: testAccRouteTableConfigTags,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
|
testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
|
||||||
testAccCheckTags(&route_table.Tags, "foo", "bar"),
|
testAccCheckTags(&route_table.Tags, "foo", "bar"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccRouteTableConfigTagsUpdate,
|
Config: testAccRouteTableConfigTagsUpdate,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
|
testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
|
||||||
testAccCheckTags(&route_table.Tags, "foo", ""),
|
testAccCheckTags(&route_table.Tags, "foo", ""),
|
||||||
testAccCheckTags(&route_table.Tags, "bar", "baz"),
|
testAccCheckTags(&route_table.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func testAccCheckRouteTableDestroy(s *terraform.State) error {
|
func testAccCheckRouteTableDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
|
|
||||||
|
@ -209,6 +208,45 @@ func testAccCheckRouteTableExists(n string, v *ec2.RouteTable) resource.TestChec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSRouteTable_vpcPeering(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: testAccRouteTableVpcPeeringConfig,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckRouteTableExists(
|
||||||
|
"aws_route_table.foo", &v),
|
||||||
|
testCheck,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const testAccRouteTableConfig = `
|
const testAccRouteTableConfig = `
|
||||||
resource "aws_vpc" "foo" {
|
resource "aws_vpc" "foo" {
|
||||||
cidr_block = "10.1.0.0/16"
|
cidr_block = "10.1.0.0/16"
|
||||||
|
@ -306,3 +344,22 @@ resource "aws_route_table" "foo" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testAccRouteTableVpcPeeringConfig = `
|
||||||
|
resource "aws_vpc" "foo" {
|
||||||
|
cidr_block = "10.1.0.0/16"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_internet_gateway" "foo" {
|
||||||
|
vpc_id = "${aws_vpc.foo.id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_route_table" "foo" {
|
||||||
|
vpc_id = "${aws_vpc.foo.id}"
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "10.2.0.0/16"
|
||||||
|
vpc_peering_connection_id = "vpc-12345"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
|
@ -39,8 +39,9 @@ Each route supports the following:
|
||||||
* `cidr_block` - (Required) The CIDR block of the route.
|
* `cidr_block` - (Required) The CIDR block of the route.
|
||||||
* `gateway_id` - (Optional) The Internet Gateway ID.
|
* `gateway_id` - (Optional) The Internet Gateway ID.
|
||||||
* `instance_id` - (Optional) The EC2 instance ID.
|
* `instance_id` - (Optional) The EC2 instance ID.
|
||||||
|
* `vpc_peering_connection_id` - (Optional) The VPC Peering ID.
|
||||||
|
|
||||||
Each route must contain either a `gateway_id` or an `instance_id`. Note that the
|
Each route must contain either a `gateway_id`, an `instance_id` or a `vpc_peering_connection_id`. Note that the
|
||||||
default route, mapping the VPC's CIDR block to "local", is created implicitly and
|
default route, mapping the VPC's CIDR block to "local", is created implicitly and
|
||||||
cannot be specified.
|
cannot be specified.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue