0
votes

I am adding resource aws_lambda_permission to send events from S3 to Lambda. But Terraform is complaining with following error message.

Error: error waiting for Lambda Function (py-lambda-foo) creation: unexpected state '', wanted target 'Active'. last error: %!s(<nil>)

Using Terraform: Terraform v0.12.17 provider.aws v2.41.0 Localstack 0.10.5

I am able to verify that function has been created successfully By checking this command

 awslocal lambda list-functions

I see this problem as AWS Provider has created the lambda function however, localstack is not returning status which is expected for provider.aws to work on. Hence, it is failing with this error.

I switched on the TRACE logs and I could see these aws.provider logs that it is waiting for state of Lambda to change to ACTIVE and it is constantly pinging lambda/GetFunction

2019-12-07T08:16:24.328Z [DEBUG] plugin.terraform-provider-aws_v2.41.0_x4: 2019/12/07 08:16:24 [DEBUG] Waiting for state to become: [Active]
2019-12-07T08:16:29.336Z [DEBUG] plugin.terraform-provider-aws_v2.41.0_x4: 2019/12/07 08:16:29 [DEBUG] [aws-sdk-go] DEBUG: Request lambda/GetFunction Details:

This is response we receive for createFunction

{
    "CodeSha256": "xnITd7GQzVtuke7kOR5LP7iprBAmgz5iu15WISiVd0U=",
    "CodeSize": 5503941,
    "Description": "",
    "Environment": {
        "Variables": {
            "foo": "bar"
        }
    },
    "FunctionArn": "arn:aws:lambda:eu-west-1:000000000000:function:py-lambda-foo",
    "FunctionName": "py-lambda-foo",
    "Handler": "app.lambda_handler",
    "LastModified": "2019-12-07T08:16:21.097+0000",
    "MemorySize": 128,
    "RevisionId": "f04d5dad-5e1e-41f0-9c96-387b7ab2313f",
    "Role": "arn:aws:iam::000000000000:role/iam_for_lambda",
    "Runtime": "python3.7",
    "Timeout": 3,
    "TracingConfig": {
        "Mode": "PassThrough"
    },
    "Version": "$LATEST"
}

1

1 Answers

0
votes

This has been an issue with the Localstack compatibility with the Terraform's AWS Provider. Take a look at issue description here https://github.com/localstack/localstack/issues/1835

Finally, Localstack developers applied the fix https://github.com/localstack/localstack/pull/1838 by adding state as ACTIVE and now this has been picked up aws-provider of Terraform.