Answers: <p>You can tell terraform to dont care about older layer versions anymore.<br />
  This can be achieved by using the <code>skip_destroy</code> parameter and set it to <code>true</code>.<br />
  Keep in mind that layer versions are then intentionally dangling resources that are not managed anymore by terraform and may incur extra expense in your AWS account. See also the <code>aws_lambda_layer_version</code> <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_layer_version" rel="nofollow noreferrer">documentation</a>.</p>
  <pre><code>resource &quot;aws_lambda_layer_version&quot; &quot;lambda_layer&quot; {
    filename            = &quot;lambda_layer_payload.zip&quot;
    layer_name          = &quot;lambda_layer_name&quot;
    source_code_hash    = filebase64sha256(&quot;lambda_layer_payload.zip&quot;)
    skip_destroy        = true
    compatible_runtimes = [&quot;nodejs12.x&quot;]
  }
  </code></pre>
  <p>As you reference a quite old terraform version in your question I want to point out that I'm currently referencing terraform version 1.3.9 and aws provider version 4.55.0 but I think the <code>skip_destroy</code> parameter is already a bit longer available.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-10-09T06:38:35.277Z
Answers: looks like they newly introduced it! but yeah it is a helpful option.
Answers: Sankalp Kotewar
Answers: CC BY-SA 4.0
Answers: 2023-04-12T12:19:37.990Z
Answers: 2023-04-12T12:19:37.990Z
Answers: Michael Aicher
Answers: <p>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.</p>
  <p>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.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-12-01T19:50:52.277Z
Answers: 2020-12-01T19:50:52.277Z
Answers: Martin Atkins
Body: <p>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.</p>
  <p>I am using steps as mentioned <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_layer_version" rel="nofollow noreferrer">here</a>.</p>
  <pre><code>resource &quot;aws_lambda_layer_version&quot; &quot;lambda_layer&quot; {
    filename   = &quot;lambda_layer_payload.zip&quot;
    layer_name = &quot;lambda_layer_name&quot;
    source_code_hash    = filebase64sha256(&quot;lambda_layer_payload.zip&quot;)
    compatible_runtimes = [&quot;nodejs12.x&quot;]
  }
  </code></pre>
  <p>How do I retain my older versions of layers?</p>
  
Tags: <amazon-web-services><terraform><aws-lambda>
Title: Terraform deletes AWS lambda layers instead of keeping the older versions
UserDisplayName: Sankalp Kotewar
ThreadText: # Terraform deletes AWS lambda layers instead of keeping the older versions
  
  (Asked by: username_0 on 2020-11-30)
  
  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](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_layer_version).
  
  ```
  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?
  
  **Tags:** amazon-web-services, terraform, aws-lambda
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-04-12. Score: 2 | Accepted answer
  
  You can tell terraform to dont care about older layer versions anymore.  
  This can be achieved by using the `skip_destroy` parameter and set it to `true`.  
  Keep in mind that layer versions are then intentionally dangling resources that are not managed anymore by terraform and may incur extra expense in your AWS account. See also the `aws_lambda_layer_version` [documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_layer_version).
  
  ```
  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")
    skip_destroy        = true
    compatible_runtimes = ["nodejs12.x"]
  }
  
  ```
  
  As you reference a quite old terraform version in your question I want to point out that I'm currently referencing terraform version 1.3.9 and aws provider version 4.55.0 but I think the `skip_destroy` parameter is already a bit longer available.
  
  > **Comments:**
  > **username_0**: looks like they newly introduced it! but yeah it is a helpful option.  
  
  ---
  
  ### Answer by username_2 on 2020-12-01. Score: 2
  
  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.
  
  
  ---
  
  