Skip to content

Commit

Permalink
returns error when read/write capacity not set when billing mode is P…
Browse files Browse the repository at this point in the history
…ROVISIONED and other small fixes
  • Loading branch information
Sunil Kumar Mohanty committed Nov 30, 2018
1 parent f2d56e2 commit a4bb354
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
27 changes: 20 additions & 7 deletions aws/resource_aws_dynamodb_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func resourceAwsDynamoDbTable() *schema.Resource {
},
"write_capacity": {
Type: schema.TypeInt,
Required: false,
Optional: true,
},
"read_capacity": {
Type: schema.TypeInt,
Required: false,
Optional: true,
},
"attribute": {
Type: schema.TypeSet,
Expand Down Expand Up @@ -294,9 +294,15 @@ func resourceAwsDynamoDbTableCreate(d *schema.ResourceData, meta interface{}) er
}

if d.Get("billing_mode").(string) == dynamodb.BillingModeProvisioned {
v_read, ok_read := d.GetOk("read_capacity")
v_write, ok_write := d.GetOk("write_capacity")
if !ok_read || !ok_write {
return fmt.Errorf("Read and Write capacity should be set when billing mode is PROVISIONED")
}

req.ProvisionedThroughput = expandDynamoDbProvisionedThroughput(map[string]interface{}{
"read_capacity": d.Get("read_capacity"),
"write_capacity": d.Get("write_capacity"),
"read_capacity": v_read,
"write_capacity": v_write,
})
}

Expand Down Expand Up @@ -379,14 +385,21 @@ func resourceAwsDynamoDbTableUpdate(d *schema.ResourceData, meta interface{}) er
BillingMode: aws.String(d.Get("billing_mode").(string)),
}
if d.Get("billing_mode").(string) == dynamodb.BillingModeProvisioned {

v_read, ok_read := d.GetOk("read_capacity")
v_write, ok_write := d.GetOk("write_capacity")
if !ok_read || !ok_write {
return fmt.Errorf("Read and Write capacity should be set when billing mode is PROVISIONED")
}

req.ProvisionedThroughput = expandDynamoDbProvisionedThroughput(map[string]interface{}{
"read_capacity": d.Get("read_capacity"),
"write_capacity": d.Get("write_capacity"),
"read_capacity": v_read,
"write_capacity": v_write,
})
}
_, err := conn.UpdateTable(req)
if err != nil {
return err
return fmt.Errorf("Error updating DynamoDB Table (%s) billing mode: %s", d.Id(), err)
}
if err := waitForDynamoDbTableToBeActive(d.Id(), d.Timeout(schema.TimeoutUpdate), conn); err != nil {
return fmt.Errorf("Error waiting for DynamoDB Table update: %s", err)
Expand Down
3 changes: 0 additions & 3 deletions aws/resource_aws_dynamodb_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1258,9 +1258,6 @@ resource "aws_dynamodb_table" "basic-dynamodb-table" {
name = "TestTableHashKey"
type = "S"
}
point_in_time_recovery {
enabled = true
}
}
`, rName)
}
Expand Down

0 comments on commit a4bb354

Please sign in to comment.