Prerequisites
Before running any Terraform commands, make sure you have the following in place:- Terraform
>= 1.5.0— required by therequired_versionconstraint inmain.tf - AWS CLI configured with credentials that have sufficient permissions (see IAM roles)
- AWS region:
eu-west-1(default; overridable viaterraform.tfvars) - A
terraform.tfvarsfile with all required sensitive variables (see below)
Module structure
The Terraform configuration lives inaws-infra-terraform/ and is organized into three layers:
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
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 throughterraform.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.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.State management and resource migrations
Terraform state is stored locally inaws-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:
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: