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

aws_vpc: Don't propagate errors from FindVPCMainRouteTable et al. #22724

Merged
merged 3 commits into from
Jan 22, 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
7 changes: 7 additions & 0 deletions .changelog/22724.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_vpc: Suppress errors if main route table, default NACL or default security group cannot be found
```

```release-note:bug
data-source/aws_vpc: Suppress errors if main route table cannot be found
```
35 changes: 16 additions & 19 deletions internal/service/ec2/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,31 +313,28 @@ func resourceVPCRead(d *schema.ResourceData, meta interface{}) error {
d.Set("enable_dns_support", v)
}

nacl, err := FindVPCDefaultNetworkACL(conn, d.Id())

if err != nil {
return fmt.Errorf("error reading EC2 VPC (%s) default NACL: %w", d.Id(), err)
if v, err := FindVPCDefaultNetworkACL(conn, d.Id()); err != nil {
log.Printf("[WARN] Error reading EC2 VPC (%s) default NACL: %s", d.Id(), err)
} else {
d.Set("default_network_acl_id", v.NetworkAclId)
}

d.Set("default_network_acl_id", nacl.NetworkAclId)

routeTable, err := FindVPCMainRouteTable(conn, d.Id())

if err != nil {
return fmt.Errorf("error reading EC2 VPC (%s) main Route Table: %w", d.Id(), err)
if v, err := FindVPCMainRouteTable(conn, d.Id()); err != nil {
log.Printf("[WARN] Error reading EC2 VPC (%s) main Route Table: %s", d.Id(), err)
d.Set("default_route_table_id", nil)
d.Set("main_route_table_id", nil)
} else {
d.Set("default_route_table_id", v.RouteTableId)
d.Set("main_route_table_id", v.RouteTableId)
}

d.Set("default_route_table_id", routeTable.RouteTableId)
d.Set("main_route_table_id", routeTable.RouteTableId)

securityGroup, err := FindVPCDefaultSecurityGroup(conn, d.Id())

if err != nil {
return fmt.Errorf("error reading EC2 VPC (%s) default Security Group: %w", d.Id(), err)
if v, err := FindVPCDefaultSecurityGroup(conn, d.Id()); err != nil {
log.Printf("[WARN] Error reading EC2 VPC (%s) default Security Group: %s", d.Id(), err)
d.Set("default_security_group_id", nil)
} else {
d.Set("default_security_group_id", v.GroupId)
}

d.Set("default_security_group_id", securityGroup.GroupId)

d.Set("assign_generated_ipv6_cidr_block", nil)
d.Set("ipv6_cidr_block", nil)
d.Set("ipv6_cidr_block_network_border_group", nil)
Expand Down
12 changes: 6 additions & 6 deletions internal/service/ec2/vpc_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ec2

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
Expand Down Expand Up @@ -177,14 +178,13 @@ func dataSourceVPCRead(d *schema.ResourceData, meta interface{}) error {
d.Set("enable_dns_support", v)
}

routeTable, err := FindVPCMainRouteTable(conn, d.Id())

if err != nil {
return fmt.Errorf("error reading EC2 VPC (%s) main Route Table: %w", d.Id(), err)
if v, err := FindVPCMainRouteTable(conn, d.Id()); err != nil {
log.Printf("[WARN] Error reading EC2 VPC (%s) main Route Table: %s", d.Id(), err)
d.Set("main_route_table_id", nil)
} else {
d.Set("main_route_table_id", v.RouteTableId)
}

d.Set("main_route_table_id", routeTable.RouteTableId)

cidrAssociations := []interface{}{}
for _, v := range vpc.CidrBlockAssociationSet {
association := map[string]interface{}{
Expand Down