@@ -226,10 +226,21 @@ func resourceTable() *schema.Resource {
226226 },
227227 },
228228 },
229- "global_table_witness_region_name " : {
230- Type : schema .TypeString ,
229+ "global_table_witness " : {
230+ Type : schema .TypeList ,
231231 Optional : true ,
232232 Computed : true ,
233+ MaxItems : 1 ,
234+ Elem : & schema.Resource {
235+ Schema : map [string ]* schema.Schema {
236+ "region_name" : {
237+ Type : schema .TypeString ,
238+ Optional : true ,
239+ Computed : true ,
240+ ValidateFunc : verify .ValidRegionName ,
241+ },
242+ },
243+ },
233244 },
234245 "hash_key" : {
235246 Type : schema .TypeString ,
@@ -889,7 +900,7 @@ func resourceTableCreate(ctx context.Context, d *schema.ResourceData, meta any)
889900 }
890901
891902 if v := d .Get ("replica" ).(* schema.Set ); v .Len () > 0 {
892- if err := createReplicas (ctx , conn , d .Id (), v .List (), d .Get ("global_table_witness_region_name" ).( string ), true , d .Timeout (schema .TimeoutCreate )); err != nil {
903+ if err := createReplicas (ctx , conn , d .Id (), v .List (), expandGlobalTableWitness ( d .Get ("global_table_witness" ) ), true , d .Timeout (schema .TimeoutCreate )); err != nil {
893904 return create .AppendDiagError (diags , names .DynamoDB , create .ErrActionCreating , resNameTable , d .Id (), fmt .Errorf ("replicas: %w" , err ))
894905 }
895906
@@ -956,7 +967,9 @@ func resourceTableRead(ctx context.Context, d *schema.ResourceData, meta any) di
956967 return create .AppendDiagSettingError (diags , names .DynamoDB , resNameTable , d .Id (), "global_secondary_index" , err )
957968 }
958969
959- d .Set ("global_table_witness_region_name" , flattenGlobalTableWitnesses (table .GlobalTableWitnesses ))
970+ if err := d .Set ("global_table_witness" , flattenGlobalTableWitnesses (table .GlobalTableWitnesses )); err != nil {
971+ return create .AppendDiagSettingError (diags , names .DynamoDB , resNameTable , d .Id (), "global_table_witness" , err )
972+ }
960973
961974 if err := d .Set ("on_demand_throughput" , flattenOnDemandThroughput (table .OnDemandThroughput )); err != nil {
962975 return create .AppendDiagSettingError (diags , names .DynamoDB , resNameTable , d .Id (), "on_demand_throughput" , err )
@@ -1400,7 +1413,7 @@ func resourceTableDelete(ctx context.Context, d *schema.ResourceData, meta any)
14001413
14011414 if replicas := d .Get ("replica" ).(* schema.Set ).List (); len (replicas ) > 0 {
14021415 log .Printf ("[DEBUG] Deleting DynamoDB Table replicas: %s" , d .Id ())
1403- if err := deleteReplicas (ctx , conn , d .Id (), replicas , d .Get ("global_table_witness_region_name" ).( string ), d .Timeout (schema .TimeoutDelete )); err != nil {
1416+ if err := deleteReplicas (ctx , conn , d .Id (), replicas , expandGlobalTableWitness ( d .Get ("global_table_witness" ) ), d .Timeout (schema .TimeoutDelete )); err != nil {
14041417 // ValidationException: Replica specified in the Replica Update or Replica Delete action of the request was not found.
14051418 // ValidationException: Cannot add, delete, or update the local region through ReplicaUpdates. Use CreateTable, DeleteTable, or UpdateTable as required.
14061419 if ! tfawserr .ErrMessageContains (err , errCodeValidationException , "request was not found" ) &&
@@ -1920,7 +1933,7 @@ func updateReplica(ctx context.Context, conn *dynamodb.Client, d *schema.Resourc
19201933 }
19211934 }
19221935
1923- globalTableWitnessRegionName := d .Get ("global_table_witness_region_name" ).( string )
1936+ globalTableWitnessRegionName := expandGlobalTableWitness ( d .Get ("global_table_witness" ) )
19241937
19251938 if len (removeFirst ) > 0 { // mini ForceNew, recreates replica but doesn't recreate the table
19261939 if err := deleteReplicas (ctx , conn , d .Id (), removeFirst , globalTableWitnessRegionName , d .Timeout (schema .TimeoutUpdate )); err != nil {
@@ -2728,22 +2741,22 @@ func flattenGSIWarmThroughput(apiObject *awstypes.GlobalSecondaryIndexWarmThroug
27282741 return []any {m }
27292742}
27302743
2731- func flattenGlobalTableWitnesses ( apiObjects []awstypes. GlobalTableWitnessDescription ) string {
2732- if apiObjects == nil {
2744+ func expandGlobalTableWitness ( v any ) string {
2745+ if v == nil || len ( v .([] any )) == 0 || v .([] any )[ 0 ] == nil {
27332746 return ""
27342747 }
27352748
2736- if len (apiObjects ) > 1 {
2737- return ""
2738- }
2749+ return v .([]any )[0 ].(map [string ]any )["region_name" ].(string )
2750+ }
27392751
2740- for _ , apiObject := range apiObjects {
2741- if apiObject .RegionName != nil {
2742- return aws .ToString (apiObject .RegionName )
2743- }
2752+ func flattenGlobalTableWitnesses (apiObjects []awstypes.GlobalTableWitnessDescription ) []any {
2753+ if len (apiObjects ) != 1 {
2754+ return []any {}
27442755 }
27452756
2746- return ""
2757+ return []any {map [string ]any {
2758+ "region_name" : aws .ToString (apiObjects [0 ].RegionName ),
2759+ }}
27472760}
27482761
27492762func flattenReplicaDescription (apiObject * awstypes.ReplicaDescription ) map [string ]any {
0 commit comments