This repository contains Terraform configurations for setting up a AWS infrastructure with EC2 instances, VPC networking, and Systems Manager integration.
-
S3 Backend
- S3 bucket for Terraform state
- DynamoDB table for state locking
- Versioning and encryption enabled
-
Networking
- VPC with custom CIDR (10.0.0.0/16)
- Public subnet in eu-central-1a
- Internet Gateway
- Route tables and associations
- VPC Endpoints for SSM connectivity:
- SSM endpoint
- SSM messages endpoint
- EC2 messages endpoint
- S3 gateway endpoint
-
Compute
- 3x EC2 instances (c7a.medium)
- Ubuntu 20.04 LTS AMI
- Auto-generated SSH key pair
- SSM Agent installed and configured
-
Security
- Security groups for SSH and SSM access
- IAM roles and instance profiles for SSM
- Network ACLs and routing rules
- AWS CLI installed and configured
- Terraform v1.0.0 or later
- AWS account with appropriate permissions
.
├── backend.tf # S3 backend configuration
├── main.tf # Main infrastructure configuration
├── terraform.tfvars # Variable values (not in git)
└── README.md
- Initialize Backend Infrastructure
# In the directory with backend.tf
terraform init
terraform apply
- Deploy Main Infrastructure
# In the directory with main.tf
terraform init
terraform apply
- Accessing Instances
Via SSM:
# Using AWS CLI
aws ssm start-session --target i-1234567890abcdef0
# Or use AWS Console:
# Navigate to Systems Manager → Session Manager → Start Session
Via SSH (backup method):
# Save the private key
terraform output -raw private_key > terraform-key-pair.pem
chmod 400 terraform-key-pair.pem
# Connect
ssh -i terraform-key-pair.pem ubuntu@<instance-public-ip>
All resources are tagged with:
Name = "ec2-testing"
region = "eu"
solution = "1nce-connect"
environment = "dev"
component = "kubemajik"
owner = "andrejs.kuidins"