Skip to content

Commit

Permalink
service/ec2: rd/transit_gateway_route_table - add arn + refactor disa…
Browse files Browse the repository at this point in the history
…ppears (#13921)

* add arn + refactor disappears for tgw route table

* add arn + refactor disappears for tgw route table

* add arn + refactor disappears for tgw route table

* datasource arn
  • Loading branch information
DrFaust92 authored Nov 12, 2020
1 parent b88da45 commit 0849a91
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 19 deletions.
15 changes: 15 additions & 0 deletions aws/data_source_aws_ec2_transit_gateway_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"

"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/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
Expand All @@ -16,6 +17,10 @@ func dataSourceAwsEc2TransitGatewayRouteTable() *schema.Resource {
Read: dataSourceAwsEc2TransitGatewayRouteTableRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"default_association_route_table": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -84,5 +89,15 @@ func dataSourceAwsEc2TransitGatewayRouteTableRead(d *schema.ResourceData, meta i

d.SetId(aws.StringValue(transitGatewayRouteTable.TransitGatewayRouteTableId))

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

d.Set("arn", arn)

return nil
}
2 changes: 2 additions & 0 deletions aws/data_source_aws_ec2_transit_gateway_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestAccAWSEc2TransitGatewayRouteTableDataSource_Filter(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "default_propagation_route_table", dataSourceName, "default_propagation_route_table"),
resource.TestCheckResourceAttrPair(resourceName, "tags.%", dataSourceName, "tags.%"),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", dataSourceName, "transit_gateway_id"),
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
),
},
},
Expand All @@ -44,6 +45,7 @@ func TestAccAWSEc2TransitGatewayRouteTableDataSource_ID(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "default_propagation_route_table", dataSourceName, "default_propagation_route_table"),
resource.TestCheckResourceAttrPair(resourceName, "tags.%", dataSourceName, "tags.%"),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", dataSourceName, "transit_gateway_id"),
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
),
},
},
Expand Down
15 changes: 15 additions & 0 deletions aws/resource_aws_ec2_transit_gateway_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"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/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand All @@ -22,6 +23,10 @@ func resourceAwsEc2TransitGatewayRouteTable() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"default_association_route_table": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -101,6 +106,16 @@ func resourceAwsEc2TransitGatewayRouteTableRead(d *schema.ResourceData, meta int

d.Set("transit_gateway_id", aws.StringValue(transitGatewayRouteTable.TransitGatewayId))

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

d.Set("arn", arn)

return nil
}

Expand Down
22 changes: 3 additions & 19 deletions aws/resource_aws_ec2_transit_gateway_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"errors"
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -25,6 +26,7 @@ func TestAccAWSEc2TransitGatewayRouteTable_basic(t *testing.T) {
Config: testAccAWSEc2TransitGatewayRouteTableConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TransitGatewayRouteTableExists(resourceName, &transitGatewayRouteTable1),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`transit-gateway-route-table/tgw-rtb-.+`)),
resource.TestCheckResourceAttr(resourceName, "default_association_route_table", "false"),
resource.TestCheckResourceAttr(resourceName, "default_propagation_route_table", "false"),
resource.TestCheckResourceAttrPair(resourceName, "transit_gateway_id", transitGatewayResourceName, "id"),
Expand Down Expand Up @@ -53,7 +55,7 @@ func TestAccAWSEc2TransitGatewayRouteTable_disappears(t *testing.T) {
Config: testAccAWSEc2TransitGatewayRouteTableConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TransitGatewayRouteTableExists(resourceName, &transitGatewayRouteTable1),
testAccCheckAWSEc2TransitGatewayRouteTableDisappears(&transitGatewayRouteTable1),
testAccCheckResourceDisappears(testAccProvider, resourceAwsEc2TransitGatewayRouteTable(), resourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down Expand Up @@ -193,24 +195,6 @@ func testAccCheckAWSEc2TransitGatewayRouteTableDestroy(s *terraform.State) error
return nil
}

func testAccCheckAWSEc2TransitGatewayRouteTableDisappears(transitGatewayRouteTable *ec2.TransitGatewayRouteTable) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn

input := &ec2.DeleteTransitGatewayRouteTableInput{
TransitGatewayRouteTableId: transitGatewayRouteTable.TransitGatewayRouteTableId,
}

_, err := conn.DeleteTransitGatewayRouteTable(input)

if err != nil {
return err
}

return waitForEc2TransitGatewayRouteTableDeletion(conn, aws.StringValue(transitGatewayRouteTable.TransitGatewayRouteTableId))
}
}

func testAccCheckAWSEc2TransitGatewayRouteTableNotRecreated(i, j *ec2.TransitGatewayRouteTable) resource.TestCheckFunc {
return func(s *terraform.State) error {
if aws.StringValue(i.TransitGatewayRouteTableId) != aws.StringValue(j.TransitGatewayRouteTableId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The following arguments are supported:

In addition to all arguments above, the following attributes are exported:

* `arn` - EC2 Transit Gateway Route Table Amazon Resource Name (ARN).
* `default_association_route_table` - Boolean whether this is the default association route table for the EC2 Transit Gateway
* `default_propagation_route_table` - Boolean whether this is the default propagation route table for the EC2 Transit Gateway
* `id` - EC2 Transit Gateway Route Table identifier
Expand Down
2 changes: 2 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ for more information about connecting to alternate AWS endpoints or AWS compatib
- [`aws_ec2_client_vpn_endpoint` resource](/docs/providers/aws/r/ec2_client_vpn_endpoint.html)
- [`aws_ec2_traffic_mirror_session` resource](/docs/providers/aws/r/ec2_traffic_mirror_session.html)
- [`aws_ec2_traffic_mirror_target` resource](/docs/providers/aws/r/ec2_traffic_mirror_target.html)
- [`aws_ec2_transit_gateway_route_table` data source](/docs/providers/aws/d/ec2_transit_gateway_route_table.html)
- [`aws_ec2_transit_gateway_route_table` resource](/docs/providers/aws/r/ec2_transit_gateway_route_table.html)
- [`aws_ecs_capacity_provider` resource (import)](/docs/providers/aws/r/ecs_capacity_provider.html)
- [`aws_ecs_cluster` resource (import)](/docs/providers/aws/r/ecs_cluster.html)
- [`aws_ecs_service` resource (import)](/docs/providers/aws/r/ecs_service.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following arguments are supported:

In addition to all arguments above, the following attributes are exported:

* `arn` - EC2 Transit Gateway Route Table Amazon Resource Name (ARN).
* `default_association_route_table` - Boolean whether this is the default association route table for the EC2 Transit Gateway.
* `default_propagation_route_table` - Boolean whether this is the default propagation route table for the EC2 Transit Gateway.
* `id` - EC2 Transit Gateway Route Table identifier
Expand Down

0 comments on commit 0849a91

Please sign in to comment.