Skip to content

Commit

Permalink
Merge pull request #37570 from dobriSu/b-fix_dynamo_db_replica_import…
Browse files Browse the repository at this point in the history
…_kms_key

Fix bug with AWS not return KMS key for replica
  • Loading branch information
ewbankkit authored May 20, 2024
2 parents b955849 + 2b2d022 commit 9330cf6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/37570.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_dynamodb_table_replica: Correctly set `kms_key_arn` on Read
```
6 changes: 5 additions & 1 deletion internal/service/dynamodb/table_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func resourceTableReplica() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: verify.ValidARN,
ForceNew: true,
ValidateFunc: verify.ValidARN,
},
"point_in_time_recovery": { // direct to replica
Type: schema.TypeBool,
Expand Down Expand Up @@ -297,6 +297,10 @@ func resourceTableReplicaReadReplica(ctx context.Context, d *schema.ResourceData
return create.AppendDiagError(diags, names.DynamoDB, create.ErrActionReading, resNameTableReplica, d.Id(), fmt.Errorf("continuous backups: %w", err))
}

if table.SSEDescription != nil && table.SSEDescription.KMSMasterKeyArn != nil {
d.Set(names.AttrKMSKeyARN, table.SSEDescription.KMSMasterKeyArn)
}

if pitrOut != nil && pitrOut.ContinuousBackupsDescription != nil && pitrOut.ContinuousBackupsDescription.PointInTimeRecoveryDescription != nil {
d.Set("point_in_time_recovery", pitrOut.ContinuousBackupsDescription.PointInTimeRecoveryDescription.PointInTimeRecoveryStatus == awstypes.PointInTimeRecoveryStatusEnabled)
} else {
Expand Down
6 changes: 3 additions & 3 deletions internal/service/dynamodb/table_replica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,23 @@ func TestAccDynamoDBTableReplica_pitrDefault(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckTableReplicaExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "point_in_time_recovery", "false"),
resource.TestCheckResourceAttr(resourceName, names.AttrKMSKeyARN, ""),
resource.TestCheckResourceAttrSet(resourceName, names.AttrKMSKeyARN),
),
},
{
Config: testAccTableReplicaConfig_pitrDefault(rName, true),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckTableReplicaExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "point_in_time_recovery", "true"),
resource.TestCheckResourceAttr(resourceName, names.AttrKMSKeyARN, ""),
resource.TestCheckResourceAttrSet(resourceName, names.AttrKMSKeyARN),
),
},
{
Config: testAccTableReplicaConfig_pitrDefault(rName, false),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckTableReplicaExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "point_in_time_recovery", "false"),
resource.TestCheckResourceAttr(resourceName, names.AttrKMSKeyARN, ""),
resource.TestCheckResourceAttrSet(resourceName, names.AttrKMSKeyARN),
),
},
{
Expand Down

0 comments on commit 9330cf6

Please sign in to comment.