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

resource/aws_dynamodb_table: Update and validate attributes #3194

Merged
merged 1 commit into from
Mar 20, 2018

Conversation

radeksimko
Copy link
Member

Fixes #1424

Test results

=== RUN   TestAccAWSDynamoDbTable_attributeUpdateValidation
--- PASS: TestAccAWSDynamoDbTable_attributeUpdateValidation (2.97s)
=== RUN   TestAccAWSDynamoDbTable_tags
--- PASS: TestAccAWSDynamoDbTable_tags (53.09s)
=== RUN   TestAccAWSDynamoDbTable_importTimeToLive
--- PASS: TestAccAWSDynamoDbTable_importTimeToLive (53.51s)
=== RUN   TestAccAWSDynamoDbTable_ttl
--- PASS: TestAccAWSDynamoDbTable_ttl (113.45s)
=== RUN   TestAccAWSDynamoDbTable_importBasic
--- PASS: TestAccAWSDynamoDbTable_importBasic (127.66s)
=== RUN   TestAccAWSDynamoDbTable_importTags
--- PASS: TestAccAWSDynamoDbTable_importTags (127.85s)
=== RUN   TestAccAWSDynamoDbTable_gsiUpdateNonKeyAttributes
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateNonKeyAttributes (146.59s)
=== RUN   TestAccAWSDynamoDbTable_streamSpecification
--- PASS: TestAccAWSDynamoDbTable_streamSpecification (168.25s)
=== RUN   TestAccAWSDynamoDbTable_gsiUpdateCapacity
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateCapacity (312.93s)
=== RUN   TestAccAWSDynamoDbTable_gsiUpdateOtherAttributes
--- PASS: TestAccAWSDynamoDbTable_gsiUpdateOtherAttributes (452.91s)
=== RUN   TestAccAWSDynamoDbTable_attributeUpdate
--- PASS: TestAccAWSDynamoDbTable_attributeUpdate (458.46s)
=== RUN   TestAccAWSDynamoDbTable_basic
--- PASS: TestAccAWSDynamoDbTable_basic (461.79s)

@radeksimko radeksimko added bug Addresses a defect in current functionality. service/dynamodb Issues and PRs that pertain to the dynamodb service. labels Jan 30, 2018
@radeksimko radeksimko requested a review from bflad January 30, 2018 13:09
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jan 30, 2018
@bflad
Copy link
Contributor

bflad commented Jan 30, 2018

FYI this requires a rebase for aws/validators.go

Can you find documentation to support this? Indexes and attributes are tightly coupled (DynamoDB disallows unindexed attributes) I don't remember this being a limitation of the service nor does it explicitly state that in the DynamoDB documentation.

@radeksimko radeksimko force-pushed the b-dynamodb-attr-update branch from ad32991 to 0d8443b Compare January 30, 2018 16:16
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jan 30, 2018
@radeksimko
Copy link
Member Author

Can you find documentation to support this? Indexes and attributes are tightly coupled (DynamoDB disallows unindexed attributes) I don't remember this being a limitation of the service nor does it explicitly state that in the DynamoDB documentation.

I came to that conclusion after:

a. Getting this error message:

ValidationException: One or more parameter values were invalid: Some AttributeDefinitions are not used. AttributeDefinitions: [TestGSIRangeKey, TestTableHashKey, TestLSIRangeKey, TestTableRangeKey], keys used: [TestTableRangeKey, TestTableHashKey, TestLSIRangeKey]
	status code: 400, request id: 9A6QGJAD38PD94IV10GJ8G2DM3VV4KQNSO5AEMVJF66Q9ASUAAJG

b. When DynamoDB removed an attribute during UpdateTable which was removing the only index that was referencing that field.

I however agree it's not very clear and we should get a confirmation from AWS support and perhaps paste it here. I'll reach out to them.

@radeksimko
Copy link
Member Author

AWS support just confirmed what I wrote above:

00:17:12 PM radek: right, that's what I thought, so AttributeDefinitions in the API is basically a schema for indexes. It obviously doesn't define schema for records (as DDB is schemaless), but any attribute which is used in KeySchema and/or in GSI and/or LSI has to be in that list (AttributeDefinitions)?
00:18:43 PM AWS: yup..

