Before runningDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/mcamacho97/terraform-mean-stack-aws/llms.txt
Use this file to discover all available pages before exploring further.
terraform init or terraform apply, you need to populate two configuration files: backend.hcl, which tells Terraform where to store its remote state, and terraform.tfvars, which supplies values for every input variable the project declares. Neither file is committed to source control — both are listed in .gitignore to keep credentials and environment-specific settings out of your repository history.
backend.hcl
Thebackend.hcl file provides the S3 backend configuration that is passed to terraform init via the -backend-config flag. Keeping it separate from backend.tf means you can maintain different state locations for different environments without modifying tracked Terraform files.
Create backend.hcl in the project root with the following content, substituting your own bucket name and preferred state key path:
| Field | Purpose |
|---|---|
bucket | Name of the S3 bucket you created in the prerequisites step |
key | Object path within the bucket for the state file |
region | AWS region where the bucket resides |
encrypt | Enables server-side encryption of the state file at rest |
terraform.tfvars
Theterraform.tfvars file supplies concrete values for all input variables declared in variables.tf. Start from the provided example:
terraform.tfvars in your editor and fill in every value. The example file ships with sensible defaults for networking and instance sizing — the only value you must change before deploying is allowed_ssh_ip.
Variable Reference
All twelve input variables are required — there are no defaults defined invariables.tf, so every field must be present in your terraform.tfvars.
Project Identity
Project name used as a prefix for all AWS resource names and tags (e.g.
terraform-mean). This value flows into locals.tf to build names like terraform-mean-vpc, terraform-mean-alb, etc.Deployment environment label applied as a tag to every resource. Accepted values:
lab, dev, qa, prod.AWS Region
AWS region in which all infrastructure will be provisioned (e.g.
us-east-1). Must match the region of your S3 state bucket if you want to keep everything co-located.Networking
CIDR block for the VPC (e.g.
10.0.0.0/16). All subnet CIDRs must fall within this range.CIDR block for Public Subnet A, which hosts Node.js Server 1 and the first ALB node (e.g.
10.0.1.0/24).CIDR block for Public Subnet B, which hosts Node.js Server 2 and the second ALB node (e.g.
10.0.2.0/24).CIDR block for the Private Subnet, which hosts the MongoDB instance and routes outbound traffic through the NAT Gateway (e.g.
10.0.3.0/24).Availability Zone for Public Subnet A (e.g.
us-east-1a). Must be a valid AZ within aws_region.Availability Zone for Public Subnet B (e.g.
us-east-1b). Should differ from availability_zone_1 to achieve multi-AZ high availability.Compute
EC2 instance type for all three servers — both Node.js instances and the MongoDB instance (e.g.
t2.micro for AWS Free Tier eligibility).Number of Node.js application servers to provision. Default in the example is
2, which matches the two public subnets and provides basic load-balanced redundancy.Access Control
The single public IP address (in CIDR
/32 notation) that is permitted to connect to EC2 instances over SSH port 22 (e.g. 203.0.113.42/32). Run curl ifconfig.me to find your public IP.Complete Example File
The following is the completeterraform.tfvars.example file shipped with the project. Copy it to terraform.tfvars and replace YOUR_IP/32 with your actual public IP before deploying:
Common Resource Tags
Thelocals.tf file defines a common_tags map that is applied to every AWS resource via the provider’s default_tags block in provider.tf. You do not need to add tags manually to individual resources.