Skip to content

Commit

Permalink
Merge branch 'tf'
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelberston committed Nov 19, 2024
2 parents 1eb1372 + 3a5e691 commit 640bf6a
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 79 deletions.
Empty file added terraform/ecr.tf
Empty file.
20 changes: 20 additions & 0 deletions terraform/eks.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 19.0"

cluster_name = "secure-auth-cluster"
cluster_version = "1.27"

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets

eks_managed_node_groups = {
default = {
min_size = 1
max_size = 3
desired_size = 2

instance_types = ["t3.medium"]
}
}
}
1 change: 1 addition & 0 deletions terraform/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// IAM policies
80 changes: 1 addition & 79 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,4 @@ provider "aws" {
region = var.region
}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"

name = "secure-auth-vpc"
cidr = "10.0.0.0/16"

azs = ["${var.region}a", "${var.region}b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]

enable_nat_gateway = true
}

module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 19.0"

cluster_name = "secure-auth-cluster"
cluster_version = "1.27"

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets

eks_managed_node_groups = {
default = {
min_size = 1
max_size = 3
desired_size = 2

instance_types = ["t3.medium"]
}
}
}

// Security group for RDS
resource "aws_security_group" "rds" {
name = "secure-auth-rds-sg"
description = "Security group for RDS instance"
vpc_id = module.vpc.vpc_id

ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
security_groups = [module.eks.cluster_security_group_id]
}
}

// RDS subnet group
resource "aws_db_subnet_group" "rds" {
name = "secure-auth-rds-subnet-group"
subnet_ids = module.vpc.private_subnets
}

// RDS instance
resource "aws_db_instance" "postgres" {
identifier = "secure-auth-db"
engine = "postgres"
engine_version = "14.7"
instance_class = "db.t3.micro" // Adjust based on your needs
allocated_storage = 20

db_name = "secureauthdb"
// Update to use AWS Secrets Manager
username = var.db_username
password = var.db_password

db_subnet_group_name = aws_db_subnet_group.rds.name
vpc_security_group_ids = [aws_security_group.rds.id]

skip_final_snapshot = true // Set to false for production

# Disable public access
publicly_accessible = false

tags = {
Name = "secure-auth-postgres-rds"
}
}
// backend
1 change: 1 addition & 0 deletions terraform/monitoring.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: Set up CloudTrail & CloudWatch
45 changes: 45 additions & 0 deletions terraform/rds.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Security group for RDS
resource "aws_security_group" "rds" {
name = "secure-auth-rds-sg"
description = "Security group for RDS instance"
vpc_id = module.vpc.vpc_id

ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
security_groups = [module.eks.cluster_security_group_id]
}
}

// RDS subnet group
resource "aws_db_subnet_group" "rds" {
name = "secure-auth-rds-subnet-group"
subnet_ids = module.vpc.private_subnets
}

// RDS instance
resource "aws_db_instance" "postgres" {
identifier = "secure-auth-db"
engine = "postgres"
engine_version = "14.7"
instance_class = "db.t3.micro" // Adjust based on your needs
allocated_storage = 20

db_name = "secureauthdb"
// Update to use AWS Secrets Manager
username = var.db_username
password = var.db_password

db_subnet_group_name = aws_db_subnet_group.rds.name
vpc_security_group_ids = [aws_security_group.rds.id]

skip_final_snapshot = true // Set to false for production

# Disable public access
publicly_accessible = false

tags = {
Name = "secure-auth-postgres-rds"
}
}
14 changes: 14 additions & 0 deletions terraform/vpc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module "vpc" {
source = "terraform-aws-modules/vpc/aws"

name = "secure-auth-vpc"
cidr = "10.0.0.0/16"

azs = ["${var.region}a", "${var.region}b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]

enable_nat_gateway = true
}

// subnets, NAT Gateways, Security Groups, etc.

0 comments on commit 640bf6a

Please sign in to comment.