Skip to content

Commit

Permalink
aws_dynamodb_table: skip payPerRequest updates if throughput not spec…
Browse files Browse the repository at this point in the history
…ified
  • Loading branch information
johnsonaj committed Oct 16, 2024
1 parent 25244b6 commit 2a142ad
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions internal/service/dynamodb/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"},
},
},
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -1736,15 +1738,15 @@ 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),
ProvisionedThroughput: expandProvisionedThroughput(newMap, billingMode),
},
}
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),
Expand Down

0 comments on commit 2a142ad

Please sign in to comment.