Skip to content

Commit

Permalink
Merge pull request #30385 from posquit0/dx-connection-fix
Browse files Browse the repository at this point in the history
Fix wrong outputs of aws_dx_connection
  • Loading branch information
ewbankkit authored Apr 12, 2023
2 parents 3e1e0a1 + 826b1a6 commit 653ed72
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .changelog/30385.txt
Original file line number Diff line number Diff line change
@@ -0,0 +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
```
29 changes: 16 additions & 13 deletions internal/service/directconnect/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -133,7 +136,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 {
Expand Down Expand Up @@ -178,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)
Expand All @@ -195,20 +198,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)
}
}

Expand All @@ -217,16 +220,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
if v, ok := d.GetOk("skip_destroy"); ok && v.(bool) {
log.Printf("[DEBUG] Retaining Direct Connect Connection: %s", d.Id())
conn := meta.(*conns.AWSClient).DirectConnectConn()

if _, ok := d.GetOk("skip_destroy"); ok {
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
}

Expand All @@ -241,13 +244,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
Expand Down
5 changes: 5 additions & 0 deletions internal/service/directconnect/connection_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down
1 change: 1 addition & 0 deletions internal/service/directconnect/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""),
Expand Down
3 changes: 2 additions & 1 deletion internal/service/directconnect/hosted_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 2 additions & 6 deletions internal/service/directconnect/lag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/dx_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions website/docs/r/dx_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 653ed72

Please sign in to comment.