From 1cd566e73c5f1fd65cba731c5b0bff7afd79e719 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Tue, 14 Mar 2017 12:39:08 +0200 Subject: [PATCH] provider/aws: Add support for IPv6 to aws_default_route_table (#12642) ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSDefaultRouteTable_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/03/13 10:57:45 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSDefaultRouteTable_ -timeout 120m === RUN TestAccAWSDefaultRouteTable_basic --- PASS: TestAccAWSDefaultRouteTable_basic (88.23s) === RUN TestAccAWSDefaultRouteTable_swap --- PASS: TestAccAWSDefaultRouteTable_swap (136.60s) === RUN TestAccAWSDefaultRouteTable_vpc_endpoint --- PASS: TestAccAWSDefaultRouteTable_vpc_endpoint (84.88s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 309.723s ``` --- .../aws/resource_aws_default_route_table.go | 73 +++++++++++++------ .../resource_aws_default_route_table_test.go | 8 +- .../aws/r/default_route_table.html.markdown | 2 + 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/builtin/providers/aws/resource_aws_default_route_table.go b/builtin/providers/aws/resource_aws_default_route_table.go index 78296cb1a..987dd4a7d 100644 --- a/builtin/providers/aws/resource_aws_default_route_table.go +++ b/builtin/providers/aws/resource_aws_default_route_table.go @@ -17,56 +17,66 @@ func resourceAwsDefaultRouteTable() *schema.Resource { Delete: resourceAwsDefaultRouteTableDelete, Schema: map[string]*schema.Schema{ - "default_route_table_id": &schema.Schema{ + "default_route_table_id": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "vpc_id": &schema.Schema{ + "vpc_id": { Type: schema.TypeString, Computed: true, }, - "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{ - Type: schema.TypeString, - Required: true, - }, - - "gateway_id": &schema.Schema{ + "cidr_block": { Type: schema.TypeString, Optional: true, }, - "instance_id": &schema.Schema{ + "ipv6_cidr_block": { Type: schema.TypeString, Optional: true, }, - "nat_gateway_id": &schema.Schema{ + "egress_only_gateway_id": { Type: schema.TypeString, Optional: true, }, - "vpc_peering_connection_id": &schema.Schema{ + "gateway_id": { Type: schema.TypeString, Optional: true, }, - "network_interface_id": &schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Optional: true, + }, + + "nat_gateway_id": { + Type: schema.TypeString, + Optional: true, + }, + + "vpc_peering_connection_id": { + Type: schema.TypeString, + Optional: true, + }, + + "network_interface_id": { Type: schema.TypeString, Optional: true, }, @@ -193,16 +203,33 @@ func revokeAllRouteTableRules(defaultRouteTableId string, meta interface{}) erro // See aws_vpc_endpoint continue } - log.Printf( - "[INFO] Deleting route from %s: %s", - defaultRouteTableId, *r.DestinationCidrBlock) - _, err := conn.DeleteRoute(&ec2.DeleteRouteInput{ - RouteTableId: aws.String(defaultRouteTableId), - DestinationCidrBlock: r.DestinationCidrBlock, - }) - if err != nil { - return err + + if r.DestinationCidrBlock != nil { + log.Printf( + "[INFO] Deleting route from %s: %s", + defaultRouteTableId, *r.DestinationCidrBlock) + _, err := conn.DeleteRoute(&ec2.DeleteRouteInput{ + RouteTableId: aws.String(defaultRouteTableId), + DestinationCidrBlock: r.DestinationCidrBlock, + }) + if err != nil { + return err + } } + + if r.DestinationIpv6CidrBlock != nil { + log.Printf( + "[INFO] Deleting route from %s: %s", + defaultRouteTableId, *r.DestinationIpv6CidrBlock) + _, err := conn.DeleteRoute(&ec2.DeleteRouteInput{ + RouteTableId: aws.String(defaultRouteTableId), + DestinationIpv6CidrBlock: r.DestinationIpv6CidrBlock, + }) + if err != nil { + return err + } + } + } return nil diff --git a/builtin/providers/aws/resource_aws_default_route_table_test.go b/builtin/providers/aws/resource_aws_default_route_table_test.go index c3feabf9f..dd67db0ff 100644 --- a/builtin/providers/aws/resource_aws_default_route_table_test.go +++ b/builtin/providers/aws/resource_aws_default_route_table_test.go @@ -20,7 +20,7 @@ func TestAccAWSDefaultRouteTable_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckDefaultRouteTableDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccDefaultRouteTableConfig, Check: resource.ComposeTestCheckFunc( testAccCheckRouteTableExists( @@ -40,7 +40,7 @@ func TestAccAWSDefaultRouteTable_swap(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckDefaultRouteTableDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccDefaultRouteTable_change, Check: resource.ComposeTestCheckFunc( testAccCheckRouteTableExists( @@ -53,7 +53,7 @@ func TestAccAWSDefaultRouteTable_swap(t *testing.T) { // behavior that may happen, in which case a follow up plan will show (in // this case) a diff as the table now needs to be updated to match the // config - resource.TestStep{ + { Config: testAccDefaultRouteTable_change_mod, Check: resource.ComposeTestCheckFunc( testAccCheckRouteTableExists( @@ -74,7 +74,7 @@ func TestAccAWSDefaultRouteTable_vpc_endpoint(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckDefaultRouteTableDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccDefaultRouteTable_vpc_endpoint, Check: resource.ComposeTestCheckFunc( testAccCheckRouteTableExists( diff --git a/website/source/docs/providers/aws/r/default_route_table.html.markdown b/website/source/docs/providers/aws/r/default_route_table.html.markdown index 8efb28446..4ef364ea2 100644 --- a/website/source/docs/providers/aws/r/default_route_table.html.markdown +++ b/website/source/docs/providers/aws/r/default_route_table.html.markdown @@ -68,6 +68,8 @@ The following arguments are supported: Each route supports the following: * `cidr_block` - (Required) The CIDR block of the route. +* `ipv6_cidr_block` - Optional) The Ipv6 CIDR block of the route +* `egress_only_gateway_id` - (Optional) The Egress Only Internet Gateway ID. * `gateway_id` - (Optional) The Internet Gateway ID. * `nat_gateway_id` - (Optional) The NAT Gateway ID. * `instance_id` - (Optional) The EC2 instance ID.