Admittedly my comment may be suggesting DynamoDB requires you to define schema for all attributes, but that's partially because of how much the resource schema is drifted from API's naming convention. Maybe if attribute was attribute_definition it would be slightly more obvious? I'm open to suggestions.

@bflad
Copy link
Contributor

bflad commented Jan 31, 2018

Ah okay - this makes more sense. Thank you for clarifying here!

I just wanted to be sure this configuration is still valid (you can have attribute definitions that are not indexed):

resource "aws_dynamodb_table" "basic-dynamodb-table" {
  name = "%s"
  read_capacity = 10
  write_capacity = 10
  hash_key = "staticHashKey"

  attribute {
    name = "staticHashKey"
    type = "S"
  }
 
  attribute {
    name = "indexed"
    type = "%s"
  }

  attribute {
    name = "notIndexed"
    type = "%s"
  }
 
   global_secondary_index {
     name = "gsiName"
     hash_key = "indexed"
     write_capacity = 10
     read_capacity = 10
     projection_type = "KEYS_ONLY"
   }
 }

Maybe some simple rewording of comments/variable names like this would help me personally (and potentially other future code readers) 😄

  • s/DynamoDB disallows unindexed attributes/DynamoDB requires attribute definitions for all indexed attributes/
  • s/Check if all attributes are indexed/Check if all indexed attributes have an attribute definition/
  • s/unusedAttributes/missingAttributeDefintions/

What do you think? Otherwise, I think this is good to go.

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay it turns out that I completely misunderstood AttributeDefinition under the hood that they cannot specify extra attributes (a limitation on the AWS side). Knowing that, this PR looks great once its rebased. 👍

@bflad bflad added this to the v1.9.0 milestone Jan 31, 2018
@radeksimko radeksimko force-pushed the b-dynamodb-attr-update branch from 0d8443b to d0effb7 Compare January 31, 2018 15:27
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jan 31, 2018
@radeksimko radeksimko force-pushed the b-dynamodb-attr-update branch from d0effb7 to 5f9d283 Compare January 31, 2018 15:30
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jan 31, 2018
@radeksimko radeksimko force-pushed the b-dynamodb-attr-update branch from 5f9d283 to 2a73882 Compare January 31, 2018 15:31
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jan 31, 2018
@radeksimko radeksimko force-pushed the b-dynamodb-attr-update branch from 2a73882 to 823cad4 Compare January 31, 2018 15:31
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jan 31, 2018
@radeksimko
Copy link
Member Author

Currently blocked by hashicorp/terraform#17261

@radeksimko radeksimko added the upstream-terraform Addresses functionality related to the Terraform core binary. label Feb 1, 2018
@radeksimko radeksimko force-pushed the b-dynamodb-attr-update branch from 3575e8b to 0296e20 Compare February 1, 2018 13:08
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Feb 1, 2018
@radeksimko radeksimko removed this from the v1.9.0 milestone Feb 9, 2018
@bflad
Copy link
Contributor

bflad commented Feb 24, 2018

Update: we're still waiting on upstream Terraform core 0.11.4 release (rather than vendoring a commit SHA)

@bflad bflad added this to the v1.12.0 milestone Mar 9, 2018
@bflad
Copy link
Contributor

bflad commented Mar 16, 2018

@radeksimko upstream Terraform 0.11.4 has been vendored! 😄

@radeksimko radeksimko force-pushed the b-dynamodb-attr-update branch from 0296e20 to 05cdd35 Compare March 20, 2018 12:55
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Mar 20, 2018
@radeksimko radeksimko removed the upstream-terraform Addresses functionality related to the Terraform core binary. label Mar 20, 2018
@radeksimko
Copy link
Member Author

Rebased & ran related acceptance tests - all green, so I'm going to merge this.

@radeksimko radeksimko merged commit e344ec7 into master Mar 20, 2018
@radeksimko radeksimko deleted the b-dynamodb-attr-update branch March 20, 2018 14:27
@bflad
Copy link
Contributor

bflad commented Mar 23, 2018

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

@Venkat2811
Copy link

Venkat2811 commented Jun 4, 2018

We are using Terraform 0.10.6 version. Any idea on how to overcome this issue ?

@ghost
Copy link

ghost commented Apr 5, 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 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/dynamodb Issues and PRs that pertain to the dynamodb service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

state does not update after running terraform apply
3 participants