-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
F aws lambda invocation crud support (#29367)
* feature(lambda): Support CRUD 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. * testing: Add test cases for CRUD functionality 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. * Add changelog * refactor: test refactor and add test for onboarding to CRUD scope * r/aws_lambda_invocation(test): add context to test helpers * r/aws_lambda_invocation(test): use function local ssm parameter name * r/aws_lambda_invocation(test): tidy test functions * r/aws_lambda_invocation: tidy helper functions * r/aws_lambda_invocation: force new on input change in create only mode * chore: terrafmt acctest linting * chore(providerlint): avoid hardcoded partitions * chore(semgrep): prefer WithContext api calls * chore(semgrep): test config func naming * chore(semgrep): avoid lambda in func, const names * r/aws_lambda_invocation: adjust CRUD lifecycle docs * chore(markdown-lint): spacing before ordered list --------- Co-authored-by: Jared Baker <[email protected]>
- Loading branch information
Showing
8 changed files
with
588 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:enhancement | ||
resource/aws_lambda_invocation: Add lifecycle_scope CRUD to invoke on each resource state transition | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package lambda | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// customizeDiffValidateInput validates that `input` is JSON object when | ||
// `lifecycle_scope` is not "CREATE_ONLY" | ||
func customizeDiffValidateInput(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { | ||
if diff.Get("lifecycle_scope") == lifecycleScopeCreateOnly { | ||
return nil | ||
} | ||
// input is validated to be valid JSON in the schema already. | ||
inputNoSpaces := strings.TrimSpace(diff.Get("input").(string)) | ||
if strings.HasPrefix(inputNoSpaces, "{") && strings.HasSuffix(inputNoSpaces, "}") { | ||
return nil | ||
} | ||
|
||
return errors.New(`lifecycle_scope other than "CREATE_ONLY" requires input to be a JSON object`) | ||
} | ||
|
||
// customizeDiffInputChangeWithCreateOnlyScope forces a new resource when `input` has | ||
// a change and `lifecycle_scope` is set to "CREATE_ONLY" | ||
func customizeDiffInputChangeWithCreateOnlyScope(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { | ||
if diff.HasChange("input") && diff.Get("lifecycle_scope").(string) == lifecycleScopeCreateOnly { | ||
return diff.ForceNew("input") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.