From bf88f75f3ffce1018098240e81081b4df4b57226 Mon Sep 17 00:00:00 2001 From: Byungjin Park Date: Sat, 1 Apr 2023 03:05:19 +0900 Subject: [PATCH 1/6] Fix wrong outputs of aws_dx_connection --- internal/service/directconnect/connection.go | 4 ++-- internal/service/directconnect/connection_data_source.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/directconnect/connection.go b/internal/service/directconnect/connection.go index 4673e16e78e..1ca0f4cc81e 100644 --- a/internal/service/directconnect/connection.go +++ b/internal/service/directconnect/connection.go @@ -184,8 +184,8 @@ func resourceConnectionRead(ctx context.Context, d *schema.ResourceData, meta in d.Set("name", connection.ConnectionName) d.Set("owner_account_id", connection.OwnerAccount) d.Set("port_encryption_status", connection.PortEncryptionStatus) - d.Set("provider_name", connection.ProviderName) - d.Set("vlan_id", connection.Vlan) + d.Set("provider_name", connection.PartnerName) + d.Set("vlan_id", connection.VLAN) // d.Set("request_macsec", d.Get("request_macsec").(bool)) diff --git a/internal/service/directconnect/connection_data_source.go b/internal/service/directconnect/connection_data_source.go index 4b8540fb79b..ee1711a2252 100644 --- a/internal/service/directconnect/connection_data_source.go +++ b/internal/service/directconnect/connection_data_source.go @@ -104,8 +104,8 @@ func dataSourceConnectionRead(ctx context.Context, d *schema.ResourceData, meta d.Set("location", connection.Location) d.Set("name", connection.ConnectionName) d.Set("owner_account_id", connection.OwnerAccount) - d.Set("provider_name", connection.ProviderName) - d.Set("vlan_id", connection.Vlan) + d.Set("provider_name", connection.PartnerName) + d.Set("vlan_id", connection.VLAN) tags, err := ListTags(ctx, conn, arn) From 6c103bdb3faf17d948c5e80a94c22fddd1f9302e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Apr 2023 14:44:52 -0400 Subject: [PATCH 2/6] Revert "Fix wrong outputs of aws_dx_connection" This reverts commit bf88f75f3ffce1018098240e81081b4df4b57226. --- internal/service/directconnect/connection.go | 4 ++-- internal/service/directconnect/connection_data_source.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/directconnect/connection.go b/internal/service/directconnect/connection.go index 0c276578592..4c33147e7b5 100644 --- a/internal/service/directconnect/connection.go +++ b/internal/service/directconnect/connection.go @@ -179,8 +179,8 @@ func resourceConnectionRead(ctx context.Context, d *schema.ResourceData, meta in d.Set("name", connection.ConnectionName) d.Set("owner_account_id", connection.OwnerAccount) d.Set("port_encryption_status", connection.PortEncryptionStatus) - d.Set("provider_name", connection.PartnerName) - d.Set("vlan_id", connection.VLAN) + d.Set("provider_name", connection.ProviderName) + d.Set("vlan_id", connection.Vlan) // d.Set("request_macsec", d.Get("request_macsec").(bool)) diff --git a/internal/service/directconnect/connection_data_source.go b/internal/service/directconnect/connection_data_source.go index ee1711a2252..4b8540fb79b 100644 --- a/internal/service/directconnect/connection_data_source.go +++ b/internal/service/directconnect/connection_data_source.go @@ -104,8 +104,8 @@ func dataSourceConnectionRead(ctx context.Context, d *schema.ResourceData, meta d.Set("location", connection.Location) d.Set("name", connection.ConnectionName) d.Set("owner_account_id", connection.OwnerAccount) - d.Set("provider_name", connection.PartnerName) - d.Set("vlan_id", connection.VLAN) + d.Set("provider_name", connection.ProviderName) + d.Set("vlan_id", connection.Vlan) tags, err := ListTags(ctx, conn, arn) From 560f5a14fedcd24e91c714cdf4112d97918625e3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Apr 2023 15:17:12 -0400 Subject: [PATCH 3/6] r/aws_dx_connection: Tidy up. --- internal/service/directconnect/connection.go | 21 +++++++++---------- .../directconnect/hosted_connection.go | 3 ++- internal/service/directconnect/lag.go | 8 ++----- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/internal/service/directconnect/connection.go b/internal/service/directconnect/connection.go index 4c33147e7b5..7c4684735a4 100644 --- a/internal/service/directconnect/connection.go +++ b/internal/service/directconnect/connection.go @@ -133,7 +133,6 @@ func resourceConnectionCreate(ctx context.Context, d *schema.ResourceData, meta input.ProviderName = aws.String(v.(string)) } - log.Printf("[DEBUG] Creating Direct Connect Connection: %s", input) output, err := conn.CreateConnectionWithContext(ctx, input) if err != nil { @@ -195,20 +194,20 @@ func resourceConnectionUpdate(ctx context.Context, d *schema.ResourceData, meta var diags diag.Diagnostics conn := meta.(*conns.AWSClient).DirectConnectConn() - // Update encryption mode if d.HasChange("encryption_mode") { input := &directconnect.UpdateConnectionInput{ ConnectionId: aws.String(d.Id()), EncryptionMode: aws.String(d.Get("encryption_mode").(string)), } - log.Printf("[DEBUG] Modifying Direct Connect connection attributes: %s", input) + _, err := conn.UpdateConnectionWithContext(ctx, input) + if err != nil { - return sdkdiag.AppendErrorf(diags, "modifying Direct Connect connection (%s) attributes: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Direct Connect Connection (%s): %s", d.Id(), err) } if _, err := waitConnectionConfirmed(ctx, conn, d.Id()); err != nil { - return sdkdiag.AppendErrorf(diags, "waiting for Direct Connect connection (%s) to become available: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Direct Connect Connection (%s) update: %s", d.Id(), err) } } @@ -217,16 +216,16 @@ func resourceConnectionUpdate(ctx context.Context, d *schema.ResourceData, meta func resourceConnectionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).DirectConnectConn() + if v, ok := d.GetOk("skip_destroy"); ok && v.(bool) { - log.Printf("[DEBUG] Retaining Direct Connect Connection: %s", d.Id()) return diags } - conn := meta.(*conns.AWSClient).DirectConnectConn() - if err := deleteConnection(ctx, conn, d.Id(), waitConnectionDeleted); err != nil { - return sdkdiag.AppendErrorf(diags, "deleting Direct Connect Connection (%s): %s", d.Id(), err) + return sdkdiag.AppendFromErr(diags, err) } + return diags } @@ -241,13 +240,13 @@ func deleteConnection(ctx context.Context, conn *directconnect.DirectConnect, co } if err != nil { - return err + return fmt.Errorf("deleting Direct Connect Connection (%s): %w", connectionID, err) } _, err = waiter(ctx, conn, connectionID) if err != nil { - return fmt.Errorf("wating for completion: %w", err) + return fmt.Errorf("waiting for Direct Connect Connection (%s): %w", connectionID, err) } return nil diff --git a/internal/service/directconnect/hosted_connection.go b/internal/service/directconnect/hosted_connection.go index 689d28f1ede..bb73981468c 100644 --- a/internal/service/directconnect/hosted_connection.go +++ b/internal/service/directconnect/hosted_connection.go @@ -162,7 +162,8 @@ func resourceHostedConnectionDelete(ctx context.Context, d *schema.ResourceData, conn := meta.(*conns.AWSClient).DirectConnectConn() if err := deleteConnection(ctx, conn, d.Id(), waitHostedConnectionDeleted); err != nil { - return sdkdiag.AppendErrorf(diags, "deleting Direct Connect Hosted Connection (%s): %s", d.Id(), err) + return sdkdiag.AppendFromErr(diags, err) } + return diags } diff --git a/internal/service/directconnect/lag.go b/internal/service/directconnect/lag.go index 600368f6fea..a0c6dce3644 100644 --- a/internal/service/directconnect/lag.go +++ b/internal/service/directconnect/lag.go @@ -123,9 +123,7 @@ func resourceLagCreate(ctx context.Context, d *schema.ResourceData, meta interfa // Delete unmanaged connection. if !connectionIDSpecified { - err = deleteConnection(ctx, conn, aws.StringValue(output.Connections[0].ConnectionId), waitConnectionDeleted) - - if err != nil { + if err := deleteConnection(ctx, conn, aws.StringValue(output.Connections[0].ConnectionId), waitConnectionDeleted); err != nil { return sdkdiag.AppendFromErr(diags, err) } } @@ -201,9 +199,7 @@ func resourceLagDelete(ctx context.Context, d *schema.ResourceData, meta interfa } for _, connection := range lag.Connections { - err = deleteConnection(ctx, conn, aws.StringValue(connection.ConnectionId), waitConnectionDeleted) - - if err != nil { + if err := deleteConnection(ctx, conn, aws.StringValue(connection.ConnectionId), waitConnectionDeleted); err != nil { return sdkdiag.AppendFromErr(diags, err) } } From 19066fa335f7f82bda9ba662ca80fc41f2bef3c9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Apr 2023 15:22:51 -0400 Subject: [PATCH 4/6] r/aws_dx_connection: Add 'partner_name' attribute. --- .changelog/30385.txt | 3 +++ internal/service/directconnect/connection.go | 6 +++++- internal/service/directconnect/connection_test.go | 1 + website/docs/r/dx_connection.html.markdown | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changelog/30385.txt diff --git a/.changelog/30385.txt b/.changelog/30385.txt new file mode 100644 index 00000000000..8d1025372f1 --- /dev/null +++ b/.changelog/30385.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_dx_connection: Add `partner_name` attribute +``` \ No newline at end of file diff --git a/internal/service/directconnect/connection.go b/internal/service/directconnect/connection.go index 7c4684735a4..69ed6182940 100644 --- a/internal/service/directconnect/connection.go +++ b/internal/service/directconnect/connection.go @@ -88,7 +88,10 @@ func ResourceConnection() *schema.Resource { Type: schema.TypeString, Computed: true, }, - // The MAC Security (MACsec) port link status of the connection. + "partner_name": { + Type: schema.TypeString, + Computed: true, + }, "port_encryption_status": { Type: schema.TypeString, Computed: true, @@ -177,6 +180,7 @@ func resourceConnectionRead(ctx context.Context, d *schema.ResourceData, meta in d.Set("macsec_capable", connection.MacSecCapable) d.Set("name", connection.ConnectionName) d.Set("owner_account_id", connection.OwnerAccount) + d.Set("partner_name", connection.PartnerName) d.Set("port_encryption_status", connection.PortEncryptionStatus) d.Set("provider_name", connection.ProviderName) d.Set("vlan_id", connection.Vlan) diff --git a/internal/service/directconnect/connection_test.go b/internal/service/directconnect/connection_test.go index 005df2e99a5..4bfe85053dc 100644 --- a/internal/service/directconnect/connection_test.go +++ b/internal/service/directconnect/connection_test.go @@ -38,6 +38,7 @@ func TestAccDirectConnectConnection_basic(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "location"), acctest.CheckResourceAttrAccountID(resourceName, "owner_account_id"), resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "partner_name", ""), resource.TestCheckResourceAttr(resourceName, "provider_name", ""), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "vlan_id", ""), diff --git a/website/docs/r/dx_connection.html.markdown b/website/docs/r/dx_connection.html.markdown index df6e423ce58..c5a0ad75997 100644 --- a/website/docs/r/dx_connection.html.markdown +++ b/website/docs/r/dx_connection.html.markdown @@ -73,6 +73,7 @@ In addition to all arguments above, the following attributes are exported: * `jumbo_frame_capable` - Boolean value representing if jumbo frames have been enabled for this connection. * `macsec_capable` - Boolean value indicating whether the connection supports MAC Security (MACsec). * `owner_account_id` - The ID of the AWS account that owns the connection. +* `partner_name` - The name of the AWS Direct Connect service provider associated with the connection. * `port_encryption_status` - The MAC Security (MACsec) port link status of the connection. * `tags_all` - A 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). * `vlan_id` - The VLAN ID. From 9cd327e24f4f943d0020ebe1edff1fef477efdd2 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Apr 2023 15:26:03 -0400 Subject: [PATCH 5/6] d/aws_dx_connection: Add 'partner_name' attribute. --- .changelog/30385.txt | 4 ++++ internal/service/directconnect/connection_data_source.go | 5 +++++ .../service/directconnect/connection_data_source_test.go | 1 + website/docs/d/dx_connection.html.markdown | 1 + 4 files changed, 11 insertions(+) diff --git a/.changelog/30385.txt b/.changelog/30385.txt index 8d1025372f1..a52d4d84235 100644 --- a/.changelog/30385.txt +++ b/.changelog/30385.txt @@ -1,3 +1,7 @@ ```release-note:enhancement resource/aws_dx_connection: Add `partner_name` attribute +``` + +```release-note:enhancement +data-source/aws_dx_connection: Add `partner_name` attribute ``` \ No newline at end of file diff --git a/internal/service/directconnect/connection_data_source.go b/internal/service/directconnect/connection_data_source.go index 4b8540fb79b..21a3a87f166 100644 --- a/internal/service/directconnect/connection_data_source.go +++ b/internal/service/directconnect/connection_data_source.go @@ -44,6 +44,10 @@ func DataSourceConnection() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "partner_name": { + Type: schema.TypeString, + Computed: true, + }, "provider_name": { Type: schema.TypeString, Computed: true, @@ -104,6 +108,7 @@ func dataSourceConnectionRead(ctx context.Context, d *schema.ResourceData, meta d.Set("location", connection.Location) d.Set("name", connection.ConnectionName) d.Set("owner_account_id", connection.OwnerAccount) + d.Set("partner_name", connection.PartnerName) d.Set("provider_name", connection.ProviderName) d.Set("vlan_id", connection.Vlan) diff --git a/internal/service/directconnect/connection_data_source_test.go b/internal/service/directconnect/connection_data_source_test.go index 1ae6572cad2..409b1fe627d 100644 --- a/internal/service/directconnect/connection_data_source_test.go +++ b/internal/service/directconnect/connection_data_source_test.go @@ -31,6 +31,7 @@ func TestAccDirectConnectConnectionDataSource_basic(t *testing.T) { resource.TestCheckResourceAttrPair(datasourceName, "location", resourceName, "location"), resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), resource.TestCheckResourceAttrPair(datasourceName, "owner_account_id", resourceName, "owner_account_id"), + resource.TestCheckResourceAttrPair(datasourceName, "partner_name", resourceName, "partner_name"), resource.TestCheckResourceAttrPair(datasourceName, "provider_name", resourceName, "provider_name"), resource.TestCheckResourceAttrPair(datasourceName, "vlan_id", resourceName, "vlan_id"), ), diff --git a/website/docs/d/dx_connection.html.markdown b/website/docs/d/dx_connection.html.markdown index bfbbb344885..89ff6e0999c 100644 --- a/website/docs/d/dx_connection.html.markdown +++ b/website/docs/d/dx_connection.html.markdown @@ -32,6 +32,7 @@ In addition to all arguments above, the following attributes are exported: * `id` - ID of the connection. * `location` - AWS Direct Connect location where the connection is located. * `owner_account_id` - ID of the AWS account that owns the connection. +* `partner_name` - The name of the AWS Direct Connect service provider associated with the connection. * `provider_name` - Name of the service provider associated with the connection. * `tags` - Map of tags for the resource. * `vlan_id` - The VLAN ID. From 826b1a6daf6ba69f16b2d87e07eba3945117cab5 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Apr 2023 16:31:12 -0400 Subject: [PATCH 6/6] Fix semgrep 'ci.helper-schema-ResourceData-GetOk-with-extraneous-conditional'. --- internal/service/directconnect/connection.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/directconnect/connection.go b/internal/service/directconnect/connection.go index 69ed6182940..d7dce8a9900 100644 --- a/internal/service/directconnect/connection.go +++ b/internal/service/directconnect/connection.go @@ -222,7 +222,7 @@ func resourceConnectionDelete(ctx context.Context, d *schema.ResourceData, meta var diags diag.Diagnostics conn := meta.(*conns.AWSClient).DirectConnectConn() - if v, ok := d.GetOk("skip_destroy"); ok && v.(bool) { + if _, ok := d.GetOk("skip_destroy"); ok { return diags }