0

I'm migrating multiple AWS Lambda functions to GCP and need to generate Terraform configurations that match the existing AWS setup. Currently, I'm manually writing each Lambda configuration, which is time-consuming and error-prone.

I'm manually creating Terraform maps like this for each Lambda function:

entity_gateway = {
  function_name = "one-journey-genai-entityGateway"
  role          = "arn:aws:iam::<ACCOUNT_ID>:role/<ENTITY_GATEWAY_ROLE>"
  handler       = "src/api/v1/endpoint/entity/gateway.handler"
  runtime       = "nodejs20.x"
  memory_size   = 1536
  timeout       = 30
  architectures = ["arm64"]
  package_type  = "Zip"
  publish       = false
  description   = ""
  s3_bucket     = "<S3_BUCKET>"
  s3_key        = "<S3_KEY>"
  layers        = ["arn:aws:lambda:<REGION>:<ACCOUNT_ID>:layer:googleStorage:<VERSION>"]
  environment_variables = local.common_env_vars
  tags = {
    STAGE = "genai"
  }
}

debugs = {
  function_name = "one-journey-genai-debugs"
  role          = "arn:aws:iam::<ACCOUNT_ID>:role/<DEBUGS_ROLE>"
  handler       = "src/api/v1/core/debugs/event.handler"
  runtime       = "nodejs20.x"
  memory_size   = 1536
  timeout       = 6
  architectures = ["arm64"]
  package_type  = "Zip"
  publish       = false
  description   = ""
  s3_bucket     = "<S3_BUCKET>"
  s3_key        = "<S3_KEY>"
  layers        = []
  environment_variables = local.common_env_vars
  tags = {
    STAGE = "genai"
  }
}

What I Need

I want to automate extracting Lambda configurations from AWS and generating Terraform code, so that when I run terraform plan, it shows no changes (configuration matches existing state).

1 Answer 1

1

What you could do is use the option to generate the configuration for all Lambdas by just defining the Lambda function name as an argument when importing:

import {
  to = aws_lambda_function.this
  id = "one-journey-genai-entityGateway"
}

Followed by:

terraform plan -generate-config-out=lambda.tf

Ideally, you would add all the imports you need in a single file so the generated tf file contains all the Lambda functions.

Sign up to request clarification or add additional context in comments.

3 Comments

Additionally terraformer is the most common other option.
Yeah, I mean this first came to mind, but any other tool that does the job is as good.
I actually have never tried the TF intrinsic solution since it was developed after I needed it, but it does have the benefit of first party and built-in.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.