Importing existing lambda layers into terraform

35 views Asked by At

I was trying to import my existing lambda-Layer into terraform. I had this configuration for my layer:

data "archive_file" "node_modules_zip" {
  type        = "zip"
  source_dir  = abspath("${path.module}/../functioncode/node_modules")
  output_path = abspath("${path.module}/../functioncode/node_modules.zip")
}

resource "aws_lambda_layer_version" "lambda_layer" {
  layer_name = "lambda_dependency"
  compatible_architectures    = []
  skip_destroy = true
  compatible_runtimes = ["nodejs16.x", "nodejs18.x"]
  filename         = data.archive_file.node_modules_zip.output_path
}

I also had a import statement written for this:

import {
  to = aws_lambda_layer_version.lambda_layer
  id = "arnOfTheLayer"
}

Now when I run terraform plan, it gives me this:

# aws_lambda_layer_version.lambda_layer must be replaced
  # (imported from "arn:aws:lambda:................")
  # Warning: this will destroy the imported resource
-/+ resource "aws_lambda_layer_version" "lambda_layer" {
        . . . . . . 
    }
 

I wanted to know if this the default behavior of lambda_layer? Does it import the layer and then try to destroy it because it detects another upload in the form of zip?

0

There are 0 answers