diff --git a/.changelog/31877.txt b/.changelog/31877.txt new file mode 100644 index 00000000000..66f22e89b40 --- /dev/null +++ b/.changelog/31877.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_vpc: Fix `reading EC2 VPC (vpc-abcd1234) Attribute (enableDnsSupport): couldn't find resource` errors when reading new resource +``` \ No newline at end of file diff --git a/internal/service/ec2/vpc_.go b/internal/service/ec2/vpc_.go index a292348bf88..3222454a68c 100644 --- a/internal/service/ec2/vpc_.go +++ b/internal/service/ec2/vpc_.go @@ -285,19 +285,25 @@ func resourceVPCRead(ctx context.Context, d *schema.ResourceData, meta interface d.Set("instance_tenancy", vpc.InstanceTenancy) d.Set("owner_id", ownerID) - if v, err := FindVPCAttribute(ctx, conn, d.Id(), ec2.VpcAttributeNameEnableDnsHostnames); err != nil { + if v, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (interface{}, error) { + return FindVPCAttribute(ctx, conn, d.Id(), ec2.VpcAttributeNameEnableDnsHostnames) + }, d.IsNewResource()); err != nil { return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), ec2.VpcAttributeNameEnableDnsHostnames, err) } else { d.Set("enable_dns_hostnames", v) } - if v, err := FindVPCAttribute(ctx, conn, d.Id(), ec2.VpcAttributeNameEnableDnsSupport); err != nil { + if v, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (interface{}, error) { + return FindVPCAttribute(ctx, conn, d.Id(), ec2.VpcAttributeNameEnableDnsSupport) + }, d.IsNewResource()); err != nil { return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), ec2.VpcAttributeNameEnableDnsSupport, err) } else { d.Set("enable_dns_support", v) } - if v, err := FindVPCAttribute(ctx, conn, d.Id(), ec2.VpcAttributeNameEnableNetworkAddressUsageMetrics); err != nil { + if v, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (interface{}, error) { + return FindVPCAttribute(ctx, conn, d.Id(), ec2.VpcAttributeNameEnableNetworkAddressUsageMetrics) + }, d.IsNewResource()); err != nil { return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) Attribute (%s): %s", d.Id(), ec2.VpcAttributeNameEnableNetworkAddressUsageMetrics, err) } else { d.Set("enable_network_address_usage_metrics", v)