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

[Bug]: aws_lambda_function requires code even with publish disabled #29043

Closed
pcallewaert opened this issue Jan 23, 2023 · 11 comments
Closed

[Bug]: aws_lambda_function requires code even with publish disabled #29043

pcallewaert opened this issue Jan 23, 2023 · 11 comments
Labels
service/lambda Issues and PRs that pertain to the lambda service.

Comments

@pcallewaert
Copy link

pcallewaert commented Jan 23, 2023

Terraform Core Version

1.3.7

AWS Provider Version

4.51.0

Affected Resource(s)

  • aws_lambda_function

Expected Behavior

With publish set to false, the filename, image_uri or s3_bucket were allowed to be not set (v4.50.0)

Actual Behavior

Returns error during validate:

│ Error: Invalid combination of arguments
│ 
│   with aws_lambda_function.my_lambda,
│   on katalog-lambdas.tf line 23, in resource "aws_lambda_function" "my_lambda":
│   23: resource "aws_lambda_function" "my_lambda" {
│ 
│ "filename": one of `filename,image_uri,s3_bucket` must be specified
╵
╷
│ Error: Invalid combination of arguments
│ 
│   with aws_lambda_function.my_lambda,
│   on katalog-lambdas.tf line 23, in resource "aws_lambda_function" "my_lambda":
│   23: resource "aws_lambda_function" "my_lambda" {
│ 
│ "image_uri": one of `filename,image_uri,s3_bucket` must be specified
╵
╷
│ Error: Invalid combination of arguments
│ 
│   with aws_lambda_function.my_lambda,
│   on katalog-lambdas.tf line 23, in resource "aws_lambda_function" "my_lambda":
│   23: resource "aws_lambda_function" "my_lambda" {
│ 
│ "s3_bucket": one of `filename,image_uri,s3_bucket` must be specified

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_lambda_function" "my_lambda" {
  function_name = "my_lambda"
  role          = "<valid role>"
  handler       = "index.handler"
  runtime       = "nodejs16.x"
  timeout       = 60
  description   = "Lambda reproduce error"
  publish       = false
}

Steps to Reproduce

Install provider v4.50.0

Try terraform validate with above code. => Should succeed.

Upgrade provider to v4.51.0:

Execute terraform validate => Will fail

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

I think it's related with the refactor in #28963

Would you like to implement a fix?

No

@pcallewaert pcallewaert added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Jan 23, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/lambda Issues and PRs that pertain to the lambda service. label Jan 23, 2023
@pcallewaert pcallewaert changed the title [Bug]: [Bug]: aws_lambda_function requires code even with publish disabled Jan 23, 2023
@justinretzolk
Copy link
Member

Hey @pcallewaert 👋 Thank you for taking the time to raise this! The publish argument refers to whether or not Lambda function versions are created when a change occurs. When set to false, a function version isn't published, but the function is still created in AWS, therefor the Lambda function package must still be supplied by setting on of:

  • image_uri
  • filename
  • s3_bucket, s3_key, and s3_object_version

@justinretzolk justinretzolk added waiting-response Maintainers are waiting on response from community or contributor. and removed bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Jan 23, 2023
@pcallewaert
Copy link
Author

Hello @justinretzolk,

AFAIK we imported most of our lambda functions, so there was no initial deployment package. We use this to manage the runtime and env variables, not the code.
This was allowed to v4.50.0, since v4.51.0 this now fails with the mentioned error.
Should we pass a dummy value in the filename setting?

@github-actions github-actions bot removed the waiting-response Maintainers are waiting on response from community or contributor. label Jan 25, 2023
@maystreet-its
Copy link

This completely broke our deployments and appears to be a valid regression. An upgrade to 4.51 from 4.50 should not trigger breakage.

@mdemartinis
Copy link

Same situation happened to me. A lot of Lambdas have been imported prior v4.51.0 and now I can't apply changes because it is requesting the code to deploy.
It would be ideal to have a flag to choose if code will be deployed or not. Eventually, if trying to create a new Lambda with no code, make it fail, but allow updating the resource without code.

@Deadvi5
Copy link

Deadvi5 commented Mar 8, 2023

Same situation happened to me too. When we create the infrastructure for the first time without a deployed package (obviously) it's going to break the apply. It's not the ideal situation

@AntonyOnScript
Copy link

This completely broke our deployments and appears to be a valid regression. An upgrade to 4.51 from 4.50 should not trigger breakage.

i think the same

@joel-apollo
Copy link

Any update here or a way to patch this?

@delsantosmiranda
Copy link

delsantosmiranda commented Apr 28, 2023

A workaround to resolve this is to pass the filename with any file, and create an ignore_changes block for the filename.
That way terraforn will not try to apply this configuration to the lambda and apply will not break.

  filename                       = "function.zip"
  lifecycle {
    ignore_changes = [filename]
  }

@justinretzolk
Copy link
Member

Thank you for mentioning that workaround @delsantosmiranda 🎉.

On reviewing this again, with an edge case such as only using the aws_lambda_function to manage certain aspects of imported Lambda functions, that workaround is the best path forward unless the underlying API has such functionality added, since modifying the resource to work around not fully managing the function would go against the design principle of matching the underlying API.

With that in mind, I'm going to close this issue. If you feel I've done this in error, or have additional thoughts that should be considered, please do let me know.

@github-actions
Copy link

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 have 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 github-actions bot locked as resolved and limited conversation to collaborators Jul 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/lambda Issues and PRs that pertain to the lambda service.
Projects
None yet
Development

No branches or pull requests

8 participants