From 2a790cbfca9b7d1b8b4e8f4901ab10f343ff052f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 15:34:44 -0400 Subject: [PATCH 01/12] r/aws_ec2_network_insights_path: Fix correct attribute name. --- internal/service/ec2/vpc_network_insights_analysis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/ec2/vpc_network_insights_analysis.go b/internal/service/ec2/vpc_network_insights_analysis.go index 8a1b28cb443b..5b974be44f02 100644 --- a/internal/service/ec2/vpc_network_insights_analysis.go +++ b/internal/service/ec2/vpc_network_insights_analysis.go @@ -2170,7 +2170,7 @@ func flattenTransitGatewayRouteTableRoute(apiObject *ec2.TransitGatewayRouteTabl } if v := apiObject.RouteOrigin; v != nil { - tfMap["route_orign"] = aws.StringValue(v) + tfMap["route_origin"] = aws.StringValue(v) } if v := apiObject.State; v != nil { From 3c698a7aea42ec0d0475fe335bd3c7801f018f5f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 15:36:28 -0400 Subject: [PATCH 02/12] Add CHANGELOG entry. --- .changelog/#####.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/#####.txt diff --git a/.changelog/#####.txt b/.changelog/#####.txt new file mode 100644 index 000000000000..b2dc222b4c5c --- /dev/null +++ b/.changelog/#####.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ec2_network_insights_analysis: Fix `setting forward_path_components: Invalid address to set` errors +``` \ No newline at end of file From d22db811dea39934a09e9fe8bda5feeb240db850 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 16:17:59 -0400 Subject: [PATCH 03/12] r/aws_ec2_network_insights_path: Add 'destination_arn' and 'source_arn' attributes. --- .changelog/#####.txt | 4 ++ .../service/ec2/vpc_network_insights_path.go | 11 +++- .../ec2/vpc_network_insights_path_test.go | 52 +++++++++++++++++++ .../r/ec2_network_insights_path.html.markdown | 6 ++- 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/.changelog/#####.txt b/.changelog/#####.txt index b2dc222b4c5c..1b48d657ddf6 100644 --- a/.changelog/#####.txt +++ b/.changelog/#####.txt @@ -1,3 +1,7 @@ ```release-note:bug resource/aws_ec2_network_insights_analysis: Fix `setting forward_path_components: Invalid address to set` errors +``` + +```release-note:enhancement +resource/aws_ec2_network_insights_path: Add `destination_arn` and `source_arn` attributes ``` \ No newline at end of file diff --git a/internal/service/ec2/vpc_network_insights_path.go b/internal/service/ec2/vpc_network_insights_path.go index f6a5130dda05..91b4a3ea4de7 100644 --- a/internal/service/ec2/vpc_network_insights_path.go +++ b/internal/service/ec2/vpc_network_insights_path.go @@ -38,6 +38,10 @@ func ResourceNetworkInsightsPath() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "destination_arn": { + Type: schema.TypeString, + Computed: true, + }, "destination": { Type: schema.TypeString, Required: true, @@ -64,6 +68,10 @@ func ResourceNetworkInsightsPath() *schema.Resource { Required: true, ForceNew: true, }, + "source_arn": { + Type: schema.TypeString, + Computed: true, + }, "source_ip": { Type: schema.TypeString, Optional: true, @@ -99,7 +107,6 @@ func resourceNetworkInsightsPathCreate(ctx context.Context, d *schema.ResourceDa input.SourceIp = aws.String(v.(string)) } - log.Printf("[DEBUG] Creating EC2 Network Insights Path: %s", input) output, err := conn.CreateNetworkInsightsPathWithContext(ctx, input) if err != nil { @@ -128,10 +135,12 @@ func resourceNetworkInsightsPathRead(ctx context.Context, d *schema.ResourceData d.Set("arn", nip.NetworkInsightsPathArn) d.Set("destination", nip.Destination) + d.Set("destination_arn", nip.DestinationArn) d.Set("destination_ip", nip.DestinationIp) d.Set("destination_port", nip.DestinationPort) d.Set("protocol", nip.Protocol) d.Set("source", nip.Source) + d.Set("source_arn", nip.SourceArn) d.Set("source_ip", nip.SourceIp) setTagsOut(ctx, nip.Tags) diff --git a/internal/service/ec2/vpc_network_insights_path_test.go b/internal/service/ec2/vpc_network_insights_path_test.go index 481d21d5b2fe..4effba77d57f 100644 --- a/internal/service/ec2/vpc_network_insights_path_test.go +++ b/internal/service/ec2/vpc_network_insights_path_test.go @@ -36,10 +36,12 @@ func TestAccVPCNetworkInsightsPath_basic(t *testing.T) { testAccCheckNetworkInsightsPathExists(ctx, resourceName), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexache.MustCompile(`network-insights-path/.+$`)), resource.TestCheckResourceAttrPair(resourceName, "destination", "aws_network_interface.test.1", "id"), + resource.TestCheckResourceAttrPair(resourceName, "destination_arn", "aws_network_interface.test.1", "arn"), resource.TestCheckResourceAttr(resourceName, "destination_ip", ""), resource.TestCheckResourceAttr(resourceName, "destination_port", "0"), resource.TestCheckResourceAttr(resourceName, "protocol", "tcp"), resource.TestCheckResourceAttrPair(resourceName, "source", "aws_network_interface.test.0", "id"), + resource.TestCheckResourceAttrPair(resourceName, "source_arn", "aws_network_interface.test.0", "arn"), resource.TestCheckResourceAttr(resourceName, "source_ip", ""), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), ), @@ -121,6 +123,36 @@ func TestAccVPCNetworkInsightsPath_tags(t *testing.T) { }) } +func TestAccVPCNetworkInsightsPath_sourceAndDestinationARN(t *testing.T) { + ctx := acctest.Context(t) + resourceName := "aws_ec2_network_insights_path.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckNetworkInsightsPathDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccVPCNetworkInsightsPathConfig_sourceAndDestinationARN(rName, "tcp"), + Check: resource.ComposeTestCheckFunc( + testAccCheckNetworkInsightsPathExists(ctx, resourceName), + resource.TestCheckResourceAttrPair(resourceName, "destination", "aws_network_interface.test.1", "id"), + resource.TestCheckResourceAttrPair(resourceName, "destination_arn", "aws_network_interface.test.1", "arn"), + resource.TestCheckResourceAttrPair(resourceName, "source", "aws_network_interface.test.0", "id"), + resource.TestCheckResourceAttrPair(resourceName, "source_arn", "aws_network_interface.test.0", "arn"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccVPCNetworkInsightsPath_sourceIP(t *testing.T) { ctx := acctest.Context(t) resourceName := "aws_ec2_network_insights_path.test" @@ -337,6 +369,26 @@ resource "aws_ec2_network_insights_path" "test" { `, rName, tagKey1, tagValue1, tagKey2, tagValue2)) } +func testAccVPCNetworkInsightsPathConfig_sourceAndDestinationARN(rName, protocol string) string { + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` +resource "aws_network_interface" "test" { + count = 2 + + subnet_id = aws_subnet.test[0].id + + tags = { + Name = %[1]q + } +} + +resource "aws_ec2_network_insights_path" "test" { + source = aws_network_interface.test[0].arn + destination = aws_network_interface.test[1].arn + protocol = %[2]q +} +`, rName, protocol)) +} + func testAccVPCNetworkInsightsPathConfig_sourceIP(rName, sourceIP string) string { return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` resource "aws_internet_gateway" "test" { diff --git a/website/docs/r/ec2_network_insights_path.html.markdown b/website/docs/r/ec2_network_insights_path.html.markdown index 660bd8243e52..b16bda244cf4 100644 --- a/website/docs/r/ec2_network_insights_path.html.markdown +++ b/website/docs/r/ec2_network_insights_path.html.markdown @@ -24,8 +24,8 @@ resource "aws_ec2_network_insights_path" "test" { The following arguments are required: -* `source` - (Required) ID of the resource which is the source of the path. Can be an Instance, Internet Gateway, Network Interface, Transit Gateway, VPC Endpoint, VPC Peering Connection or VPN Gateway. -* `destination` - (Required) ID of the resource which is the source of the path. Can be an Instance, Internet Gateway, Network Interface, Transit Gateway, VPC Endpoint, VPC Peering Connection or VPN Gateway. +* `source` - (Required) ID or ARN of the resource which is the source of the path. Can be an Instance, Internet Gateway, Network Interface, Transit Gateway, VPC Endpoint, VPC Peering Connection or VPN Gateway. If the resource is in another account, you must specify an ARN. +* `destination` - (Required) ID or ARN of the resource which is the source of the path. Can be an Instance, Internet Gateway, Network Interface, Transit Gateway, VPC Endpoint, VPC Peering Connection or VPN Gateway. If the resource is in another account, you must specify an ARN. * `protocol` - (Required) Protocol to use for analysis. Valid options are `tcp` or `udp`. The following arguments are optional: @@ -40,7 +40,9 @@ The following arguments are optional: This resource exports the following attributes in addition to the arguments above: * `arn` - ARN of the Network Insights Path. +* `destination_arn` - ARN of the destination. * `id` - ID of the Network Insights Path. +* `source_arn` - ARN of the source. * `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). ## Import From b2184d1ab41bae7e13c96a52957d008271b4706c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 16:20:13 -0400 Subject: [PATCH 04/12] Acceptance test output: % make testacc TESTARGS='-run=TestAccVPCNetworkInsightsPath_basic' PKG=ec2 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 20 -run=TestAccVPCNetworkInsightsPath_basic -timeout 180m === RUN TestAccVPCNetworkInsightsPath_basic === PAUSE TestAccVPCNetworkInsightsPath_basic === CONT TestAccVPCNetworkInsightsPath_basic --- PASS: TestAccVPCNetworkInsightsPath_basic (52.71s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/ec2 58.363s From b351ee2ba8ce8df951efb28f38f89db4087494ed Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 16:24:09 -0400 Subject: [PATCH 05/12] d/aws_ec2_network_insights_path: Add 'destination_arn' and 'source_arn' attributes. --- .changelog/#####.txt | 4 ++++ .../ec2/vpc_network_insights_path_data_source.go | 10 ++++++++++ .../ec2/vpc_network_insights_path_data_source_test.go | 2 ++ website/docs/d/ec2_network_insights_path.html.markdown | 2 ++ 4 files changed, 18 insertions(+) diff --git a/.changelog/#####.txt b/.changelog/#####.txt index 1b48d657ddf6..a41492976a2e 100644 --- a/.changelog/#####.txt +++ b/.changelog/#####.txt @@ -4,4 +4,8 @@ resource/aws_ec2_network_insights_analysis: Fix `setting forward_path_components ```release-note:enhancement resource/aws_ec2_network_insights_path: Add `destination_arn` and `source_arn` attributes +``` + +```release-note:enhancement +data-source/aws_ec2_network_insights_path: Add `destination_arn` and `source_arn` attributes ``` \ No newline at end of file diff --git a/internal/service/ec2/vpc_network_insights_path_data_source.go b/internal/service/ec2/vpc_network_insights_path_data_source.go index f7c8e35d2ba4..de44586d8bd0 100644 --- a/internal/service/ec2/vpc_network_insights_path_data_source.go +++ b/internal/service/ec2/vpc_network_insights_path_data_source.go @@ -29,6 +29,10 @@ func DataSourceNetworkInsightsPath() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "destination_arn": { + Type: schema.TypeString, + Computed: true, + }, "destination_ip": { Type: schema.TypeString, Computed: true, @@ -51,6 +55,10 @@ func DataSourceNetworkInsightsPath() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "source_arn": { + Type: schema.TypeString, + Computed: true, + }, "source_ip": { Type: schema.TypeString, Computed: true, @@ -89,11 +97,13 @@ func dataSourceNetworkInsightsPathRead(ctx context.Context, d *schema.ResourceDa d.SetId(networkInsightsPathID) d.Set("arn", nip.NetworkInsightsPathArn) d.Set("destination", nip.Destination) + d.Set("destination_arn", nip.DestinationArn) d.Set("destination_ip", nip.DestinationIp) d.Set("destination_port", nip.DestinationPort) d.Set("network_insights_path_id", networkInsightsPathID) d.Set("protocol", nip.Protocol) d.Set("source", nip.Source) + d.Set("source_arn", nip.SourceArn) d.Set("source_ip", nip.SourceIp) if err := d.Set("tags", KeyValueTags(ctx, nip.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { diff --git a/internal/service/ec2/vpc_network_insights_path_data_source_test.go b/internal/service/ec2/vpc_network_insights_path_data_source_test.go index 64ef05cacfec..b6cf943cc690 100644 --- a/internal/service/ec2/vpc_network_insights_path_data_source_test.go +++ b/internal/service/ec2/vpc_network_insights_path_data_source_test.go @@ -29,11 +29,13 @@ func TestAccVPCNetworkInsightsPathDataSource_basic(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"), resource.TestCheckResourceAttrPair(datasourceName, "destination", resourceName, "destination"), + resource.TestCheckResourceAttrPair(datasourceName, "destination_arn", resourceName, "destination_arn"), resource.TestCheckResourceAttrPair(datasourceName, "destination_ip", resourceName, "destination_ip"), resource.TestCheckResourceAttrPair(datasourceName, "destination_port", resourceName, "destination_port"), resource.TestCheckResourceAttrPair(datasourceName, "network_insights_path_id", resourceName, "id"), resource.TestCheckResourceAttrPair(datasourceName, "protocol", resourceName, "protocol"), resource.TestCheckResourceAttrPair(datasourceName, "source", resourceName, "source"), + resource.TestCheckResourceAttrPair(datasourceName, "source_arn", resourceName, "source_arn"), resource.TestCheckResourceAttrPair(datasourceName, "source_ip", resourceName, "source_ip"), resource.TestCheckResourceAttrPair(datasourceName, "tags.%", resourceName, "tags.%"), ), diff --git a/website/docs/d/ec2_network_insights_path.html.markdown b/website/docs/d/ec2_network_insights_path.html.markdown index 74341373b34e..8b46e787325e 100644 --- a/website/docs/d/ec2_network_insights_path.html.markdown +++ b/website/docs/d/ec2_network_insights_path.html.markdown @@ -40,9 +40,11 @@ This data source exports the following attributes in addition to the arguments a * `arn` - ARN of the selected Network Insights Path. * `destination` - AWS resource that is the destination of the path. +* `destination_arn` - ARN of the destination. * `destination_ip` - IP address of the AWS resource that is the destination of the path. * `destination_port` - Destination port. * `protocol` - Protocol. * `source` - AWS resource that is the source of the path. +* `source_arn` - ARN of the source. * `source_ip` - IP address of the AWS resource that is the source of the path. * `tags` - Map of tags assigned to the resource. From 1353887a308101e2ae8aa085f843dac8f90be9cf Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 16:25:50 -0400 Subject: [PATCH 06/12] Acceptance test output: % make testacc TESTARGS='-run=TestAccVPCNetworkInsightsPathDataSource_basic' PKG=ec2 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 20 -run=TestAccVPCNetworkInsightsPathDataSource_basic -timeout 180m === RUN TestAccVPCNetworkInsightsPathDataSource_basic === PAUSE TestAccVPCNetworkInsightsPathDataSource_basic === CONT TestAccVPCNetworkInsightsPathDataSource_basic --- PASS: TestAccVPCNetworkInsightsPathDataSource_basic (46.45s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/ec2 52.380s From 74e89fc8c20b52cc50e8a4e7376dc7b557206f00 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 16:32:01 -0400 Subject: [PATCH 07/12] r/aws_ec2_network_insights_path: Avoid recreating resource when passing an ARN as 'source' or 'destination'. --- .changelog/#####.txt | 4 +++ .../service/ec2/vpc_network_insights_path.go | 28 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.changelog/#####.txt b/.changelog/#####.txt index a41492976a2e..c62757ba64f5 100644 --- a/.changelog/#####.txt +++ b/.changelog/#####.txt @@ -8,4 +8,8 @@ resource/aws_ec2_network_insights_path: Add `destination_arn` and `source_arn` a ```release-note:enhancement data-source/aws_ec2_network_insights_path: Add `destination_arn` and `source_arn` attributes +``` + +```release-note:bug +resource/aws_ec2_network_insights_path: Avoid recreating resource when passing an ARN as `source` or `destination` ``` \ No newline at end of file diff --git a/internal/service/ec2/vpc_network_insights_path.go b/internal/service/ec2/vpc_network_insights_path.go index 91b4a3ea4de7..f4eb129acc03 100644 --- a/internal/service/ec2/vpc_network_insights_path.go +++ b/internal/service/ec2/vpc_network_insights_path.go @@ -6,6 +6,7 @@ package ec2 import ( "context" "log" + "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -43,9 +44,10 @@ func ResourceNetworkInsightsPath() *schema.Resource { Computed: true, }, "destination": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: suppressEquivalentIDOrARN, }, "destination_ip": { Type: schema.TypeString, @@ -64,9 +66,10 @@ func ResourceNetworkInsightsPath() *schema.Resource { ValidateFunc: validation.StringInSlice(ec2.Protocol_Values(), false), }, "source": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: suppressEquivalentIDOrARN, }, "source_arn": { Type: schema.TypeString, @@ -171,3 +174,16 @@ func resourceNetworkInsightsPathDelete(ctx context.Context, d *schema.ResourceDa return nil } + +// idFromIDOrARN return a resource ID from an ID or ARN. +func idFromIDOrARN(idOrARN string) string { + // e.g. "eni-02ae120b80627a68f" or + // "arn:aws:ec2:ap-southeast-2:123456789012:network-interface/eni-02ae120b80627a68f". + return idOrARN[strings.LastIndex(idOrARN, "/")+1:] +} + +// suppressEquivalentIDOrARN provides custom difference suppression +// for strings that represent equal resource IDs or ARNs. +func suppressEquivalentIDOrARN(_, old, new string, _ *schema.ResourceData) bool { + return idFromIDOrARN(old) == idFromIDOrARN(new) +} From c0bcf19ac2f075615ec1c6d54ed05476ee8a2ea3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 16:45:13 -0400 Subject: [PATCH 08/12] Acceptance test output: % make testacc TESTARGS='-run=TestAccVPCNetworkInsightsPath_' PKG=ec2 ACCTEST_PARALLELISM=2 ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 2 -run=TestAccVPCNetworkInsightsPath_ -timeout 180m === RUN TestAccVPCNetworkInsightsPath_basic === PAUSE TestAccVPCNetworkInsightsPath_basic === RUN TestAccVPCNetworkInsightsPath_disappears === PAUSE TestAccVPCNetworkInsightsPath_disappears === RUN TestAccVPCNetworkInsightsPath_tags === PAUSE TestAccVPCNetworkInsightsPath_tags === RUN TestAccVPCNetworkInsightsPath_sourceAndDestinationARN === PAUSE TestAccVPCNetworkInsightsPath_sourceAndDestinationARN === RUN TestAccVPCNetworkInsightsPath_sourceIP === PAUSE TestAccVPCNetworkInsightsPath_sourceIP === RUN TestAccVPCNetworkInsightsPath_destinationIP === PAUSE TestAccVPCNetworkInsightsPath_destinationIP === RUN TestAccVPCNetworkInsightsPath_destinationPort === PAUSE TestAccVPCNetworkInsightsPath_destinationPort === CONT TestAccVPCNetworkInsightsPath_basic === CONT TestAccVPCNetworkInsightsPath_sourceIP --- PASS: TestAccVPCNetworkInsightsPath_basic (57.25s) === CONT TestAccVPCNetworkInsightsPath_destinationPort --- PASS: TestAccVPCNetworkInsightsPath_sourceIP (88.68s) === CONT TestAccVPCNetworkInsightsPath_tags --- PASS: TestAccVPCNetworkInsightsPath_destinationPort (86.46s) === CONT TestAccVPCNetworkInsightsPath_sourceAndDestinationARN --- PASS: TestAccVPCNetworkInsightsPath_sourceAndDestinationARN (53.52s) === CONT TestAccVPCNetworkInsightsPath_destinationIP --- PASS: TestAccVPCNetworkInsightsPath_tags (122.06s) === CONT TestAccVPCNetworkInsightsPath_disappears --- PASS: TestAccVPCNetworkInsightsPath_disappears (59.85s) --- PASS: TestAccVPCNetworkInsightsPath_destinationIP (86.54s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/ec2 290.139s From 89ed773ae86fb198ef680db5996b77f9b1c25ce1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 17:21:14 -0400 Subject: [PATCH 09/12] ec2: Use 'errors.Join'. --- internal/service/ec2/errors.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/internal/service/ec2/errors.go b/internal/service/ec2/errors.go index 7e41bd299882..34d4e68105e7 100644 --- a/internal/service/ec2/errors.go +++ b/internal/service/ec2/errors.go @@ -4,12 +4,12 @@ package ec2 import ( + "errors" "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" - multierror "github.com/hashicorp/go-multierror" ) const ( @@ -129,15 +129,15 @@ func CancelSpotFleetRequestError(apiObject *ec2.CancelSpotFleetRequestsErrorItem } func CancelSpotFleetRequestsError(apiObjects []*ec2.CancelSpotFleetRequestsErrorItem) error { - var errors *multierror.Error + var errs []error for _, apiObject := range apiObjects { if err := CancelSpotFleetRequestError(apiObject); err != nil { - errors = multierror.Append(errors, fmt.Errorf("%s: %w", aws.StringValue(apiObject.SpotFleetRequestId), err)) + errs = append(errs, fmt.Errorf("%s: %w", aws.StringValue(apiObject.SpotFleetRequestId), err)) } } - return errors.ErrorOrNil() + return errors.Join(errs...) } func DeleteFleetError(apiObject *ec2.DeleteFleetErrorItem) error { @@ -149,15 +149,15 @@ func DeleteFleetError(apiObject *ec2.DeleteFleetErrorItem) error { } func DeleteFleetsError(apiObjects []*ec2.DeleteFleetErrorItem) error { - var errors *multierror.Error + var errs []error for _, apiObject := range apiObjects { if err := DeleteFleetError(apiObject); err != nil { - errors = multierror.Append(errors, fmt.Errorf("%s: %w", aws.StringValue(apiObject.FleetId), err)) + errs = append(errs, fmt.Errorf("%s: %w", aws.StringValue(apiObject.FleetId), err)) } } - return errors.ErrorOrNil() + return errors.Join(errs...) } func UnsuccessfulItemError(apiObject *ec2.UnsuccessfulItemError) error { @@ -169,19 +169,17 @@ func UnsuccessfulItemError(apiObject *ec2.UnsuccessfulItemError) error { } func UnsuccessfulItemsError(apiObjects []*ec2.UnsuccessfulItem) error { - var errors *multierror.Error + var errs []error for _, apiObject := range apiObjects { if apiObject == nil { continue } - err := UnsuccessfulItemError(apiObject.Error) - - if err != nil { - errors = multierror.Append(errors, fmt.Errorf("%s: %w", aws.StringValue(apiObject.ResourceId), err)) + if err := UnsuccessfulItemError(apiObject.Error); err != nil { + errs = append(errs, fmt.Errorf("%s: %w", aws.StringValue(apiObject.ResourceId), err)) } } - return errors.ErrorOrNil() + return errors.Join(errs...) } From 5b926bab28e41a1d8d5fdb9d8e9357ec281482c4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 17:28:49 -0400 Subject: [PATCH 10/12] r/aws_ec2_network_insights_path: Retry 'AnalysisExistsForNetworkInsightsPath' errors on resource Delete. --- .changelog/#####.txt | 4 ++++ internal/service/ec2/errors.go | 1 + internal/service/ec2/vpc_network_insights_path.go | 8 +++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.changelog/#####.txt b/.changelog/#####.txt index c62757ba64f5..c87b865d503e 100644 --- a/.changelog/#####.txt +++ b/.changelog/#####.txt @@ -12,4 +12,8 @@ data-source/aws_ec2_network_insights_path: Add `destination_arn` and `source_arn ```release-note:bug resource/aws_ec2_network_insights_path: Avoid recreating resource when passing an ARN as `source` or `destination` +``` + +```release-note:bug +resource/aws_ec2_network_insights_path: Retry `AnalysisExistsForNetworkInsightsPath` errors on resource Delete ``` \ No newline at end of file diff --git a/internal/service/ec2/errors.go b/internal/service/ec2/errors.go index 34d4e68105e7..8f9e0b137d72 100644 --- a/internal/service/ec2/errors.go +++ b/internal/service/ec2/errors.go @@ -13,6 +13,7 @@ import ( ) const ( + errCodeAnalysisExistsForNetworkInsightsPath = "AnalysisExistsForNetworkInsightsPath" errCodeAuthFailure = "AuthFailure" errCodeClientInvalidHostIDNotFound = "Client.InvalidHostID.NotFound" errCodeConcurrentMutationLimitExceeded = "ConcurrentMutationLimitExceeded" diff --git a/internal/service/ec2/vpc_network_insights_path.go b/internal/service/ec2/vpc_network_insights_path.go index f4eb129acc03..ede94387b65c 100644 --- a/internal/service/ec2/vpc_network_insights_path.go +++ b/internal/service/ec2/vpc_network_insights_path.go @@ -160,9 +160,11 @@ func resourceNetworkInsightsPathDelete(ctx context.Context, d *schema.ResourceDa conn := meta.(*conns.AWSClient).EC2Conn(ctx) log.Printf("[DEBUG] Deleting EC2 Network Insights Path: %s", d.Id()) - _, err := conn.DeleteNetworkInsightsPathWithContext(ctx, &ec2.DeleteNetworkInsightsPathInput{ - NetworkInsightsPathId: aws.String(d.Id()), - }) + _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, ec2PropagationTimeout, func() (interface{}, error) { + return conn.DeleteNetworkInsightsPathWithContext(ctx, &ec2.DeleteNetworkInsightsPathInput{ + NetworkInsightsPathId: aws.String(d.Id()), + }) + }, errCodeAnalysisExistsForNetworkInsightsPath) if tfawserr.ErrCodeEquals(err, errCodeInvalidNetworkInsightsPathIdNotFound) { return nil From 4e6462128ab209ee15befc0c71b03590322852ce Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 17:31:36 -0400 Subject: [PATCH 11/12] Correct CHANGELOG entry file name. --- .changelog/{#####.txt => 33168.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{#####.txt => 33168.txt} (100%) diff --git a/.changelog/#####.txt b/.changelog/33168.txt similarity index 100% rename from .changelog/#####.txt rename to .changelog/33168.txt From ae0d19b7e75803332bd48ab3e442b3c11a9a13fb Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Aug 2023 17:40:29 -0400 Subject: [PATCH 12/12] Remove import step from 'TestAccVPCNetworkInsightsAnalysis_waitForCompletion'. --- internal/service/ec2/vpc_network_insights_analysis_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/internal/service/ec2/vpc_network_insights_analysis_test.go b/internal/service/ec2/vpc_network_insights_analysis_test.go index 9855dac81161..ea3af861df71 100644 --- a/internal/service/ec2/vpc_network_insights_analysis_test.go +++ b/internal/service/ec2/vpc_network_insights_analysis_test.go @@ -177,12 +177,6 @@ func TestAccVPCNetworkInsightsAnalysis_waitForCompletion(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "status", "running"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"wait_for_completion"}, - }, { Config: testAccVPCNetworkInsightsAnalysisConfig_waitForCompletion(rName, true), Check: resource.ComposeTestCheckFunc(