Skip to main content

Prerequisites

Before running any Terraform commands, make sure you have the following in place:
  • Terraform >= 1.5.0 — required by the required_version constraint in main.tf
  • AWS CLI configured with credentials that have sufficient permissions (see IAM roles)
  • AWS region: eu-west-1 (default; overridable via terraform.tfvars)
  • A terraform.tfvars file with all required sensitive variables (see below)

Module structure

The Terraform configuration lives in aws-infra-terraform/ and is organized into three layers:
The root module (main.tf) calls the iam and lambdas child modules and wires their inputs and outputs together. Resources that are not Lambda- or IAM-specific (DynamoDB, S3, CloudWatch, etc.) are defined directly in the root module.

Required providers

The klayers provider is used to fetch the latest ARN of the community-maintained KLayers Lambda layer for bcrypt.

terraform.tfvars

Sensitive and environment-specific values are passed through terraform.tfvars. This file is not committed to version control.
terraform.tfvars is listed in .gitignore. Never commit this file — it contains secrets such as Gmail credentials, the Google OAuth client ID, and the Gemini API key.
The following variables must be set in terraform.tfvars: All other variables have defaults defined in variables.tf and can optionally be overridden here (e.g., aws_region, bucket names, table names). Example structure (do not include real values):

Deploying the infrastructure

1

Initialize Terraform

Download providers and initialize the module registry.
2

Review the plan

Preview all changes before applying them. Inspect the output carefully — especially for destructive actions (replacements or deletions).
3

Apply the changes

Apply the planned changes to your AWS account.
Terraform will prompt for confirmation before making any changes. Type yes to proceed.
Running terraform apply in a production environment will modify live AWS resources. Always review the plan output before confirming, and consider using a separate workspace or state file for production.

State management and resource migrations

Terraform state is stored locally in aws-infra-terraform/terraform.tfstate. This file is not committed to version control. When resources are refactored — for example, moved from the root module into the iam or lambdas child modules — their state addresses change. The moved.tf file records these address renames so Terraform can reconcile existing state without destroying and re-creating resources. Example entry from moved.tf:
When Terraform encounters a moved block it updates the state in-place and plans no infrastructure changes. This makes module refactoring safe to apply. To inspect current state or diagnose issues: