SERVERLESS RUBY
Build and Deploy AWS Lambda Functions from Scratch

Interlude: What the Heck Is Terraform?

Infrastructure as Code, Without the DevOps Trauma

Okay, time to talk about Terraform.

You've manually deployed a Lambda. It worked, but it was a lot of clicking, copying, and pasting. That doesn't scale.

Terraform fixes this.


🧱 What Terraform Actually Does

Terraform is a tool that lets you describe your infrastructure in code.

You write files like this:

resource "aws_lambda_function" "my_function" {
  function_name = "my-ruby-lambda"
  ...
}

Then you run terraform apply, and Terraform talks to AWS on your behalf to create the Lambda function automatically.

You can:

  • Version-control your infrastructure
  • Reproduce the exact same environment in staging and prod
  • Destroy and rebuild environments instantly
  • Share deploy logic across teams
Think of it like writing a Rails migration, but for your AWS infrastructure.

🛠️ How Terraform Works (High-Level)

Here's the workflow:

  1. You write .tf files to describe what you want.
  2. You run terraform init (once) to set up Terraform.
  3. You run terraform plan to see what it would do.
  4. You run terraform apply to actually make the changes.

Behind the scenes:

  • Terraform uses providers (like aws) to talk to cloud APIs
  • It keeps a state file to know what it has created
  • You can reference variables, modules, and outputs to compose reusable infrastructure