Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dynamodb make a DescribeTable call per replica #35630

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/35630.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_dynamodb_table: Make DescribeTable call per replica
```
45 changes: 23 additions & 22 deletions internal/service/dynamodb/table.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) HashiCorp, Inc.

Check failure on line 1 in internal/service/dynamodb/table.go

View workflow job for this annotation

GitHub Actions / importlint

Import groups are not in the proper order: ["Std" "Third party" "Third party"]
// SPDX-License-Identifier: MPL-2.0

package dynamodb
Expand All @@ -22,6 +22,7 @@
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
Expand Down Expand Up @@ -1795,25 +1796,6 @@
return enabled, nil
}

func replicaStream(ctx context.Context, conn *dynamodb.DynamoDB, tableName string, region string, tfVersion string) (string, string) {
// This does not return an error because it is attempting to add "Computed"-only information to replica - tolerating errors.
session, err := conns.NewSessionForRegion(&conn.Config, region, tfVersion)
if err != nil {
log.Printf("[WARN] Attempting to get replica (%s) stream information, ignoring encountered error: %s", tableName, err)
return "", ""
}

conn = dynamodb.New(session)

table, err := FindTableByName(ctx, conn, tableName)
if err != nil {
log.Printf("[WARN] When attempting to get replica (%s) stream information, ignoring encountered error: %s", tableName, err)
return "", ""
}

return aws.StringValue(table.LatestStreamArn), aws.StringValue(table.LatestStreamLabel)
}

func addReplicaPITRs(ctx context.Context, conn *dynamodb.DynamoDB, tableName string, tfVersion string, replicas []interface{}) ([]interface{}, error) {
// This non-standard approach is needed because PITR info for a replica
// must come from a region-specific connection.
Expand Down Expand Up @@ -1844,9 +1826,28 @@
}
replica[names.AttrARN] = newARN

streamARN, streamLabel := replicaStream(ctx, conn, tableName, replica["region_name"].(string), tfVersion)
replica["stream_arn"] = streamARN
replica["stream_label"] = streamLabel
session, err := conns.NewSessionForRegion(&conn.Config, replica["region_name"].(string), tfVersion)
if err != nil {
log.Printf("[WARN] Attempting to get replica (%s) stream information, ignoring encountered error: %s", tableName, err)
return nil, fmt.Errorf("")
}

conn = dynamodb.New(session)

table, err := FindTableByName(ctx, conn, tableName)
if err != nil {
log.Printf("[WARN] When attempting to get replica (%s) stream information, ignoring encountered error: %s", tableName, err)
return nil, fmt.Errorf("")
}

replica["stream_arn"] = aws.StringValue(table.LatestStreamArn)
replica["stream_label"] = aws.StringValue(table.LatestStreamLabel)

if table.SSEDescription != nil {
log.Printf("[WARN] in enrichReplicas setting KMS key arn")
replica[names.AttrKMSKeyARN] = aws.StringValue(table.SSEDescription.KMSMasterKeyArn)
}

replicas[i] = replica
}

Expand Down
Loading