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

r/aws_route_table: AWS Wavelength support and 'arn' attribute #16979

Merged
merged 16 commits into from
Mar 26, 2021
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
11 changes: 11 additions & 0 deletions .changelog/16979.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-notes:enhancement
resource/aws_default_route_table: Add `arn` attribute
```

```release-notes:enhancement
resource/aws_route_table: Add `arn` attribute
```

```release-notes:enhancement
resource/aws_route_table: Add `carrier_gateway_id` attribute to `route` configuration block
```
5 changes: 5 additions & 0 deletions aws/resource_aws_default_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func resourceAwsDefaultRouteTable() *schema.Resource {

"tags": tagsSchema(),

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

"owner_id": {
Type: schema.TypeString,
Computed: true,
Expand Down
7 changes: 6 additions & 1 deletion aws/resource_aws_default_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestAccAWSDefaultRouteTable_basic(t *testing.T) {
Config: testAccDefaultRouteTableConfigBasic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists(resourceName, &routeTable),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`route-table/.+$`)),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "propagating_vgws.#", "0"),
resource.TestCheckResourceAttr(resourceName, "route.#", "0"),
Expand Down Expand Up @@ -100,6 +101,7 @@ func TestAccAWSDefaultRouteTable_Route_ConfigMode(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists(resourceName, &routeTable),
testAccCheckAWSRouteTableNumberOfRoutes(&routeTable, 2),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`route-table/.+$`)),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "propagating_vgws.#", "0"),
resource.TestCheckResourceAttr(resourceName, "route.#", "1"),
Expand All @@ -119,6 +121,7 @@ func TestAccAWSDefaultRouteTable_Route_ConfigMode(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists(resourceName, &routeTable),
testAccCheckAWSRouteTableNumberOfRoutes(&routeTable, 2),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`route-table/.+$`)),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "propagating_vgws.#", "0"),
// The route block from the previous step should still be
Expand All @@ -134,6 +137,7 @@ func TestAccAWSDefaultRouteTable_Route_ConfigMode(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists(resourceName, &routeTable),
testAccCheckAWSRouteTableNumberOfRoutes(&routeTable, 1),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`route-table/.+$`)),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "propagating_vgws.#", "0"),
// This config uses attribute syntax to set zero routes
Expand Down Expand Up @@ -168,6 +172,7 @@ func TestAccAWSDefaultRouteTable_swap(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists(resourceName, &routeTable),
testAccCheckAWSRouteTableNumberOfRoutes(&routeTable, 2),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`route-table/.+$`)),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "propagating_vgws.#", "0"),
resource.TestCheckResourceAttr(resourceName, "route.#", "1"),
Expand Down Expand Up @@ -256,7 +261,7 @@ func TestAccAWSDefaultRouteTable_IPv4_To_VpcEndpoint(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID),
ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID, "elasticloadbalancing"),
Providers: testAccProviders,
CheckDestroy: testAccCheckRouteTableDestroy,
Steps: []resource.TestStep{
Expand Down
52 changes: 45 additions & 7 deletions aws/resource_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -22,6 +23,7 @@ var routeTableValidDestinations = []string{
}

var routeTableValidTargets = []string{
"carrier_gateway_id",
"egress_only_gateway_id",
"gateway_id",
"instance_id",
Expand Down Expand Up @@ -67,6 +69,9 @@ func resourceAwsRouteTable() *schema.Resource {
ConfigMode: schema.SchemaConfigModeAttr,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
///
// Destinations.
///
"cidr_block": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -85,6 +90,14 @@ func resourceAwsRouteTable() *schema.Resource {
),
},

//
// Targets.
//
"carrier_gateway_id": {
Type: schema.TypeString,
Optional: true,
},

"egress_only_gateway_id": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -100,32 +113,32 @@ func resourceAwsRouteTable() *schema.Resource {
Optional: true,
},

"nat_gateway_id": {
"local_gateway_id": {
Type: schema.TypeString,
Optional: true,
},

"local_gateway_id": {
"nat_gateway_id": {
Type: schema.TypeString,
Optional: true,
},

"transit_gateway_id": {
"network_interface_id": {
Type: schema.TypeString,
Optional: true,
},

"vpc_endpoint_id": {
"transit_gateway_id": {
Type: schema.TypeString,
Optional: true,
},

"vpc_peering_connection_id": {
"vpc_endpoint_id": {
Type: schema.TypeString,
Optional: true,
},

"network_interface_id": {
"vpc_peering_connection_id": {
Type: schema.TypeString,
Optional: true,
},
Expand All @@ -134,6 +147,11 @@ func resourceAwsRouteTable() *schema.Resource {
Set: resourceAwsRouteTableHash,
},

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

"owner_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -231,6 +249,9 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
if r.DestinationIpv6CidrBlock != nil {
m["ipv6_cidr_block"] = aws.StringValue(r.DestinationIpv6CidrBlock)
}
if r.CarrierGatewayId != nil {
m["carrier_gateway_id"] = aws.StringValue(r.CarrierGatewayId)
}
if r.EgressOnlyInternetGatewayId != nil {
m["egress_only_gateway_id"] = aws.StringValue(r.EgressOnlyInternetGatewayId)
}
Expand Down Expand Up @@ -269,7 +290,16 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error setting tags: %w", err)
}

d.Set("owner_id", rt.OwnerId)
ownerID := aws.StringValue(rt.OwnerId)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #16978.

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: ec2.ServiceName,
Region: meta.(*AWSClient).region,
AccountID: ownerID,
Resource: fmt.Sprintf("route-table/%s", d.Id()),
}.String()
d.Set("arn", arn)
d.Set("owner_id", ownerID)

return nil
}
Expand Down Expand Up @@ -422,6 +452,10 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
opts.GatewayId = aws.String(s)
}

if s, ok := m["carrier_gateway_id"].(string); ok && s != "" {
opts.CarrierGatewayId = aws.String(s)
}

if s, ok := m["egress_only_gateway_id"].(string); ok && s != "" {
opts.EgressOnlyInternetGatewayId = aws.String(s)
}
Expand Down Expand Up @@ -559,6 +593,10 @@ func resourceAwsRouteTableHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}

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

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