Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamoDB On-Demand doesn't work with GSIs #6736

Closed
sbogacz opened this issue Dec 6, 2018 · 15 comments · Fixed by #6737
Closed

DynamoDB On-Demand doesn't work with GSIs #6736

sbogacz opened this issue Dec 6, 2018 · 15 comments · Fixed by #6737
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/dynamodb Issues and PRs that pertain to the dynamodb service.
Milestone

Comments

@sbogacz
Copy link
Contributor

sbogacz commented Dec 6, 2018

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.51.0

Affected Resource(s)

  • aws_dynamodb_table

Terraform Configuration Files

resource "aws_dynamodb_table" "lvs" {
  name = "lvs-${var.environment}"
  tags = "${var.tags}"

  hash_key  = "Account"
  range_key = "SortKey"

  billing_mode = "PAY_PER_REQUEST"

  # Streams have to be enabled for DynamoDB global table
  # https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/globaltables_reqs_bestpractices.html
  stream_enabled = true

  stream_view_type = "NEW_AND_OLD_IMAGES"

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

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

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

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

  global_secondary_index {
    name            = "GSI"
    hash_key        = "CancelStatus"
    range_key       = "AccountOffering"
    projection_type = "KEYS_ONLY"
  }
}

Expected Behavior

I expected to be able to create a DynamoDB table with the new PAY_PER_REQUEST billing option set, and use the table with GSIs.

Actual Behavior

I tried to not specify the read and write capacity units for my GSIs, but that led to the following error at the plan phase, since the schema marks the provisioned throughput arguments as required:

Error: module.lvs.module.lvs_table_region1.aws_dynamodb_table.lvs: "global_secondary_index.0.read_capacity": required field is not set

When I tried to specify a dummy value, it fails the call to the AWS DynamoDB API:

* module.lvs.module.lvs_table_region3.aws_dynamodb_table.lvs: 1 error(s) occurred:

* aws_dynamodb_table.lvs: ValidationException: One or more parameter values were invalid: ProvisionedThroughput should not be specified for index: GSI when BillingMode is PAY_PER_REQUEST
	status code: 400, request id: 1IVRLJOG48QHPG3FO4UAJUV347VV4KQNSO5AEMVJF66Q9ASUAAJG

Steps to Reproduce

With no capacity specified in the GSI it fails at plan time.

With dummy capacity values specified it fails at apply time.

@sbogacz
Copy link
Contributor Author

sbogacz commented Dec 6, 2018

I made a PR with the fix for resource creation, currently still pending update logic fix: #6737

@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/dynamodb Issues and PRs that pertain to the dynamodb service. labels Dec 6, 2018
@LiborVilimekMassive
Copy link

Confirming the same issue

@AntonBazhal
Copy link

@bflad I don't understand why this issue is not labelled as a bug and not prioritized accordingly. It essentially makes billing_mode feature impossible to use.

@donglaizhang
Copy link

Same issue, and it should be a high prioritized defect.

@Hinidu
Copy link
Contributor

Hinidu commented Dec 10, 2018

There is a workaround for this issue: #6632 (comment)

@macbutch
Copy link
Contributor

The workaround does not appear to always work. Our integration tests spin up a new stack on each run and they always fail to create the table. We will be stuck with provisioned capacity for now (at least for our integration tests).

@sbogacz
Copy link
Contributor Author

sbogacz commented Dec 11, 2018

@macbutch the workaround would only work on successive applies I think. The PR I opened above (#6737 ) should fix the issue.

@LiborVilimekMassive
Copy link

@macbutch - yea, I use workaround around that workaround :) - first created table and indexes with provisioned capacity, then run again with changed it to on-demand and set the 0 as read/write capacity.

Then terraform throw few errors, but it works and table and indexes are on-demand.

@donglaizhang
Copy link

There is a workaround for this issue: #6632 (comment)

This solution works for me, set read/write capacity to "0" in GIS when applied 'pay_per_request'.

Thanks.

@bflad bflad added this to the v1.52.0 milestone Dec 13, 2018
@bflad
Copy link
Contributor

bflad commented Dec 13, 2018

Support for on-demand billing with global secondary indices has been merged and will release with version 1.52.0 of the AWS provider, likely later today. 👍

@bflad
Copy link
Contributor

bflad commented Dec 13, 2018

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

@brikis98
Copy link
Contributor

Just hit this issue with version 1.52.0 of the AWS provider. Code:

resource "aws_dynamodb_table" "foo" {
  name         = "foo"
  billing_mode = "PAY_PER_REQUEST"

  hash_key = "id"

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

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

  global_secondary_index {
    name               = "UserNameGlobalIndex"
    hash_key           = "userName"
    projection_type    = "ALL"
  }
}

Log output:

$ terraform apply

...

* provider.aws: version = "~> 1.52"

...

Error: Error applying plan:

1 error(s) occurred:

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

* aws_dynamodb_table.foo: InvalidParameter: 1 validation error(s) found.
- missing required field, UpdateTableInput.GlobalSecondaryIndexUpdates[0].Update.ProvisionedThroughput.

One wrinkle in our use case: our DynamoDB table was already created with billing_mode set to PROVISIONED and we updated it to PAY_PER_REQUEST, removing the read_capacity and write_capacity settings everywhere. Not sure if that triggers a different code path / bug?

@brikis98
Copy link
Contributor

Note that the workaround in #6632 (comment) (setting read and write capacity to 0 in GIS) solved it in our situation too.

@LiborVilimekMassive
Copy link

@brikis98 - have you tried to run it twice? Had similar problem, but it disappeared next time I run it.

I suppose it was just because it was still PROVISIONED when these fields missing as changing to on-demand takes a while (still the Terraform should know what to do in such case)

@ghost
Copy link

ghost commented Apr 1, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/dynamodb Issues and PRs that pertain to the dynamodb service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants