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_table_item create: use ConditionExpression #27517

Merged
merged 6 commits into from
Nov 16, 2022
Merged

dynamodb_table_item create: use ConditionExpression #27517

merged 6 commits into from
Nov 16, 2022

Conversation

milescrabill
Copy link
Member

Description

  • per AWS' documentation Expected is a legacy parameter and should no longer be used
  • should fix r/aws_dynamodb_table_item: cannot create when the hash key already exists #26080, or at least be more predictable, while maintaining the same behavior for tables without composite keys. It seems like Expected is only checking that the hash key does not exist whereas this ConditionExpression will check whether an item with the same hash key and range key does not exist
  • this blog post explains how this ConditionExpression works, essentially the condition will always be compared against a single item and so it is sufficient to just check for the existence of the hash key

Relations

Relates #27503
Closes #26080

References

- per [AWS' documentation](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.Expected.html) `Expected` is a legacy parameter and should no longer be used
- should fix #26080, or at least be more predictable, while maintaining the same behavior for tables without composite keys. It seems like `Expected` is only checking that the hash key does not exist whereas this `ConditionExpression` will check whether an item with the same hash key _and_ range key does not exist
- [this blog post](https://www.alexdebrie.com/posts/dynamodb-condition-expressions/) explains how this `ConditionExpression` works, essentially the condition will always be compared against a single item and so it is sufficient to just check for the existence of the hash key
@github-actions github-actions bot added size/XS Managed by automation to categorize the size of a PR. service/dynamodb Issues and PRs that pertain to the dynamodb service. needs-triage Waiting for first response or review from a maintainer. labels Oct 27, 2022
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Oct 27, 2022
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome @milescrabill 👋

It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTOR guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.

Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.

Thanks again, and welcome to the community! 😃

@ewbankkit ewbankkit added the bug Addresses a defect in current functionality. label Oct 27, 2022
@ewbankkit ewbankkit added enhancement Requests to existing resources that expand the functionality or scope. and removed bug Addresses a defect in current functionality. labels Oct 27, 2022
@github-actions github-actions bot added size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. and removed size/XS Managed by automation to categorize the size of a PR. labels Oct 27, 2022
ewbankkit
ewbankkit previously approved these changes Oct 27, 2022
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

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

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccDynamoDBTableItem_' PKG=dynamodb ACCTEST_PARALLELISM=2 
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/dynamodb/... -v -count 1 -parallel 2  -run=TestAccDynamoDBTableItem_ -timeout 180m
=== RUN   TestAccDynamoDBTableItem_basic
=== PAUSE TestAccDynamoDBTableItem_basic
=== RUN   TestAccDynamoDBTableItem_rangeKey
=== PAUSE TestAccDynamoDBTableItem_rangeKey
=== RUN   TestAccDynamoDBTableItem_withMultipleItems
=== PAUSE TestAccDynamoDBTableItem_withMultipleItems
=== RUN   TestAccDynamoDBTableItem_withDuplicateItemsSameRangeKey
=== PAUSE TestAccDynamoDBTableItem_withDuplicateItemsSameRangeKey
=== RUN   TestAccDynamoDBTableItem_withDuplicateItemsDifferentRangeKey
=== PAUSE TestAccDynamoDBTableItem_withDuplicateItemsDifferentRangeKey
=== RUN   TestAccDynamoDBTableItem_wonkyItems
=== PAUSE TestAccDynamoDBTableItem_wonkyItems
=== RUN   TestAccDynamoDBTableItem_update
=== PAUSE TestAccDynamoDBTableItem_update
=== RUN   TestAccDynamoDBTableItem_updateWithRangeKey
=== PAUSE TestAccDynamoDBTableItem_updateWithRangeKey
=== RUN   TestAccDynamoDBTableItem_disappears
=== PAUSE TestAccDynamoDBTableItem_disappears
=== CONT  TestAccDynamoDBTableItem_basic
=== CONT  TestAccDynamoDBTableItem_wonkyItems
--- PASS: TestAccDynamoDBTableItem_basic (25.47s)
=== CONT  TestAccDynamoDBTableItem_withDuplicateItemsSameRangeKey
--- PASS: TestAccDynamoDBTableItem_wonkyItems (28.14s)
=== CONT  TestAccDynamoDBTableItem_withDuplicateItemsDifferentRangeKey
--- PASS: TestAccDynamoDBTableItem_withDuplicateItemsSameRangeKey (17.61s)
=== CONT  TestAccDynamoDBTableItem_withMultipleItems
--- PASS: TestAccDynamoDBTableItem_withDuplicateItemsDifferentRangeKey (26.25s)
=== CONT  TestAccDynamoDBTableItem_rangeKey
--- PASS: TestAccDynamoDBTableItem_withMultipleItems (26.49s)
=== CONT  TestAccDynamoDBTableItem_updateWithRangeKey
--- PASS: TestAccDynamoDBTableItem_rangeKey (26.05s)
=== CONT  TestAccDynamoDBTableItem_disappears
--- PASS: TestAccDynamoDBTableItem_disappears (27.43s)
=== CONT  TestAccDynamoDBTableItem_update
--- PASS: TestAccDynamoDBTableItem_updateWithRangeKey (40.38s)
--- PASS: TestAccDynamoDBTableItem_update (38.15s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/dynamodb	150.180s

@ewbankkit ewbankkit self-requested a review October 27, 2022 20:01
@ewbankkit ewbankkit dismissed their stale review October 27, 2022 20:02

Needs additional test

@YakDriver YakDriver self-assigned this Nov 16, 2022
Copy link
Member

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

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

Looks good to me 🎉

% make testacc TESTARGS='-run=TestAccDynamoDBTableItem_' PKG=dynamodb ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/dynamodb/... -v -count 1 -parallel 2  -run=TestAccDynamoDBTableItem_ -timeout 180m
go: downloading github.com/aws/aws-sdk-go-v2/service/auditmanager v1.20.11
go: downloading github.com/aws/aws-sdk-go-v2/service/ivschat v1.0.21
go: downloading github.com/aws/aws-sdk-go-v2/service/scheduler v1.0.1
go: downloading github.com/aws/aws-sdk-go-v2/service/ssm v1.32.1
=== RUN   TestAccDynamoDBTableItem_basic
=== PAUSE TestAccDynamoDBTableItem_basic
=== RUN   TestAccDynamoDBTableItem_rangeKey
=== PAUSE TestAccDynamoDBTableItem_rangeKey
=== RUN   TestAccDynamoDBTableItem_withMultipleItems
=== PAUSE TestAccDynamoDBTableItem_withMultipleItems
=== RUN   TestAccDynamoDBTableItem_withDuplicateItemsSameRangeKey
=== PAUSE TestAccDynamoDBTableItem_withDuplicateItemsSameRangeKey
=== RUN   TestAccDynamoDBTableItem_withDuplicateItemsDifferentRangeKey
=== PAUSE TestAccDynamoDBTableItem_withDuplicateItemsDifferentRangeKey
=== RUN   TestAccDynamoDBTableItem_wonkyItems
=== PAUSE TestAccDynamoDBTableItem_wonkyItems
=== RUN   TestAccDynamoDBTableItem_update
=== PAUSE TestAccDynamoDBTableItem_update
=== RUN   TestAccDynamoDBTableItem_updateWithRangeKey
=== PAUSE TestAccDynamoDBTableItem_updateWithRangeKey
=== RUN   TestAccDynamoDBTableItem_disappears
=== PAUSE TestAccDynamoDBTableItem_disappears
=== CONT  TestAccDynamoDBTableItem_basic
=== CONT  TestAccDynamoDBTableItem_wonkyItems
--- PASS: TestAccDynamoDBTableItem_basic (27.68s)
=== CONT  TestAccDynamoDBTableItem_updateWithRangeKey
--- PASS: TestAccDynamoDBTableItem_wonkyItems (30.16s)
=== CONT  TestAccDynamoDBTableItem_disappears
--- PASS: TestAccDynamoDBTableItem_disappears (26.40s)
=== CONT  TestAccDynamoDBTableItem_withDuplicateItemsSameRangeKey
--- PASS: TestAccDynamoDBTableItem_updateWithRangeKey (42.22s)
=== CONT  TestAccDynamoDBTableItem_withDuplicateItemsDifferentRangeKey
--- PASS: TestAccDynamoDBTableItem_withDuplicateItemsSameRangeKey (20.79s)
=== CONT  TestAccDynamoDBTableItem_update
--- PASS: TestAccDynamoDBTableItem_withDuplicateItemsDifferentRangeKey (26.14s)
=== CONT  TestAccDynamoDBTableItem_withMultipleItems
--- PASS: TestAccDynamoDBTableItem_update (41.09s)
=== CONT  TestAccDynamoDBTableItem_rangeKey
--- PASS: TestAccDynamoDBTableItem_withMultipleItems (25.53s)
--- PASS: TestAccDynamoDBTableItem_rangeKey (25.80s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/dynamodb	146.204s

@github-actions
Copy link

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

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 18, 2022
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. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

r/aws_dynamodb_table_item: cannot create when the hash key already exists
3 participants