@@ -301,7 +301,9 @@ func resourceVPCRead(ctx context.Context, d *schema.ResourceData, meta any) diag
301301 return sdkdiag .AppendErrorf (diags , "reading EC2 VPC (%s): %s" , d .Id (), err )
302302 }
303303
304- diags = append (diags , resourceVPCFlatten (ctx , c , vpc , d )... )
304+ if err := resourceVPCFlatten (ctx , c , vpc , d ); err != nil {
305+ diags = sdkdiag .AppendFromErr (diags , err )
306+ }
305307
306308 return diags
307309}
@@ -652,9 +654,7 @@ func modifyVPCTenancy(ctx context.Context, conn *ec2.Client, vpcID string, v str
652654 return nil
653655}
654656
655- func resourceVPCFlatten (ctx context.Context , client * conns.AWSClient , vpc * awstypes.Vpc , d * schema.ResourceData ) diag.Diagnostics {
656- var diags diag.Diagnostics
657-
657+ func resourceVPCFlatten (ctx context.Context , client * conns.AWSClient , vpc * awstypes.Vpc , d * schema.ResourceData ) error {
658658 conn := client .EC2Client (ctx )
659659 ownerID := aws .ToString (vpc .OwnerId )
660660 d .Set (names .AttrARN , vpcARN (ctx , client , ownerID , d .Id ()))
@@ -666,45 +666,42 @@ func resourceVPCFlatten(ctx context.Context, client *conns.AWSClient, vpc *awsty
666666 if v , err := tfresource .RetryWhenNewResourceNotFound (ctx , ec2PropagationTimeout , func (ctx context.Context ) (bool , error ) {
667667 return findVPCAttribute (ctx , conn , d .Id (), awstypes .VpcAttributeNameEnableDnsHostnames )
668668 }, d .IsNewResource ()); err != nil {
669- return sdkdiag . AppendErrorf ( diags , "reading EC2 VPC (%s) Attribute (%s): %s " , d .Id (), awstypes .VpcAttributeNameEnableDnsHostnames , err )
669+ return fmt . Errorf ( "reading EC2 VPC (%s) Attribute (%s): %w " , d .Id (), awstypes .VpcAttributeNameEnableDnsHostnames , err )
670670 } else {
671671 d .Set ("enable_dns_hostnames" , v )
672672 }
673673
674674 if v , err := tfresource .RetryWhenNewResourceNotFound (ctx , ec2PropagationTimeout , func (ctx context.Context ) (bool , error ) {
675675 return findVPCAttribute (ctx , conn , d .Id (), awstypes .VpcAttributeNameEnableDnsSupport )
676676 }, d .IsNewResource ()); err != nil {
677- return sdkdiag . AppendErrorf ( diags , "reading EC2 VPC (%s) Attribute (%s): %s " , d .Id (), awstypes .VpcAttributeNameEnableDnsSupport , err )
677+ return fmt . Errorf ( "reading EC2 VPC (%s) Attribute (%s): %w " , d .Id (), awstypes .VpcAttributeNameEnableDnsSupport , err )
678678 } else {
679679 d .Set ("enable_dns_support" , v )
680680 }
681681
682682 if v , err := tfresource .RetryWhenNewResourceNotFound (ctx , ec2PropagationTimeout , func (ctx context.Context ) (bool , error ) {
683683 return findVPCAttribute (ctx , conn , d .Id (), awstypes .VpcAttributeNameEnableNetworkAddressUsageMetrics )
684684 }, d .IsNewResource ()); err != nil {
685- return sdkdiag . AppendErrorf ( diags , "reading EC2 VPC (%s) Attribute (%s): %s " , d .Id (), awstypes .VpcAttributeNameEnableNetworkAddressUsageMetrics , err )
685+ return fmt . Errorf ( "reading EC2 VPC (%s) Attribute (%s): %w " , d .Id (), awstypes .VpcAttributeNameEnableNetworkAddressUsageMetrics , err )
686686 } else {
687687 d .Set ("enable_network_address_usage_metrics" , v )
688688 }
689689
690690 if v , err := findVPCDefaultNetworkACL (ctx , conn , d .Id ()); err != nil {
691- log . Printf ( "[WARN] Error reading EC2 VPC (%s) default NACL: %s " , d .Id (), err )
691+ return fmt . Errorf ( " reading EC2 VPC (%s) default NACL: %w " , d .Id (), err )
692692 } else {
693693 d .Set ("default_network_acl_id" , v .NetworkAclId )
694694 }
695695
696696 if v , err := findVPCMainRouteTable (ctx , conn , d .Id ()); err != nil {
697- log .Printf ("[WARN] Error reading EC2 VPC (%s) main Route Table: %s" , d .Id (), err )
698- d .Set ("default_route_table_id" , nil )
699- d .Set ("main_route_table_id" , nil )
697+ return fmt .Errorf ("reading EC2 VPC (%s) main Route Table: %w" , d .Id (), err )
700698 } else {
701699 d .Set ("default_route_table_id" , v .RouteTableId )
702700 d .Set ("main_route_table_id" , v .RouteTableId )
703701 }
704702
705703 if v , err := findVPCDefaultSecurityGroup (ctx , conn , d .Id ()); err != nil {
706- log .Printf ("[WARN] Error reading EC2 VPC (%s) default Security Group: %s" , d .Id (), err )
707- d .Set ("default_security_group_id" , nil )
704+ return fmt .Errorf ("reading EC2 VPC (%s) default Security Group: %w" , d .Id (), err )
708705 } else {
709706 d .Set ("default_security_group_id" , v .GroupId )
710707 }
@@ -750,7 +747,7 @@ func resourceVPCFlatten(ctx context.Context, client *conns.AWSClient, vpc *awsty
750747
751748 setTagsOut (ctx , vpc .Tags )
752749
753- return diags
750+ return nil
754751}
755752
756753func vpcARN (ctx context.Context , c * conns.AWSClient , accountID , vpcID string ) string {
@@ -871,8 +868,13 @@ func (l *vpcListResource) List(ctx context.Context, request list.ListRequest, st
871868
872869 rd := l .ResourceData ()
873870 rd .SetId (aws .ToString (vpc .VpcId ))
874- result .Diagnostics .Append (translateDiags (resourceVPCFlatten (ctx , awsClient , & vpc , rd ))... )
875- if result .Diagnostics .HasError () {
871+ err := resourceVPCFlatten (ctx , awsClient , & vpc , rd )
872+ if retry .NotFound (err ) {
873+ tflog .Warn (ctx , "Resource disappeared during listing, skipping" )
874+ continue
875+ }
876+ if err != nil {
877+ result = fwdiag .NewListResultErrorDiagnostic (err )
876878 yield (result )
877879 return
878880 }
0 commit comments