Skip to content

Terraform Secure VPC + EC2 (Step 1,2,3). Hardened AWS IaC with centralized logging, encrypted storage, private endpoints, and ISO/IEC 27001 control mapping.

Notifications You must be signed in to change notification settings

amina0806/terraform-secure-vpc-ec2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Terraform Secure VPC + EC2 β€” Portfolio Project

Overview

This portfolio demonstrates how to design, harden, and document secure AWS workloads using Terraform. It evolves across three steps, each adding stronger security and compliance layers:

  1. Step 1 β€” Public EC2 + ALB

    • Basic VPC, Internet Gateway, Security Groups
    • Application Load Balancer + Public EC2
  2. Step 2 β€” Private EC2 (SSM only)

    • Private Subnets + NAT Gateway
    • Private EC2 (no public IP) managed via Session Manager
    • Encrypted EBS volumes + IMDSv2 enforced
  3. Step 3 β€” Centralized Logging + VPC Endpoints

    • Default EBS encryption enabled
    • VPC Flow Logs β†’ S3 with SSE-KMS (CMK protected)
    • VPC Endpoints for SSM, EC2 Messages, and S3
    • Scoped Security Groups for least privilege

What This Portfolio Demonstrates

  • Secure AWS infrastructure codified with Terraform
  • Application of security best practices: encryption, least privilege, bastionless access
  • Mapping of technical design to ISO/IEC 27001 Annex A controls
  • Evidence-based documentation: screenshots + Terraform code

ISO/IEC 27001 Annex A Coverage

Step Controls Implemented
Step 1 A.8.12 Data leakage prevention (Security Group rules)
A.5.23 Information security for use of cloud services (subnet segregation)
Step 2 A.8.24 Use of cryptography (EBS encryption)
A.8.28 Secure authentication (IMDSv2)
A.8.16 Identity and access control (IAM role for SSM)
A.8.12 Data leakage prevention (no public IP, egress-only networking)
A.5.23 Information security for use of cloud services (bastionless via SSM)
Step 3 A.8.15 Logging (VPC Flow Logs)
A.8.16 Monitoring activities (Flow Logs to encrypted S3 with restricted policy)
A.8.24 Use of cryptography (EBS default encryption, SSE-KMS, CMK)
A.8.12 Data leakage prevention (VPC Endpoints restrict traffic)
A.5.23 Information security for use of cloud services (private-only design with centralized audit trail)
A.8.16 Identity and access control (SSM least privilege)
A.8.28 Secure authentication (IMDSv2 enforced)

πŸ“„ Full mappings: docs/iso27001-mapping.md


Architecture Diagram

Architecture Diagram


Project Structure

terraform-secure-vpc-ec2/
β”œβ”€β”€ providers.tf
β”œβ”€β”€ variables.tf
β”œβ”€β”€ outputs.tf
β”œβ”€β”€ main.tf
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ compute/
β”‚   β”‚   β”œβ”€β”€ main.tf                # Step 1 - Public EC2
β”‚   β”‚   β”œβ”€β”€ private.tf             # Step 2 - Private EC2
β”‚   β”‚   β”œβ”€β”€ step3_encryption.tf    # Step 3 - Encrypted EBS
β”‚   β”‚   β”œβ”€β”€ outputs.tf
β”‚   β”‚   └── variables.tf
β”‚   └── network/
β”‚       β”œβ”€β”€ main.tf                # Step 1 - VPC, IGW
β”‚       β”œβ”€β”€ private.tf             # Step 2 - Private subnets + NAT
β”‚       β”œβ”€β”€ step3_endpoints+logging.tf  # Step 3 - Endpoints + Flow Logs
β”‚       β”œβ”€β”€ locals.tf
β”‚       β”œβ”€β”€ outputs.tf
β”‚       └── variables.tf
└── docs/
    β”œβ”€β”€ diagrams/
    β”‚   └── architecture-diagram.png
    β”œβ”€β”€ iso27001-mapping.md
    └── screenshots/
        β”œβ”€β”€ step1/
        β”œβ”€β”€ step2/
        └── step3/

How to Run

terraform init
terraform plan
terraform apply


Step 1

Terraform Secure VPC + EC2 β€” Step 1 (Public EC2 + ALB)

Project Description

This step builds the foundation VPC with public subnets, an Internet Gateway, and a demo EC2 instance behind an ALB. It establishes the base networking layer to be secured and extended in later steps.


What This Step Proves

  • I can codify a basic VPC architecture with Terraform.
  • I can configure Internet Gateway, routing, and public subnets.
  • I can launch a public EC2 instance behind an ALB.
  • I can apply initial ISO/IEC 27001 Annex A mappings.

Project Structure (Step 1)

terraform-secure-vpc-ec2/
β”œβ”€β”€ main.tf
β”œβ”€β”€ providers.tf
β”œβ”€β”€ variables.tf
β”œβ”€β”€ outputs.tf
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ network/
β”‚   β”‚   β”œβ”€β”€ main.tf          # VPC, IGW, public subnets, public route table
β”‚   β”‚   β”œβ”€β”€ variables.tf
β”‚   β”‚   └── outputs.tf
β”‚   └── compute/
β”‚       β”œβ”€β”€ main.tf          # Public EC2 + Security Group
β”‚       β”œβ”€β”€ variables.tf
β”‚       └── outputs.tf
└── docs/screenshots/step1/

Screenshots

Step Screenshot
βœ… VPC Created VPC Created
βœ… Internet Gateway Attached IGW
βœ… Public Subnets Created Public Subnets
βœ… Public Route Table with IGW Route Public RT
βœ… Public Route Table Associations RT Associations
βœ… EC2 in Public Subnet (Launch Config) EC2 Public Details
βœ… Security Group Rules SG Rules
βœ… Terraform Apply Output Terraform Output

Security Highlights

  • Basic segregation of subnets β†’ Public vs private
  • Security Groups β†’ Limit inbound traffic
  • Foundation β†’ Compliance-ready design

ISO/IEC 27001 Annex A Mapping

  • A.8.24 Data leakage prevention β†’ Security Group rules
  • A.5.23 Cloud security β†’ Segregated subnet design

Step 2

Terraform Secure VPC + EC2 β€” Step 2 (Private EC2 via SSM)


Project Description

This step extends the baseline VPC (Step 1) by adding a private application tier. The design ensures the EC2 instance is not exposed to the internet and is managed securely via AWS Systems Manager Session Manager.


What This Project Proves:

  • I can design and codify a bastionless architecture using Terraform.
  • I enforce least-privilege networking (egress-only, no inbound).
  • I apply security best practices: IMDSv2, EBS encryption, IAM roles, SSM access.
  • I map controls to ISO/IEC 27001 Annex A for compliance readiness.

Project Structure (Step 2)

terraform-secure-vpc-ec2/
β”œβ”€β”€ main.tf
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ network/
β”‚   β”‚   β”œβ”€β”€ private.tf           # Private subnets + NAT Gateway
β”‚   └── compute/
β”‚       β”œβ”€β”€ private.tf           # Private EC2 (SSM only, IMDSv2, encrypted EBS)
└── docs/screenshots/step2/

Screenshots (Step 2)

Step Screenshot
βœ… Private Subnets Created Private Subnets
βœ… NAT EIP Allocated NAT EIP
βœ… NAT Gateway Available NAT Gateway
βœ… Private Route Table with NAT Route Private RT
βœ… Private Route Table Associations Private RT Associations
βœ… EC2 in Private Subnet (No Public IP, SSM Role) EC2 Private Details
βœ… SSM Managed Instance SSM Managed
βœ… SSM Session Active SSM Session
βœ… Terraform Apply Output Terraform Output

Security Highlights

  • No inbound exposure β†’ EC2 has no public IP, no SSH
  • Bastionless access β†’ Managed exclusively through AWS Systems Manager Session Manager
  • Egress-only SG β†’ Outbound ports 80/443 only (updates + SSM traffic)
  • IMDSv2 enforced β†’ Protects against SSRF credential theft
  • Encrypted EBS volumes β†’ Data at rest protected by default
  • IAM role with SSM policy β†’ Principle of least privilege for instance management

ISO/IEC 27001 Annex A Mapping

  • A.8.20 Use of cryptography β†’ Encrypted EBS volumes
  • A.8.28 Secure authentication β†’ IMDSv2 required
  • A.8.24 Data leakage prevention β†’ No public IP, egress-only networking
  • A.5.23 Cloud security β†’ Private subnets, bastionless access via SSM
  • A.8.16 Identity & access control β†’ Scoped IAM role for SSM access

Step 3

Terraform Secure VPC + EC2 β€” Step 3 (Centralized Logging & VPC Endpoints)

Project Description

This step enforces centralized logging, encryption, and private connectivity. It ensures auditability and compliance through VPC Flow Logs, KMS protection, and private VPC Endpoints.


What This Step Proves

  • I can enforce encryption at rest & in transit.
  • I can design centralized logging with KMS protection.
  • I can configure VPC Endpoints for private-only traffic.
  • I can demonstrate compliance mapping with ISO/IEC 27001.

Project Structure (Step 3)

terraform-secure-vpc-ec2/
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ compute/
β”‚   β”‚   β”œβ”€β”€ step3_encryption.tf      # Encrypted EBS volumes
β”‚   └── network/
β”‚       β”œβ”€β”€ step3_endpoints+logging.tf  # VPC Endpoints + Flow Logs
└── docs/screenshots/step3/

Screenshots (Step 3)

Step Screenshot
βœ… Default EBS Encryption Enabled ebs-default-encryption
βœ… EC2 Root Volume Encrypted ec2-root-volume-encrypted
βœ… KMS CMK Created for Logs kms-logs-key
βœ… VPC Flow Logs Active vpc-flowlogs-status
βœ… VPC Endpoint (Gateway for S3) vpce-gateway-s3
βœ… VPC Endpoints (SSM, EC2 Messages) vpce-interface-ssm
βœ… Security Group Scoped to HTTPS vpce-sg-inbound
βœ… Logs S3 Bucket with SSE-KMS logs-s3-properties
βœ… Flow Logs Delivered to S3 logs-s3-flowlogs-object

Security Highlights

  • EBS encryption β†’ Default + CMK for compliance
  • Centralized logging β†’ Flow Logs β†’ S3 (SSE-KMS)
  • Private connectivity β†’ SSM & S3 endpoints, no internet traversal
  • Scoped Security Group β†’ Only HTTPS traffic allowed
  • Bastionless management β†’ EC2 via SSM only

ISO/IEC 27001 Annex A Mapping

  • A.8.24 Use of cryptography β†’ EBS default encryption, SSE-KMS for logs
  • A.8.15 Logging β†’ VPC Flow Logs capture all traffic events
  • A.8.16 Monitoring activities β†’ Logs delivered to encrypted S3 bucket with restricted access policy
  • A.8.12 Data leakage prevention β†’ VPC Endpoints restrict traffic paths
  • A.5.23 Information security for use of cloud services β†’ Private-only design with centralized audit trail
  • A.8.16 Identity & access control β†’ IAM role for SSM (least privilege)
  • A.8.28 Secure authentication β†’ IMDSv2 enforced

About

Terraform Secure VPC + EC2 (Step 1,2,3). Hardened AWS IaC with centralized logging, encrypted storage, private endpoints, and ISO/IEC 27001 control mapping.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages