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: Call SetId before WaitRouteReady #24024

Merged
merged 13 commits into from
Apr 5, 2022
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
27 changes: 27 additions & 0 deletions .changelog/24024.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
```release-note:bug
resource/aws_route: Ensure that resource ID is set in case of wait-for-creation time out
```

```release-note:enhancement
resource/aws_route: Add `core_network_arn` argument
```

```release-note:enhancement
data-source/aws_route: Add `core_network_arn` argument
```

```release-note:enhancement
resource/aws_route_table: Add `core_network_arn` argument to the `route` configuration block
```

```release-note:enhancement
data-source/aws_route_table: Add 'routes.core_network_arn' attribute'
```

```release-note:enhancement
resource/aws_default_route_table: Add `core_network_arn` argument to the `route` configuration block
```

```release-note:enhancement
resource/aws_vpn_connection: Add `core_network_arn` and `core_network_attachment_arn` attributes
```
4 changes: 4 additions & 0 deletions internal/service/ec2/default_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func ResourceDefaultRouteTable() *schema.Resource {
// These target attributes are a subset of the aws_route_table resource's target attributes
// as there are some targets that are not allowed in the default route table for a VPC.
//
"core_network_arn": {
Type: schema.TypeString,
Optional: true,
},
"egress_only_gateway_id": {
Type: schema.TypeString,
Optional: true,
Expand Down
15 changes: 13 additions & 2 deletions internal/service/ec2/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var routeValidDestinations = []string{

var routeValidTargets = []string{
"carrier_gateway_id",
"core_network_arn",
"egress_only_gateway_id",
"gateway_id",
"instance_id",
Expand Down Expand Up @@ -91,6 +92,11 @@ func ResourceRoute() *schema.Resource {
ExactlyOneOf: routeValidTargets,
ConflictsWith: []string{"destination_ipv6_cidr_block"}, // IPv4 destinations only.
},
"core_network_arn": {
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: routeValidTargets,
},
"egress_only_gateway_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -203,6 +209,8 @@ func resourceRouteCreate(d *schema.ResourceData, meta interface{}) error {
switch target := aws.String(target); targetAttributeKey {
case "carrier_gateway_id":
input.CarrierGatewayId = target
case "core_network_arn":
input.CoreNetworkArn = target
case "egress_only_gateway_id":
input.EgressOnlyInternetGatewayId = target
case "gateway_id":
Expand Down Expand Up @@ -239,14 +247,14 @@ func resourceRouteCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error creating Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err)
}

d.SetId(RouteCreateID(routeTableID, destination))

_, err = WaitRouteReady(conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutCreate))

if err != nil {
return fmt.Errorf("error waiting for Route in Route Table (%s) with destination (%s) to become available: %w", routeTableID, destination, err)
}

d.SetId(RouteCreateID(routeTableID, destination))

return resourceRouteRead(d, meta)
}

Expand Down Expand Up @@ -287,6 +295,7 @@ func resourceRouteRead(d *schema.ResourceData, meta interface{}) error {
}

d.Set("carrier_gateway_id", route.CarrierGatewayId)
d.Set("core_network_arn", route.CoreNetworkArn)
d.Set("destination_cidr_block", route.DestinationCidrBlock)
d.Set("destination_ipv6_cidr_block", route.DestinationIpv6CidrBlock)
d.Set("destination_prefix_list_id", route.DestinationPrefixListId)
Expand Down Expand Up @@ -351,6 +360,8 @@ func resourceRouteUpdate(d *schema.ResourceData, meta interface{}) error {
switch target := aws.String(target); targetAttributeKey {
case "carrier_gateway_id":
input.CarrierGatewayId = target
case "core_network_arn":
input.CoreNetworkArn = target
case "egress_only_gateway_id":
input.EgressOnlyInternetGatewayId = target
case "gateway_id":
Expand Down
11 changes: 10 additions & 1 deletion internal/service/ec2/route_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func DataSourceRoute() *schema.Resource {
Optional: true,
Computed: true,
},

"destination_prefix_list_id": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -48,6 +47,11 @@ func DataSourceRoute() *schema.Resource {
Optional: true,
Computed: true,
},
"core_network_arn": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"egress_only_gateway_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -132,6 +136,10 @@ func dataSourceRouteRead(d *schema.ResourceData, meta interface{}) error {
continue
}

if v, ok := d.GetOk("core_network_arn"); ok && aws.StringValue(r.CoreNetworkArn) != v.(string) {
continue
}

if v, ok := d.GetOk("egress_only_gateway_id"); ok && aws.StringValue(r.EgressOnlyInternetGatewayId) != v.(string) {
continue
}
Expand Down Expand Up @@ -186,6 +194,7 @@ func dataSourceRouteRead(d *schema.ResourceData, meta interface{}) error {
}

d.Set("carrier_gateway_id", route.CarrierGatewayId)
d.Set("core_network_arn", route.CoreNetworkArn)
d.Set("destination_cidr_block", route.DestinationCidrBlock)
d.Set("destination_ipv6_cidr_block", route.DestinationIpv6CidrBlock)
d.Set("destination_prefix_list_id", route.DestinationPrefixListId)
Expand Down
21 changes: 21 additions & 0 deletions internal/service/ec2/route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var routeTableValidDestinations = []string{

var routeTableValidTargets = []string{
"carrier_gateway_id",
"core_network_arn",
"egress_only_gateway_id",
"gateway_id",
"instance_id",
Expand Down Expand Up @@ -105,6 +106,10 @@ func ResourceRouteTable() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"core_network_arn": {
Type: schema.TypeString,
Optional: true,
},
"egress_only_gateway_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -429,6 +434,10 @@ func resourceRouteTableHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}

if v, ok := m["core_network_arn"]; 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 Expand Up @@ -681,6 +690,10 @@ func expandEc2CreateRouteInput(tfMap map[string]interface{}) *ec2.CreateRouteInp
apiObject.CarrierGatewayId = aws.String(v)
}

if v, ok := tfMap["core_network_arn"].(string); ok && v != "" {
apiObject.CoreNetworkArn = aws.String(v)
}

if v, ok := tfMap["egress_only_gateway_id"].(string); ok && v != "" {
apiObject.EgressOnlyInternetGatewayId = aws.String(v)
}
Expand Down Expand Up @@ -743,6 +756,10 @@ func expandEc2ReplaceRouteInput(tfMap map[string]interface{}) *ec2.ReplaceRouteI
apiObject.CarrierGatewayId = aws.String(v)
}

if v, ok := tfMap["core_network_arn"].(string); ok && v != "" {
apiObject.CoreNetworkArn = aws.String(v)
}

if v, ok := tfMap["egress_only_gateway_id"].(string); ok && v != "" {
apiObject.EgressOnlyInternetGatewayId = aws.String(v)
}
Expand Down Expand Up @@ -805,6 +822,10 @@ func flattenEc2Route(apiObject *ec2.Route) map[string]interface{} {
tfMap["carrier_gateway_id"] = aws.StringValue(v)
}

if v := apiObject.CoreNetworkArn; v != nil {
tfMap["core_network_arn"] = aws.StringValue(v)
}

if v := apiObject.EgressOnlyInternetGatewayId; v != nil {
tfMap["egress_only_gateway_id"] = aws.StringValue(v)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/service/ec2/route_table_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func DataSourceRouteTable() *schema.Resource {
Computed: true,
},

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

"egress_only_gateway_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -285,6 +290,9 @@ func dataSourceRoutesRead(conn *ec2.EC2, ec2Routes []*ec2.Route) []map[string]in
if r.CarrierGatewayId != nil {
m["carrier_gateway_id"] = *r.CarrierGatewayId
}
if r.CoreNetworkArn != nil {
m["core_network_arn"] = *r.CoreNetworkArn
}
if r.EgressOnlyInternetGatewayId != nil {
m["egress_only_gateway_id"] = *r.EgressOnlyInternetGatewayId
}
Expand Down
Loading