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

New Resource: aws_cloudfrontkeyvaluestore_key #36534

Merged

Conversation

brittandeyoung
Copy link
Collaborator

Description

This pull requests adds the ability to create and manage Cloudfront Key Value Store Keys with terraform utilizing the aws_cloudfrontkeyvaluestore_key resource.

Relations

Closes #35793

References

Output from Acceptance Testing

% make testacc TESTARGS='-run=TestAccCloudFrontKeyValueStoreKey' PKG=cloudfrontkeyvaluestore
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.21.8 test ./internal/service/cloudfrontkeyvaluestore/... -v -count 1 -parallel 20  -run=TestAccCloudFrontKeyValueStoreKey -timeout 360m
=== RUN   TestAccCloudFrontKeyValueStoreKey_basic
=== PAUSE TestAccCloudFrontKeyValueStoreKey_basic
=== RUN   TestAccCloudFrontKeyValueStoreKey_value
=== PAUSE TestAccCloudFrontKeyValueStoreKey_value
=== RUN   TestAccCloudFrontKeyValueStoreKey_disappears
=== PAUSE TestAccCloudFrontKeyValueStoreKey_disappears
=== CONT  TestAccCloudFrontKeyValueStoreKey_basic
=== CONT  TestAccCloudFrontKeyValueStoreKey_value
=== CONT  TestAccCloudFrontKeyValueStoreKey_disappears
--- PASS: TestAccCloudFrontKeyValueStoreKey_basic (28.79s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_disappears (37.95s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_value (46.48s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/cloudfrontkeyvaluestore    52.515s
...

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.

@github-actions github-actions bot added size/XL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. generators Relates to code generators. service/cloudfrontkeyvaluestore Issues and PRs that pertain to the cloudfrontkeyvaluestore service. labels Mar 22, 2024
@terraform-aws-provider terraform-aws-provider bot added needs-triage Waiting for first response or review from a maintainer. external-maintainer Contribution from a trusted external contributor. labels Mar 22, 2024
@brittandeyoung brittandeyoung added the new-resource Introduces a new resource. label Mar 22, 2024
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Mar 25, 2024
@ewbankkit ewbankkit self-assigned this Mar 26, 2024
@terraform-aws-provider terraform-aws-provider bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Mar 26, 2024
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=TestAccCloudFrontKeyValueStoreKey_' PKG=cloudfrontkeyvaluestore
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.21.8 test ./internal/service/cloudfrontkeyvaluestore/... -v -count 1 -parallel 20  -run=TestAccCloudFrontKeyValueStoreKey_ -timeout 360m
=== RUN   TestAccCloudFrontKeyValueStoreKey_basic
=== PAUSE TestAccCloudFrontKeyValueStoreKey_basic
=== RUN   TestAccCloudFrontKeyValueStoreKey_value
=== PAUSE TestAccCloudFrontKeyValueStoreKey_value
=== RUN   TestAccCloudFrontKeyValueStoreKey_disappears
=== PAUSE TestAccCloudFrontKeyValueStoreKey_disappears
=== CONT  TestAccCloudFrontKeyValueStoreKey_basic
=== CONT  TestAccCloudFrontKeyValueStoreKey_disappears
=== CONT  TestAccCloudFrontKeyValueStoreKey_value
--- PASS: TestAccCloudFrontKeyValueStoreKey_disappears (48.63s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_basic (55.16s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_value (64.36s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/cloudfrontkeyvaluestore	75.352s

@ewbankkit
Copy link
Contributor

@brittandeyoung Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit b8f37b6 into hashicorp:main Mar 26, 2024
45 checks passed
@github-actions github-actions bot added this to the v5.43.0 milestone Mar 26, 2024
@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Mar 28, 2024
Copy link

This functionality has been released in v5.43.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!

@lawliet89
Copy link
Contributor

lawliet89 commented Apr 2, 2024

@brittandeyoung Thanks for adding this resource.

I think this resource needs to have some form of mutex or locking to prevent multiple key writes from happening at the same time.

Consider the following plan where multiple keys are being created

image

During the apply, the following errors will appear

image

I suspect this precondition is due to a race condition of multiple keys are being created in parallel and their etag being invalidated after the first one is created.

@brittandeyoung
Copy link
Collaborator Author

brittandeyoung commented Apr 2, 2024

@lawliet89 From writing the resource, it appears to update the etag of the key_value_store each time it puts an item. I think your observation is correct that it is possible multiple updates at once could cause a race condition where there are multiple updates taking place at once. I will do some digging into the best way to solve this. I wonder if having the key_value_store_arn as an attribute would allow chaining the resources using either explicitly defined dependencies, or implicit dependencies by passing the arn into the next resource like so (This is sudo code that would not work currently).

resource "aws_cloudfront_key_value_store" "example" {
  name    = "ExampleKeyValueStore"
  comment = "This is an example key value store"
}

resource "aws_cloudfrontkeyvaluestore_key" "example1" {
  key_value_store_arn = aws_cloudfront_key_value_store.example.arn
  key                 = "Test Key"
  value               = "Test Value"
}

resource "aws_cloudfrontkeyvaluestore_key" "example2" {
  key_value_store_arn = aws_cloudfrontkeyvaluestore_key.example1.key_value_store_arn
  key                 = "Test Key"
  value               = "Test Value"
}

Do you think me adding this would solve for your use case?

@lawliet89
Copy link
Contributor

@brittandeyoung This wouldn't work well when for_each is used to create keys.

I was thinking of doing something similar to aws_security_group_rule

conns.GlobalMutexKV.Lock(securityGroupID)
defer conns.GlobalMutexKV.Unlock(securityGroupID)

The resource locks a mutex before it does anything, and defers an unlock when the function returns. The mutex key can be the ID/ARN of the KeyValueStore itself.

@brittandeyoung
Copy link
Collaborator Author

brittandeyoung commented Apr 4, 2024

@lawliet89 I see, I was pointed to a similar method by the provider team. I will get a PR ready to resolve.

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 May 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. external-maintainer Contribution from a trusted external contributor. generators Relates to code generators. new-resource Introduces a new resource. service/cloudfrontkeyvaluestore Issues and PRs that pertain to the cloudfrontkeyvaluestore service. size/XL 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.

New Resource: aws_cloudfrontkeyvaluestore_key
4 participants