Terraform-provider-aws: Lambda creation fails in version 2.40.0 in LocalStack

Created on 27 Nov 2019  ·  4Comments  ·  Source: hashicorp/terraform-provider-aws

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 "me too" comments, 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

Terraform Version

Terraform Version = 1.12.6
aws Provider Version = 2.40

Affected Resource(s)

  • aws_lambda_function

Terraform Configuration Files

resource aws_lambda_function find-images {
  function_name = "sentinel-find-images"
  handler = "sentinel-find-images.handler"
  role = ""
  runtime = "python3.6"
  filename = "../../lambda/sentinel-find-images/sentinel-find-images.zip"
  timeout = 900
  memory_size = 3000
  environment {
    variables = {
      STAGE = "TESTING"
    }
  }
}

Debug Output

https://gist.github.com/ciaranevans/de537317f933b98df7af306bb86e2730 For failing run
https://gist.github.com/ciaranevans/0a30164e61ae444198a59fad37c80013 For successful run

Expected Behavior

Terraform finishes deployment with line similar to:

Apply complete! Resources: 24 added, 0 changed, 0 destroyed.

Actual Behavior

All functions failed to deploy (According to Terraform), shown in debug logs above.

However they are actually deployed - my tests that wait for them to be deployed kick off and pass...

Tests are initiated once:

aws lambda list-functions --endpoint-url=http://localhost:4574 | jq '.[] | length'

returns a number == to the number of functions I'm deploying

Steps to Reproduce

  1. Create AWS provider with LocalStack with:
provider aws {
  region                      = "eu-west-2"
  s3_force_path_style         = true
  skip_credentials_validation = true
  skip_metadata_api_check     = true
  skip_requesting_account_id  = true

  endpoints {
    apigateway     = "http://localhost:4567"
    cloudwatchlogs = "http://localhost:4586"
    dynamodb       = "http://localhost:4569"
    iam            = "http://localhost:4593"
    lambda         = "http://localhost:4574"
    s3             = "http://localhost:4572"
    sns            = "http://localhost:4575"
    sqs            = "http://localhost:4576"
    ssm            = "http://localhost:4583"
  }
}
  1. Create a Lambda function resource
  2. terraform apply

Important Factoids

  • Deploying against LocalStack
  • Works with aws provider version 2.39
  • Does not work with aws provider version 2.40

References

needs-triage serviclambda

Most helpful comment

@ciaranevans My guess is that this is a LocalStack-specific problem.
The AWS Lambda GetFunctionConfiguration API now returns a State field and the Terraform AWS Provider (as of v2.40.0) uses this field to ensure that the lambda function is created successfully.
A missing value (as in the current LocalStack implementation) results in an empty State value which isn't either the in-progress value (Pending) or success value (Active), triggering the error you experienced.

You can pin the provider version to v2.39.0 until LocalStack support this functionality; I'd suggest opening an issue in their repo and referencing this issue.

All 4 comments

@ciaranevans My guess is that this is a LocalStack-specific problem.
The AWS Lambda GetFunctionConfiguration API now returns a State field and the Terraform AWS Provider (as of v2.40.0) uses this field to ensure that the lambda function is created successfully.
A missing value (as in the current LocalStack implementation) results in an empty State value which isn't either the in-progress value (Pending) or success value (Active), triggering the error you experienced.

You can pin the provider version to v2.39.0 until LocalStack support this functionality; I'd suggest opening an issue in their repo and referencing this issue.

@ewbankkit Great, thanks for taking a look into this!

I did indeed end up pinning the version. Couldn't quite figure out which end of the stick was going wrong!

Letting the LocalStack folks know!

Fixed in the latest version of LocalStack, tested with version 2.41.0 of the AWS Provider

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings