hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.79k stars 9.14k forks source link

Updating lambda without code #15402

Open Fjandin opened 4 years ago

Fjandin commented 4 years ago

Community Note

Description

Sorry if this question has been asked before We have a pipeline where we deploy lambda code via aws cli and would like to keep everything else on terraform. However currently it is not possible to perform terraform updates on a lambda with aws_lambda_function without providing code. Would be super nice if i could perform architectural changes to a lambda without having to provide filename or source_code_hash

New or Affected Resource(s)

Potential Terraform Configuration

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key.

References

tmccombs commented 1 year ago

You can add use ignore_changes to ignore changes to the code in terraform. Something like this:

lifecycle {
  ignore_changes = [filename, source_code_hash]
}

Unfortunately, since neither lifecycle nor ignore_changes can be dynamic or depend on variables, it is impossible to have a module which works both for lambdas where you want to manage the code alongside terraform, and lambdas where the code is managed externally. See https://github.com/hashicorp/terraform/issues/24188

So for example I currently have two modules that are completely identical, except that one has this ignore_changes line, and the other doesn't.

But you do still have to provide some minimal code for the initial creation of the lambda. :frowning_face:

tmccombs commented 1 year ago

I see this has the upstream tag. And it would be nice if the AWS API allowed you to create a lambda without any code initially, maybe automatically adding minimal code, similar to what happens when you create a new Lambda from the console.

But this also could be done by terraform by having a mechanism where it creates a minimal zip file for the specified runtime, even just a zip with an empty file would probably work for most runtimes.