From 2a142adf377810b6bbc7aafbb9296ba7081ba133 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 16 Oct 2024 11:04:12 -0500 Subject: [PATCH] aws_dynamodb_table: skip payPerRequest updates if throughput not specified --- internal/service/dynamodb/table.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/internal/service/dynamodb/table.go b/internal/service/dynamodb/table.go index 1a2483034cd..b2486c5b43a 100644 --- a/internal/service/dynamodb/table.go +++ b/internal/service/dynamodb/table.go @@ -272,9 +272,10 @@ func resourceTable() *schema.Resource { ForceNew: true, }, "read_capacity": { - Type: schema.TypeInt, - Optional: true, - Computed: true, + Type: schema.TypeInt, + Optional: true, + Computed: true, + ConflictsWith: []string{"on_demand_throughput"}, }, "replica": { Type: schema.TypeSet, @@ -483,9 +484,10 @@ func resourceTable() *schema.Resource { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, }, "write_capacity": { - Type: schema.TypeInt, - Computed: true, - Optional: true, + Type: schema.TypeInt, + Computed: true, + Optional: true, + ConflictsWith: []string{"on_demand_throughput"}, }, }, } @@ -1079,7 +1081,7 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter // update only on-demand throughput indexes when switching to PAY_PER_REQUEST if newBillingMode == awstypes.BillingModePayPerRequest { for _, gsiUpdate := range gsiUpdates { - if gsiUpdate.Update.OnDemandThroughput == nil { + if gsiUpdate.Update == nil || (gsiUpdate.Update != nil && gsiUpdate.Update.OnDemandThroughput == nil) { continue } @@ -1736,7 +1738,7 @@ func updateDiffGSI(oldGsi, newGsi []interface{}, billingMode awstypes.BillingMod } otherAttributesChanged := nonKeyAttributesChanged || !reflect.DeepEqual(oldAttributes, newAttributes) - if capacityChanged && !otherAttributesChanged { + if capacityChanged && !otherAttributesChanged && billingMode == awstypes.BillingModeProvisioned { update := awstypes.GlobalSecondaryIndexUpdate{ Update: &awstypes.UpdateGlobalSecondaryIndexAction{ IndexName: aws.String(idxName), @@ -1744,7 +1746,7 @@ func updateDiffGSI(oldGsi, newGsi []interface{}, billingMode awstypes.BillingMod }, } ops = append(ops, update) - } else if onDemandThroughputChanged && !otherAttributesChanged { + } else if onDemandThroughputChanged && !otherAttributesChanged && billingMode == awstypes.BillingModePayPerRequest { update := awstypes.GlobalSecondaryIndexUpdate{ Update: &awstypes.UpdateGlobalSecondaryIndexAction{ IndexName: aws.String(idxName),