I am using terraform version 12.26 for AWS deployment. Whenever I try updating a lambda layer, the lambda layer version is incremented, but the older layer is deleted. Even though my current version of layer is for example 8, the older versions from 1 to 7 are automatically deleted.

I am using steps as mentioned here.

resource "aws_lambda_layer_version" "lambda_layer" {
  filename   = "lambda_layer_payload.zip"
  layer_name = "lambda_layer_name"
  source_code_hash    = filebase64sha256("lambda_layer_payload.zip")
  compatible_runtimes = ["nodejs12.x"]

How do I retain my older versions of layers?


Terraform's job is to maintain one remote object per resource block, either by updating that same object over time or by replacing it with a new object that meets new requirements.

If you wish to gradually accumulate new objects over time then Terraform is not the correct tool for the job. Your need would be better served by an application deployment tool, such as the Serverless framework.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.