@@ -1072,33 +1072,34 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter
1072
1072
}
1073
1073
1074
1074
if d .HasChange ("server_side_encryption" ) {
1075
- if replicas := d .Get ("replica" ).(* schema.Set ); replicas .Len () > 0 {
1075
+ if replicas , sseSpecification := d .Get ("replica" ).(* schema.Set ), expandEncryptAtRestOptions ( d . Get ( "server_side_encryption" ).([] interface {})) ; replicas .Len () > 0 && sseSpecification . KMSMasterKeyId != nil {
1076
1076
log .Printf ("[DEBUG] Using SSE update on replicas" )
1077
1077
var replicaInputs []awstypes.ReplicationGroupUpdate
1078
- var replicaRegions []string
1079
1078
for _ , replica := range replicas .List () {
1080
1079
tfMap , ok := replica .(map [string ]interface {})
1081
1080
if ! ok {
1082
1081
continue
1083
1082
}
1084
- var regionName string
1085
- var KMSMasterKeyId string
1086
- if v , ok := tfMap ["region_name" ].(string ); ok {
1087
- regionName = v
1088
- replicaRegions = append (replicaRegions , v )
1083
+
1084
+ region , ok := tfMap ["region_name" ].(string )
1085
+ if ! ok {
1086
+ continue
1089
1087
}
1090
- if v , ok := tfMap [names .AttrKMSKeyARN ].(string ); ok && v != "" {
1091
- KMSMasterKeyId = v
1088
+
1089
+ key , ok := tfMap [names .AttrKMSKeyARN ].(string )
1090
+ if ! ok || key == "" {
1091
+ continue
1092
1092
}
1093
+
1093
1094
var input = & awstypes.UpdateReplicationGroupMemberAction {
1094
- RegionName : aws .String (regionName ),
1095
- KMSMasterKeyId : aws .String (KMSMasterKeyId ),
1095
+ RegionName : aws .String (region ),
1096
+ KMSMasterKeyId : aws .String (key ),
1096
1097
}
1097
1098
var update = awstypes.ReplicationGroupUpdate {Update : input }
1098
1099
replicaInputs = append (replicaInputs , update )
1099
1100
}
1100
1101
var input = & awstypes.UpdateReplicationGroupMemberAction {
1101
- KMSMasterKeyId : expandEncryptAtRestOptions ( d . Get ( "server_side_encryption" ).([] interface {})) .KMSMasterKeyId ,
1102
+ KMSMasterKeyId : sseSpecification .KMSMasterKeyId ,
1102
1103
RegionName : aws .String (meta .(* conns.AWSClient ).Region ),
1103
1104
}
1104
1105
var update = awstypes.ReplicationGroupUpdate {Update : input }
@@ -1110,28 +1111,41 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter
1110
1111
if err != nil {
1111
1112
return sdkdiag .AppendErrorf (diags , "updating DynamoDB Table (%s) SSE: %s" , d .Id (), err )
1112
1113
}
1113
- for _ , region := range replicaRegions {
1114
- if _ , err := waitReplicaSSEUpdated (ctx , conn , region , d .Id (), d .Timeout (schema .TimeoutUpdate )); err != nil {
1115
- return sdkdiag .AppendErrorf (diags , "waiting for DynamoDB Table (%s) replica SSE update in region %q: %s" , d .Id (), region , err )
1116
- }
1117
- }
1118
- if _ , err := waitSSEUpdated (ctx , conn , d .Id (), d .Timeout (schema .TimeoutUpdate )); err != nil {
1119
- return sdkdiag .AppendErrorf (diags , "waiting for DynamoDB Table (%s) SSE update: %s" , d .Id (), err )
1120
- }
1121
1114
} else {
1122
1115
log .Printf ("[DEBUG] Using normal update for SSE" )
1123
1116
_ , err := conn .UpdateTable (ctx , & dynamodb.UpdateTableInput {
1124
1117
TableName : aws .String (d .Id ()),
1125
- SSESpecification : expandEncryptAtRestOptions ( d . Get ( "server_side_encryption" ).([] interface {})) ,
1118
+ SSESpecification : sseSpecification ,
1126
1119
})
1127
1120
if err != nil {
1128
1121
return sdkdiag .AppendErrorf (diags , "updating DynamoDB Table (%s) SSE: %s" , d .Id (), err )
1129
1122
}
1123
+ }
1130
1124
1131
- if _ , err := waitSSEUpdated (ctx , conn , d .Id (), d .Timeout (schema .TimeoutUpdate )); err != nil {
1132
- return sdkdiag .AppendErrorf (diags , "waiting for DynamoDB Table (%s) SSE update: %s" , d .Id (), err )
1125
+ // since we don't update replicas unless there is a KMS key, we need to wait for replica
1126
+ // updates for the scenario where 1) there are replicas, 2) we are updating SSE (such as
1127
+ // disabling), and 3) we have no KMS key
1128
+ if replicas := d .Get ("replica" ).(* schema.Set ); replicas .Len () > 0 {
1129
+ var replicaRegions []string
1130
+ for _ , replica := range replicas .List () {
1131
+ tfMap , ok := replica .(map [string ]interface {})
1132
+ if ! ok {
1133
+ continue
1134
+ }
1135
+ if v , ok := tfMap ["region_name" ].(string ); ok {
1136
+ replicaRegions = append (replicaRegions , v )
1137
+ }
1138
+ }
1139
+ for _ , region := range replicaRegions {
1140
+ if _ , err := waitReplicaSSEUpdated (ctx , conn , region , d .Id (), d .Timeout (schema .TimeoutUpdate )); err != nil {
1141
+ return sdkdiag .AppendErrorf (diags , "waiting for DynamoDB Table (%s) replica SSE update in region %q: %s" , d .Id (), region , err )
1142
+ }
1133
1143
}
1134
1144
}
1145
+
1146
+ if _ , err := waitSSEUpdated (ctx , conn , d .Id (), d .Timeout (schema .TimeoutUpdate )); err != nil {
1147
+ return sdkdiag .AppendErrorf (diags , "waiting for DynamoDB Table (%s) SSE update: %s" , d .Id (), err )
1148
+ }
1135
1149
}
1136
1150
1137
1151
if d .HasChange ("ttl" ) {
@@ -1902,7 +1916,7 @@ func clearSSEDefaultKey(ctx context.Context, client *conns.AWSClient, sseList []
1902
1916
return sseList
1903
1917
}
1904
1918
1905
- if sse [names .AttrKMSKeyARN ].(string ) == dk {
1919
+ if v , ok := sse [names .AttrKMSKeyARN ].(string ); ok && v == dk {
1906
1920
sse [names .AttrKMSKeyARN ] = ""
1907
1921
return []interface {}{sse }
1908
1922
}
0 commit comments