Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Add IPv6 Support to aws_route_table #12640

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions builtin/providers/aws/data_source_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ func dataSourceAwsRouteTable() *schema.Resource {
Computed: true,
},

"ipv6_cidr_block": {
Type: schema.TypeString,
Computed: true,
},

"egress_only_gateway_id": {
Type: schema.TypeString,
Computed: true,
},

"gateway_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -177,6 +187,12 @@ func dataSourceRoutesRead(ec2Routes []*ec2.Route) []map[string]interface{} {
if r.DestinationCidrBlock != nil {
m["cidr_block"] = *r.DestinationCidrBlock
}
if r.DestinationIpv6CidrBlock != nil {
m["ipv6_cidr_block"] = *r.DestinationIpv6CidrBlock
}
if r.EgressOnlyInternetGatewayId != nil {
m["egress_only_gateway_id"] = *r.EgressOnlyInternetGatewayId
}
if r.GatewayId != nil {
m["gateway_id"] = *r.GatewayId
}
Expand Down
4 changes: 2 additions & 2 deletions builtin/providers/aws/data_source_aws_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAccDataSourceAwsRouteTable_basic(t *testing.T) {
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccDataSourceAwsRouteTableGroupConfig,
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_tag"),
Expand All @@ -33,7 +33,7 @@ func TestAccDataSourceAwsRouteTable_main(t *testing.T) {
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccDataSourceAwsRouteTableMainRoute,
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsRouteTableCheckMain("data.aws_route_table.by_filter"),
Expand Down
1 change: 1 addition & 0 deletions builtin/providers/aws/import_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func resourceAwsRouteTableImportState(
d.SetType("aws_route")
d.Set("route_table_id", id)
d.Set("destination_cidr_block", route.DestinationCidrBlock)
d.Set("destination_ipv6_cidr_block", route.DestinationIpv6CidrBlock)
d.SetId(routeIDHash(d, route))
results = append(results, d)
}
Expand Down
8 changes: 4 additions & 4 deletions builtin/providers/aws/import_aws_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ func TestAccAWSRouteTable_importBasic(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckRouteTableDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccRouteTableConfig,
},

resource.TestStep{
{
ResourceName: "aws_route_table.foo",
ImportState: true,
ImportStateCheck: checkFn,
Expand All @@ -51,11 +51,11 @@ func TestAccAWSRouteTable_complex(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckRouteTableDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccRouteTableConfig_complexImport,
},

resource.TestStep{
{
ResourceName: "aws_route_table.mod",
ImportState: true,
ImportStateCheck: checkFn,
Expand Down
112 changes: 86 additions & 26 deletions builtin/providers/aws/resource_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,63 @@ func resourceAwsRouteTable() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"vpc_id": &schema.Schema{
"vpc_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"tags": tagsSchema(),

"propagating_vgws": &schema.Schema{
"propagating_vgws": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"route": &schema.Schema{
"route": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cidr_block": &schema.Schema{
"cidr_block": {
Type: schema.TypeString,
Required: true,
Optional: true,
},

"ipv6_cidr_block": {
Type: schema.TypeString,
Optional: true,
},

"gateway_id": &schema.Schema{
"egress_only_gateway_id": {
Type: schema.TypeString,
Optional: true,
},

"instance_id": &schema.Schema{
"gateway_id": {
Type: schema.TypeString,
Optional: true,
},

"nat_gateway_id": &schema.Schema{
"instance_id": {
Type: schema.TypeString,
Optional: true,
},

"vpc_peering_connection_id": &schema.Schema{
"nat_gateway_id": {
Type: schema.TypeString,
Optional: true,
},

"network_interface_id": &schema.Schema{
"vpc_peering_connection_id": {
Type: schema.TypeString,
Optional: true,
},

"network_interface_id": {
Type: schema.TypeString,
Optional: true,
},
Expand Down Expand Up @@ -166,6 +176,12 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
if r.DestinationCidrBlock != nil {
m["cidr_block"] = *r.DestinationCidrBlock
}
if r.DestinationIpv6CidrBlock != nil {
m["ipv6_cidr_block"] = *r.DestinationIpv6CidrBlock
}
if r.EgressOnlyInternetGatewayId != nil {
m["egress_only_gateway_id"] = *r.EgressOnlyInternetGatewayId
}
if r.GatewayId != nil {
m["gateway_id"] = *r.GatewayId
}
Expand Down Expand Up @@ -266,14 +282,27 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
for _, route := range ors.List() {
m := route.(map[string]interface{})

// Delete the route as it no longer exists in the config
log.Printf(
"[INFO] Deleting route from %s: %s",
d.Id(), m["cidr_block"].(string))
_, err := conn.DeleteRoute(&ec2.DeleteRouteInput{
RouteTableId: aws.String(d.Id()),
DestinationCidrBlock: aws.String(m["cidr_block"].(string)),
})
deleteOpts := &ec2.DeleteRouteInput{
RouteTableId: aws.String(d.Id()),
}

if s := m["ipv6_cidr_block"].(string); s != "" {
deleteOpts.DestinationIpv6CidrBlock = aws.String(s)

log.Printf(
"[INFO] Deleting route from %s: %s",
d.Id(), m["ipv6_cidr_block"].(string))
}

if s := m["cidr_block"].(string); s != "" {
deleteOpts.DestinationCidrBlock = aws.String(s)

log.Printf(
"[INFO] Deleting route from %s: %s",
d.Id(), m["cidr_block"].(string))
}

_, err := conn.DeleteRoute(deleteOpts)
if err != nil {
return err
}
Expand All @@ -288,16 +317,39 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
m := route.(map[string]interface{})

opts := ec2.CreateRouteInput{
RouteTableId: aws.String(d.Id()),
DestinationCidrBlock: aws.String(m["cidr_block"].(string)),
GatewayId: aws.String(m["gateway_id"].(string)),
InstanceId: aws.String(m["instance_id"].(string)),
VpcPeeringConnectionId: aws.String(m["vpc_peering_connection_id"].(string)),
NetworkInterfaceId: aws.String(m["network_interface_id"].(string)),
RouteTableId: aws.String(d.Id()),
}

if s := m["vpc_peering_connection_id"].(string); s != "" {
opts.VpcPeeringConnectionId = aws.String(s)
}

if s := m["network_interface_id"].(string); s != "" {
opts.NetworkInterfaceId = aws.String(s)
}

if s := m["instance_id"].(string); s != "" {
opts.InstanceId = aws.String(s)
}

if s := m["ipv6_cidr_block"].(string); s != "" {
opts.DestinationIpv6CidrBlock = aws.String(s)
}

if s := m["cidr_block"].(string); s != "" {
opts.DestinationCidrBlock = aws.String(s)
}

if m["nat_gateway_id"].(string) != "" {
opts.NatGatewayId = aws.String(m["nat_gateway_id"].(string))
if s := m["gateway_id"].(string); s != "" {
opts.GatewayId = aws.String(s)
}

if s := m["egress_only_gateway_id"].(string); s != "" {
opts.EgressOnlyInternetGatewayId = aws.String(s)
}

if s := m["nat_gateway_id"].(string); s != "" {
opts.NatGatewayId = aws.String(s)
}

log.Printf("[INFO] Creating route for %s: %#v", d.Id(), opts)
Expand Down Expand Up @@ -402,6 +454,10 @@ func resourceAwsRouteTableHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})

if v, ok := m["ipv6_cidr_block"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}

if v, ok := m["cidr_block"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
Expand All @@ -410,6 +466,10 @@ func resourceAwsRouteTableHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}

if v, ok := m["egress_only_gateway_id"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}

natGatewaySet := false
if v, ok := m["nat_gateway_id"]; ok {
natGatewaySet = v.(string) != ""
Expand Down
Loading