Terraform-provider-aws: Unable to change DynamoDB billing_mode from PAY_PER_REQUEST to PROVISIONED when using GSIs

Created on 5 Feb 2019  ·  6Comments  ·  Source: hashicorp/terraform-provider-aws

When updating a DynamoDB table with one or more global secondary indexes, changing billing_mode from PAY_PER_REQUEST to PROVISIONED, the update fails to apply. Terraform tries to create a new GSI with given read & write capacity, while the existing GSI is left with "0" capacity which makes it fail due to invalid parameter (ProvisionedThroughput must be specified when BillingMode is PROVISIONED).

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.11.10
provider.aws v1.57.0

Affected Resource(s)

  • aws_dynamodb_table

Terraform Configuration Files

resource "aws_dynamodb_table" "users" {
  name           = "users"
  billing_mode   = "PROVISIONED"
  read_capacity  = "10"
  write_capacity = "10"
  hash_key       = "uuid"

  attribute {
    name = "uuid"
    type = "S"
  }

  attribute {
    name = "nick_lower"
    type = "S"
  }

  attribute {
    name = "discriminator"
    type = "S"
  }

  global_secondary_index {
    name               = "username"
    hash_key           = "nick_lower"
    range_key          = "discriminator"
    write_capacity     = "10"
    read_capacity      = "10"
    projection_type    = "INCLUDE"
    non_key_attributes = [ "nick" ]
  }
}

Expected Behavior

Billing mode should have changed along with read & write capacities for the table and global secondary index(es).

Actual Behavior

terraform apply exits with an error.

Output:

aws_dynamodb_table.users: Modifying... (ID: users)
  billing_mode:                                           "PAY_PER_REQUEST" => "PROVISIONED"
  global_secondary_index.3667214579.hash_key:             "nick_lower" => ""
  global_secondary_index.3667214579.name:                 "username" => ""
  global_secondary_index.3667214579.non_key_attributes.#: "1" => "0"
  global_secondary_index.3667214579.non_key_attributes.0: "nick" => ""
  global_secondary_index.3667214579.projection_type:      "INCLUDE" => ""
  global_secondary_index.3667214579.range_key:            "discriminator" => ""
  global_secondary_index.3667214579.read_capacity:        "0" => "0"
  global_secondary_index.3667214579.write_capacity:       "0" => "0"
  global_secondary_index.3853577238.hash_key:             "" => "nick_lower"
  global_secondary_index.3853577238.name:                 "" => "username"
  global_secondary_index.3853577238.non_key_attributes.#: "0" => "1"
  global_secondary_index.3853577238.non_key_attributes.0: "" => "nick"
  global_secondary_index.3853577238.projection_type:      "" => "INCLUDE"
  global_secondary_index.3853577238.range_key:            "" => "discriminator"
  global_secondary_index.3853577238.read_capacity:        "" => "10"
  global_secondary_index.3853577238.write_capacity:       "" => "10"
  read_capacity:                                          "0" => "10"
  write_capacity:                                         "0" => "10"
Releasing state lock. This may take a few moments...

Error: Error applying plan:

1 error(s) occurred:

* aws_dynamodb_table.users: 1 error(s) occurred:

* aws_dynamodb_table.users: Error updating DynamoDB Table (users) billing mode: ValidationException: One or more parameter values were invalid: ProvisionedThroughput must be specified when BillingMode is PROVISIONED
    status code: 400, request id: E1T2ARB74U6K2FFET5M2U878MJVV4KQNSO5AEMVJF66Q9ASUAAJG

Steps to Reproduce

  1. Have a TF configuration with DynamoDB table applied, including one or more global secondary indexes and PAY_PER_REQUEST as billing_mode
  2. Change billing_mode in aws_dynamodb_table configuration from PAY_PER_REQUEST to PROVISIONED
  3. Run terraform apply
bug servicdynamodb

All 6 comments

I am double checking this against the currently unreleased fix we merged yesterday (#7363) via additional acceptance testing and will report back shortly.

It looks like GSIs still have a similar issue when going PAY_BY_REQUEST to PROVISIONED:

--- FAIL: TestAccAWSDynamoDbTable_BillingModeUpdateWithGSI (141.28s)
    testing.go:538: Step 1 error: Error applying: 1 error occurred:
            * aws_dynamodb_table.basic-dynamodb-table: 1 error occurred:
            * aws_dynamodb_table.basic-dynamodb-table: Error updating DynamoDB Table (TerraformTestTable--1308651219154584046) billing mode: ValidationException: One or more parameter values were invalid: ProvisionedThroughput must be specified for index: TestTableGSI

I will submit a fix later today.

Fix submitted: #7453

The fix for this has been merged and will release with version 1.59.0 of the Terraform AWS Provider, likely middle of this week. 👍

This has been released in version 1.59.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings