Skip to content

greqq/terraform-aws-infrastructure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

32 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Cloud Resume Challenge - AWS Infrastructure

Terraform AWS

πŸ“‹ Overview

This repository contains the Infrastructure as Code (IaC) for the Cloud Resume Challenge, implementing a serverless resume website with visitor counter functionality on AWS using Terraform.

Live Site: lukamasa.com

Frontend Repository: greqq/cloud-resume


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Cloudflare β”‚  DNS Management
β”‚     DNS     β”‚  lukamasa.com β†’ CloudFront
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      AWS Infrastructure                      β”‚
β”‚                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
β”‚  β”‚  CloudFront  │──────│  S3 Bucket  β”‚  Website Hosting    β”‚
β”‚  β”‚     (CDN)    β”‚      β”‚ (Private)   β”‚                     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β”‚                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ API Gateway  │──────│   Lambda    │──────│ DynamoDB  β”‚ β”‚
β”‚  β”‚  (REST API)  β”‚      β”‚  (Python)   β”‚      β”‚  Tables   β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
β”‚  β”‚  CloudWatch  │──────│     SNS     β”‚  Monitoring         β”‚
β”‚  β”‚   Alarms     β”‚      β”‚   Topics    β”‚                     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🧩 Modules

Module Purpose Key Resources
s3 Static website hosting S3 bucket with CloudFront OAC
cloudfront CDN with HTTPS Distribution, cache policy, OAC
certificate SSL/TLS certificate ACM certificate (DNS validation)
lambda Visitor counter logic Python function, IAM role
api_gateway REST API endpoint API Gateway with CORS support
dynamodb Visitor count storage VisitorCounter table
dynamodb_unique_visits Unique visitor tracking UniqueVisitors table
monitoring Alarms & notifications CloudWatch alarms, SNS topics

πŸš€ Getting Started

Prerequisites

  • Terraform: v1.12.0 or higher
  • AWS CLI: Configured with SSO
  • AWS Account: With appropriate permissions
  • Git: For version control

Initial Setup

  1. Clone the repository:

    git clone https://github.com/greqq/terraform-aws-infrastructure.git
    cd terraform-aws-infrastructure
  2. Login to AWS SSO:

    ./aws-login.sh
    # Or manually:
    aws sso login --profile FullAccessLambdaDynamo-591968772652
    export AWS_PROFILE=FullAccessLambdaDynamo-591968772652
  3. Initialize Terraform:

    cd environments/production
    terraform init -backend-config=backend.conf
  4. Review planned changes:

    terraform plan
  5. Apply infrastructure:

    terraform apply

πŸ“ Project Structure

terraform-aws-infrastructure/
β”œβ”€β”€ README.md
β”œβ”€β”€ aws-login.sh                    # AWS SSO login helper
β”œβ”€β”€ setup-dev-environment.sh        # Dev environment setup
β”‚
β”œβ”€β”€ environments/
β”‚   β”œβ”€β”€ development/                # Dev environment (isolated testing)
β”‚   β”‚   β”œβ”€β”€ main.tf
β”‚   β”‚   β”œβ”€β”€ variables.tf
β”‚   β”‚   └── outputs.tf
β”‚   β”‚
β”‚   └── production/                 # Production environment
β”‚       β”œβ”€β”€ main.tf                 # Module composition
β”‚       β”œβ”€β”€ variables.tf            # Variable definitions
β”‚       β”œβ”€β”€ terraform.tfvars        # Configuration values
β”‚       β”œβ”€β”€ outputs.tf              # Exported values
β”‚       └── backend.conf            # S3 backend config
β”‚
└── modules/                        # Reusable infrastructure components
    β”œβ”€β”€ api_gateway/
    β”œβ”€β”€ certificate/
    β”œβ”€β”€ cloudfront/
    β”œβ”€β”€ dynamodb/
    β”œβ”€β”€ dynamodb_unique_visits/
    β”œβ”€β”€ lambda/
    β”œβ”€β”€ monitoring/
    └── s3/

πŸ” Backend Configuration

Remote State Storage

Terraform state is stored remotely in S3 with DynamoDB locking to prevent concurrent modifications:

bucket         = "terraform-state-webflow-lma"
key            = "global/s3/terraform.tfstate"
region         = "us-east-1"
dynamodb_table = "terraform-up-and-running-locks"

πŸ”§ Configuration

Key Variables (terraform.tfvars)

Variable Value Description
domain_name lukamasa.com Primary domain
bucket_name cloud-resume-lma S3 bucket for website
function_name incrementCounter Lambda function name
billing_mode PAY_PER_REQUEST DynamoDB billing (serverless)
environment_type prod Environment identifier

πŸ”„ CI/CD Integration

The frontend repository uses GitHub Actions to:

  1. Pull infrastructure outputs from Terraform
  2. Build Next.js app with correct API URL (NEXT_PUBLIC_API_URL)
  3. Deploy to S3 bucket
  4. Invalidate CloudFront cache

Workflow: .github/workflows/ci.yaml in cloud-resume


πŸ› οΈ Common Operations

Update Infrastructure

cd environments/production
terraform plan      # Review changes
terraform apply     # Apply changes

View Current State

terraform show
terraform state list  # List all resources

Destroy Resources

# ⚠️ CAUTION: This will destroy all infrastructure!
terraform destroy

Unlock State (if stuck)

terraform force-unlock <LOCK_ID>

Add New Resource

  1. Modify or create module in modules/
  2. Update environments/production/main.tf to use module
  3. Add variables to terraform.tfvars if needed
  4. Run terraform plan and terraform apply

πŸ™ Acknowledgments

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors