Skip to content

Commit d8b4ccb

Browse files
committed
initial release
0 parents  commit d8b4ccb

32 files changed

Lines changed: 732 additions & 0 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Terraform Validate
2+
3+
on: [push]
4+
5+
jobs:
6+
validate:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: opentofu/setup-opentofu@v1
11+
- run: tofu fmt -check
12+
- run: tofu validate

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# 🚀 Startup AWS Production Stack
2+
3+
**The smallest AWS infrastructure that is secure, scalable, cost-aware, and truly production-ready.**
4+
5+
## Who This Is For
6+
- **Early-stage startups** looking for a production-ready baseline.
7+
- **Solo founders** needing a secure, low-maintenance stack.
8+
- **Agency engineers** wanting to launch MVPs or POCs (Proof of Concepts) rapidly.
9+
10+
## Tech Stack
11+
- **OpenTofu** (Terraform compatible)
12+
- **AWS ECS Fargate** (Container Orchestration)
13+
- **AWS RDS** (PostgreSQL Database)
14+
- **AWS Secrets Manager** (Password Security)
15+
- **AWS ALB + ACM** (Load Balancing & SSL)
16+
- **AWS VPC** (Public/Private Subnets, NAT Gateway)
17+
18+
## 🛠️ Quick Start
19+
20+
### 1. Prerequisites
21+
Before you start, ensure you have:
22+
- **OpenTofu** (`brew install opentofu`) OR **Terraform** installed.
23+
- **AWS CLI** installed and configured (`aws configure`).
24+
- A **Domain Name** (e.g., `myapp.com`) with a **Route53 Hosted Zone** in your AWS account.
25+
26+
### 2. Configuration
27+
Create a file named `terraform.tfvars` in `environments/dev/` to store your specific settings. This keeps your changes separate from the code.
28+
29+
**`environments/dev/terraform.tfvars`**
30+
```hcl
31+
project_name = "my-startup"
32+
container_image = "nginx:latest" # Replace with your Docker image URL (e.g., DockerHub or ECR)
33+
container_port = 80 # The port your container listens on
34+
domain_name = "myapp.com" # Your actual domain
35+
hosted_zone_id = "Z123456789ABC" # Find this in Route53 Console -> Hosted Zones
36+
```
37+
38+
> **Tip:** You can find your `hosted_zone_id` by running:
39+
> `aws route53 list-hosted-zones --query "HostedZones[*].{Name:Name,ID:Id}"`
40+
41+
### 3. Deploy
42+
Run the following commands in the `environments/dev` folder:
43+
44+
```bash
45+
# Initialize the project (downloads providers)
46+
tofu init
47+
48+
# Preview the changes
49+
tofu plan
50+
51+
# Apply the changes (type 'yes' when prompted)
52+
tofu apply
53+
```
54+
55+
> **Note:** The apply step may pause for a few minutes while AWS validates your SSL certificate. This is normal.
56+
57+
### 4. Access Your App
58+
Once finished, `tofu` will output your Load Balancer DNS (though you should just visit your domain):
59+
- Go to `https://myapp.com`
60+
61+
---
62+
63+
## Architecture Overview
64+
- **Security**:
65+
- Application and Database live in **Private Subnets** (no direct internet access).
66+
- **NAT Gateway** allows them to download updates/images securely.
67+
- **ALB** handles HTTPS termination and forwards traffic to the app.
68+
- **Database**:
69+
- Password is auto-generated and stored in **AWS Secrets Manager**.
70+
- App reads the password securely at runtime via environment variables.
71+
72+
## 🧹 Clean Up
73+
To avoid incurring costs (~$50/mo for NAT GW + RDS) when you are done testing:
74+
75+
```bash
76+
tofu destroy
77+
```
78+
79+
## Estimated Monthly Cost
80+
See [cost/monthly-estimate.md](cost/monthly-estimate.md)
81+
82+
## License
83+
MIT

architecture/high-level.png

3.35 KB
Loading

architecture/networking.png

3.72 KB
Loading
3.54 KB
Loading

cost/monthly-estimate.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Estimated Monthly Cost (USD)
2+
3+
| Service | Details | Monthly Cost (USD) |
4+
| :--- | :--- | :--- |
5+
| **ECS Fargate** | Smallest task size (0.25 vCPU, 0.5GB RAM) | $20–40 |
6+
| **Application Load Balancer** | Standard ALB (hourly rate + LCU charges) | ~$18 |
7+
| **RDS (PostgreSQL)** | `db.t3.micro` instance, 20GB SSD storage | ~$15 |
8+
| **CloudWatch** | Logs ingestion and 14-day retention | ~$5 |
9+
| **Total** | | **$60–80** |

environments/dev/main.tf

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
terraform {
2+
required_version = ">= 1.6"
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
version = "~> 5.0"
7+
}
8+
}
9+
}
10+
11+
12+
13+
provider "aws" {
14+
region = var.aws_region
15+
}
16+
17+
18+
module "network" {
19+
source = "../../modules/network"
20+
project_name = var.project_name
21+
environment = var.environment
22+
}
23+
24+
module "security" {
25+
source = "../../modules/security"
26+
project_name = var.project_name
27+
environment = var.environment
28+
vpc_id = module.network.vpc_id
29+
db_secret_arn = module.database.db_secret_arn
30+
}
31+
32+
33+
module "database" {
34+
source = "../../modules/database"
35+
project_name = var.project_name
36+
environment = var.environment
37+
vpc_id = module.network.vpc_id
38+
private_subnets = module.network.private_subnets
39+
db_sg = module.security.db_sg_id
40+
}
41+
42+
module "compute" {
43+
source = "../../modules/compute"
44+
project_name = var.project_name
45+
environment = var.environment
46+
vpc_id = module.network.vpc_id
47+
public_subnets = module.network.public_subnets
48+
private_subnets = module.network.private_subnets
49+
alb_sg = module.security.alb_sg_id
50+
51+
ecs_execution_role_arn = module.security.ecs_execution_role_arn
52+
ecs_task_role_arn = module.security.ecs_task_role_arn
53+
db_secret_arn = module.database.db_secret_arn
54+
domain_name = "digikraaft.com"
55+
hosted_zone_id = "Z00000000000000000000" # MOCK ZONE ID
56+
}
57+
58+
59+
60+
61+
module "observability" {
62+
source = "../../modules/observability"
63+
project_name = var.project_name
64+
environment = var.environment
65+
}

environments/dev/terraform.tfvars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project_name = "startup"
2+
environment = "dev"
3+
aws_region = "us-east-1"

environments/prod/main.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
terraform {
2+
required_version = ">= 1.6"
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
version = "~> 5.0"
7+
}
8+
}
9+
}
10+
11+
12+
13+
provider "aws" {
14+
region = var.aws_region
15+
}
16+
17+
18+
module "network" {
19+
source = "../../modules/network"
20+
project_name = "startup"
21+
environment = "prod"
22+
}

environments/prod/terraform.tfvars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project_name = "startup"
2+
environment = "prod"
3+
aws_region = "us-east-1"

0 commit comments

Comments
 (0)