From a4bb35447f1bea15f11546d9cb0df07c7ddb4fa1 Mon Sep 17 00:00:00 2001 From: Sunil Kumar Mohanty Date: Fri, 30 Nov 2018 07:20:50 +0200 Subject: [PATCH] returns error when read/write capacity not set when billing mode is PROVISIONED and other small fixes --- aws/resource_aws_dynamodb_table.go | 27 ++++++++++++++++++------- aws/resource_aws_dynamodb_table_test.go | 3 --- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/aws/resource_aws_dynamodb_table.go b/aws/resource_aws_dynamodb_table.go index e5902b366f7..74bdd5b0a8f 100644 --- a/aws/resource_aws_dynamodb_table.go +++ b/aws/resource_aws_dynamodb_table.go @@ -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, @@ -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, }) } @@ -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) diff --git a/aws/resource_aws_dynamodb_table_test.go b/aws/resource_aws_dynamodb_table_test.go index 964f7c479ce..ad284b30d30 100644 --- a/aws/resource_aws_dynamodb_table_test.go +++ b/aws/resource_aws_dynamodb_table_test.go @@ -1258,9 +1258,6 @@ resource "aws_dynamodb_table" "basic-dynamodb-table" { name = "TestTableHashKey" type = "S" } - point_in_time_recovery { - enabled = true - } } `, rName) }