terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

Lifecycle: Unable to perform postcondition on lambda result

Open nitaysol opened this issue 8 months ago • 5 comments

Expected Behavior

I'm trying to verify lambda invocation result and accordingly if the lambda result indicates a failure I want to fail the 'apply' stage. As described in the documentation I've created a lifecycle.postCondition on the dataAwsLambdaInvocation in order to do so. The lambda invocation returns a json with 'statusCode' - 200 for success, 500 for failure. My DataAwsLambdaInvocation variable is corresponding to the invocation itself('invocation') and is as follows:

        new dataAwsLambdaInvocation.DataAwsLambdaInvocation(this, `${id}`, {
            functionName: `${my_lambda_fun}.arn`,
            input: '',
            dependsOn: [invocation],
            lifecycle: {
                postcondition: [
                    {
                        condition: `${Fn.lookup(Fn.jsondecode(invocation.result), 'statusCode')} == 200}`,
                        errorMessage: 'error_test',
                    },
                ],
            },
        });

Actual Behavior

cdktf plan fails with:

│ Error: Invalid condition result
                 │ 
                 │   on cdk.tf.json line 44, in data.aws_lambda_invocation-*-data(*-data).lifecycle.postcondition[0]:
                 │   44:               "condition": "${jsondecode(aws_lambda_invocation*-invoc (*-invoc).result).statusCode} == 200}",

Steps to Reproduce

  1. Create lambdaFunction variable 'lambda'.
  2. Create lambdaInvocation.LambdaInvocation variable 'invocation' corresponding to the 'lambda' created on step 1.
  3. Create dataAwsLambdaInvocation.DataAwsLambdaInvocation variable 'invocationData' with the same values as the 'invocation' itself(as the documentation says) and with postcondition that accessing the 'invocation'.result value

Versions

language: typescript cdktf-cli: 0.17.3 node: v18.17.1 cdktf: null constructs: null jsii: null terraform: 1.5.5 arch: x64 os: linux 5.15.0-89-generic

Providers

┌───────────────┬──────────────────┬─────────┬────────────┬─────────────────────┬─────────────────┐ │ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │ ├───────────────┼──────────────────┼─────────┼────────────┼─────────────────────┼─────────────────┤ │ aws │ 5.31.0 │ ^0.19.0 │ │ @cdktf/provider-aws │ 18.2.0 │ ├───────────────┼──────────────────┼─────────┼────────────┼─────────────────────┼─────────────────┤

Gist

No response

Possible Solutions

No response

Workarounds

No response

Anything Else?

No response

References

No response

Help Wanted

  • [ ] I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • 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
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

nitaysol avatar Dec 19 '23 13:12 nitaysol

Hi @nitaysol 👋

Could you post what's in your cdk.tf.json in line 44 (and the surrounding lines)? Is there a * in the id of your construct? It might cause this hickup 🤔

Thanks!

ansgarm avatar Jan 02 '24 14:01 ansgarm

Thanks for reaching out @ansgarm . No there are no '*' in my construct I've used it in my comment to not use the full name. Line 44(with the surrounding lines): "lifecycle": { "postcondition": [ { "condition": "${jsondecode(aws_lambda_invocation.phau-ca-root-ca-create-root-ca-keys-invoc.result).statusCode} == 200}", "error_message": "error" } ] }

nitaysol avatar Jan 03 '24 09:01 nitaysol

It looks like this error originates from terraform when a condition fails: https://github.com/hashicorp/terraform/blob/3c14eeb94552fc1b61485abeabeefa9b95dcc85e/internal/terraform/eval_conditions.go#L117

DanielMSchmidt avatar Jan 09 '24 11:01 DanielMSchmidt

@DanielMSchmidt - Thanks Daniel I will check it out and leave them a comment then:)

nitaysol avatar Jan 15 '24 07:01 nitaysol

Hi there! 👋 We haven't heard from you in 15 days and would like to know if the problem has been resolved or if you still need help. If we don't hear from you before then, I'll auto-close this issue in 30 days.

github-actions[bot] avatar Feb 10 '24 02:02 github-actions[bot]

I'm closing this issue because we haven't heard back in 45 days. ⌛️ If you still need help, feel free to comment or reopen the issue!

github-actions[bot] avatar Mar 11 '24 02:03 github-actions[bot]

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've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Apr 11 '24 01:04 github-actions[bot]