Terraform deletes AWS lambda layers instead of keeping the older versions 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 &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;]
}

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.