Terraform Interview Exercise

Objective

Use Terraform and LocalStack to configure a Lambda function and function URL. LocalStack acts as a stand-in for AWS, there's no need an AWS account or access keys. The initial configuration in main.tf configures Terraform to make calls to the LocalStack container.

Prerequisites

All can be installed via Homebrew on macOS or Linux

  • Python: brew install python@3.11
  • Docker CLI: brew install docker
  • Colima: brew install colima (likely only needed on macOS)
  • Localstack: brew install localstack
  • Terraform: brew install terraform

Note that the LocalStack Python package must be installed on your host machine – running only the LocalStack Docker container is not sufficient to complete this exercise.

Steps

1. Initialization

  1. Make sure Docker (or Colima) is running

  2. Start LocalStack:

    $ localstack start
  3. Clone this repo to a local working directory

  4. Initialize a Terraform root module within the repo directory

2. Add Lambda Function

  1. Write Terraform configuration for a Lambda function that runs the Python code contained in the lambda/ directory
  2. Validate, plan, and apply your changes

3. Add Lambda Function URL

  1. Write Terraform configuration for a Lambda function URL for the function you created
  2. Validate, plan, and apply your changes

4. Testing & Teardown

  1. Get the URL of the Lambda function you created
  2. Call the Lambda function using curl and observe its output
  3. Destroy the running infrastructure

Sources/Inspiration