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

F aws lambda invocation crud support #29367

Merged
merged 17 commits into from
May 30, 2023

Conversation

pvbouwel
Copy link
Contributor

@pvbouwel pvbouwel commented Feb 13, 2023

Description

Enhance the aws_lambda_invocation resource by triggering on each resource state transition and therefore allowing full CRUD implementation. Manipulate the triggering JSON payload such that an update/delete has all the information it needs to be processed.

In order to be backwards compatible this behaviour is activated when lifecycle_scope is set to CRUD (defaults to CREATE_ONLY).

For in-depth description of the JSON payload that will be send to invoke the Lambda function see the documentation file in the PR. In short it adds a tf key which has an action (one of create, update, delete) and a prev_input which provides the input that was for the previous invocation (this is required if a Lambda function can manage multiple resources).

Relations

Closes #23555
Closes #21905

References

Output from Acceptance Testing

$ make testacc TESTS=TestAccLambdaInvocation_ PKG=lambda
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/lambda/... -v -count 1 -parallel 20 -run='TestAccLambdaInvocation_'  -timeout 180m
=== RUN   TestAccLambdaInvocation_basic
=== PAUSE TestAccLambdaInvocation_basic
=== RUN   TestAccLambdaInvocation_qualifier
=== PAUSE TestAccLambdaInvocation_qualifier
=== RUN   TestAccLambdaInvocation_complex
=== PAUSE TestAccLambdaInvocation_complex
=== RUN   TestAccLambdaInvocation_triggers
=== PAUSE TestAccLambdaInvocation_triggers
=== RUN   TestAccLambdaInvocation_lifecycle_scopeCRUDCreate
=== PAUSE TestAccLambdaInvocation_lifecycle_scopeCRUDCreate
=== RUN   TestAccLambdaInvocation_lifecycle_scopeCRUDUpdateInput
=== PAUSE TestAccLambdaInvocation_lifecycle_scopeCRUDUpdateInput
=== RUN   TestAccLambdaInvocation_lifecycle_scopeCRUDDestroy
=== PAUSE TestAccLambdaInvocation_lifecycle_scopeCRUDDestroy
=== RUN   TestAccLambdaInvocation_lifecycle_scopeCreateOnlyToCRUD
=== PAUSE TestAccLambdaInvocation_lifecycle_scopeCreateOnlyToCRUD
=== RUN   TestAccLambdaInvocation_terraform_key
=== PAUSE TestAccLambdaInvocation_terraform_key
=== CONT  TestAccLambdaInvocation_basic
=== CONT  TestAccLambdaInvocation_lifecycle_scopeCRUDUpdateInput
=== CONT  TestAccLambdaInvocation_terraform_key
=== CONT  TestAccLambdaInvocation_triggers
=== CONT  TestAccLambdaInvocation_lifecycle_scopeCRUDCreate
=== CONT  TestAccLambdaInvocation_lifecycle_scopeCRUDDestroy
=== CONT  TestAccLambdaInvocation_complex
=== CONT  TestAccLambdaInvocation_lifecycle_scopeCreateOnlyToCRUD
=== CONT  TestAccLambdaInvocation_qualifier
--- PASS: TestAccLambdaInvocation_qualifier (45.42s)
--- PASS: TestAccLambdaInvocation_basic (51.51s)
--- PASS: TestAccLambdaInvocation_lifecycle_scopeCreateOnlyToCRUD (71.07s)
--- PASS: TestAccLambdaInvocation_complex (76.33s)
--- PASS: TestAccLambdaInvocation_lifecycle_scopeCRUDDestroy (78.16s)
--- PASS: TestAccLambdaInvocation_lifecycle_scopeCRUDCreate (82.56s)
--- PASS: TestAccLambdaInvocation_lifecycle_scopeCRUDUpdateInput (83.53s)
--- PASS: TestAccLambdaInvocation_terraform_key (87.48s)
--- PASS: TestAccLambdaInvocation_triggers (120.86s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/lambda	122.665s

Add a lifecycle_scope argument which allows configuring the lambda_invocation
resource to trigger for each lifecycle transition of the terraform resource.
By adding the argument it is possible to maintain backwards compatibility
and enable lambda invocations for resource updates/deletes.

See the updated documentation for a detailed explanation of the feature.
Add test cases for all the different resource state transitions:
- create
- update
- delete

Also verify that the terraform_key argument works as expected.

Refactor existing tests a bit to avoid heavy duplication.

Verified using:
 `make testacc TESTS=TestAccLambdaInvocation_lifecycle_ PKG=lambda`

Both prior and after this commit all the tests pass.
@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.

@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. service/lambda Issues and PRs that pertain to the lambda service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. needs-triage Waiting for first response or review from a maintainer. labels Feb 13, 2023
@pvbouwel pvbouwel marked this pull request as ready for review February 13, 2023 20:14
@pvbouwel pvbouwel changed the title Draft: F aws lambda invocation crud support F aws lambda invocation crud support Feb 13, 2023
@breathingdust breathingdust added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Apr 6, 2023
@jacob-house-vgh
Copy link

Hey @breathingdust @bflad wondering if this is a change that could make it into an upcoming version of the provider. This would be really useful for destroying things that a lambda is used to create at apply-time (for example, releasing IP space in IPAM upon VPC destruction where the lambda was responsible for allocating an available CIDR at plan/apply time).

@breathingdust
Copy link
Member

Hi @jacob-house-vgh 👋 This is in our immediate queue for review and I expect it to be picked up in the next few weeks. Appreciate your patience!

@jar-b jar-b self-assigned this May 23, 2023
Copy link
Member

@jar-b jar-b 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 TESTS=TestAccLambdaInvocation_ PKG=lambda
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/lambda/... -v -count 1 -parallel 20 -run='TestAccLambdaInvocation_'  -timeout 180m

--- PASS: TestAccLambdaInvocation_lifecycle_scopeCRUDCreate (31.40s)
--- PASS: TestAccLambdaInvocation_qualifier (37.04s)
--- PASS: TestAccLambdaInvocation_lifecycle_scopeCRUDUpdateInput (55.27s)
--- PASS: TestAccLambdaInvocation_lifecycle_scopeCreateOnlyToCRUD (61.38s)
--- PASS: TestAccLambdaInvocation_lifecycle_scopeCreateOnlyUpdateInput (67.85s)
--- PASS: TestAccLambdaInvocation_basic (75.85s)
--- PASS: TestAccLambdaInvocation_lifecycle_scopeCRUDDestroy (81.37s)
--- PASS: TestAccLambdaInvocation_terraformKey (82.37s)
--- PASS: TestAccLambdaInvocation_complex (88.28s)
--- PASS: TestAccLambdaInvocation_triggers (88.77s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/lambda     91.921

@jar-b jar-b added this to the v5.1.0 milestone May 26, 2023
@jar-b
Copy link
Member

jar-b commented May 26, 2023

Thanks for your contribution, @pvbouwel - looks great! I've added the v5.1.0 milestone, which will likely be released some time next week.

@jar-b jar-b merged commit 2b317c7 into hashicorp:main May 30, 2023
45 checks passed
@jar-b
Copy link
Member

jar-b commented May 30, 2023

Thanks for your contribution, @pvbouwel! 👍

@github-actions
Copy link

github-actions bot commented Jun 1, 2023

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

github-actions bot commented Jul 2, 2023

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 Jul 2, 2023
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. enhancement Requests to existing resources that expand the functionality or scope. service/lambda Issues and PRs that pertain to the lambda 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.

Add destroy invocation to aws_lambda_invocation resource aws_lambda_invocation : apply vs destroy
4 participants