The Terraform MEAN stack project is decomposed into six focused child modules, each owning a single infrastructure concern. Rather than managing every resource in a flatDocumentation 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.
main.tf, this design keeps each module independently testable, versioned, and replaceable. The root configuration wires the modules together by passing outputs from one as inputs to another — for example, subnet IDs from network flow into ec2-instance, and security group IDs from security are consumed by both ec2-instance and alb.
Module Dependency Order
Modules must be created in a specific order because later modules consume outputs from earlier ones:- network — creates the VPC and subnets; its IDs are required by every other module
- keypair and iam — no upstream dependencies; can be created alongside
network - security — requires
vpc_idfromnetwork - ec2-instance (×3) — requires subnet IDs from
network, security group IDs fromsecurity, key name fromkeypair, and instance profile fromiam - alb — requires VPC ID from
network, subnet IDs fromnetwork, security group ID fromsecurity, and instance IDs from bothec2-instance(node_1, node_2)
Modules at a Glance
network
Creates the VPC, two public subnets across two AZs, one private subnet, an Internet Gateway, NAT Gateway, Elastic IP, and all route tables.
security
Defines three chained security groups — ALB, Node.js, and MongoDB — enforcing least-privilege traffic between tiers.
ec2-instance
A reusable EC2 module instantiated three times (node_1, node_2, mongodb) with IMDSv2 enforcement, encrypted gp3 storage, and user-data bootstrap.
alb
Provisions an internet-facing Application Load Balancer, HTTP listener, target group with
/health checks, and registers both Node.js instances.iam
Creates an IAM role attached to
AmazonSSMManagedInstanceCore, enabling SSM Session Manager access to all instances without open SSH ports.keypair
Auto-generates an RSA 4096-bit SSH key pair using the TLS provider, saves the
.pem file locally at keys/<project_name>.pem, and registers the public key with AWS.How Modules Are Called from main.tf
The root main.tf calls every module and threads outputs between them. Below is the complete abbreviated view:
Naming Convention
Every module accepts aproject_name variable and uses it as a consistent prefix for all resource names and tags. For example, with project_name = "terraform-mean":
| Module | Example resource name |
|---|---|
| network | terraform-mean-vpc |
| security | terraform-mean-alb-sg |
| ec2-instance | terraform-mean-node-1 |
| alb | terraform-mean-alb |
| iam | terraform-mean-ec2-role |
| keypair | terraform-mean-key |
project_name values.