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

rd/transit_gateway_route_table - add arn + refactor disappears #13921

Merged
merged 4 commits into from
Nov 12, 2020
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
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/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 @@ -23,6 +23,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 @@ -45,6 +46,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/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/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 @@ -252,6 +252,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