Skip to content

Commit

Permalink
eks_fargate_cluster updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Amits64 committed Aug 20, 2024
1 parent e7a0425 commit dcb6940
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 26 deletions.
29 changes: 22 additions & 7 deletions eks_fargate_cluster/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
terraform {
cloud {

organization = "SFBTraining"

workspaces {
name = "eks_fargate"
}
}
}

provider "aws" {
region = var.region
}
Expand All @@ -7,19 +18,23 @@ module "vpc" {
}

module "eks" {
source = "./modules/eks"
vpc_id = module.vpc.vpc_id
subnets = module.vpc.private_subnets
source = "./modules/eks"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
}

module "fargate" {
source = "./modules/fargate"
source = "./modules/fargate"
cluster_name = module.eks.cluster_name
subnet_ids = module.vpc.private_subnets
subnet_ids = module.vpc.private_subnets
fargate_profile_name = var.fargate_profile_name
namespace = var.namespace
tags = var.tags
}

module "alb" {
source = "./modules/alb"
source = "./modules/alb"
cluster_name = module.eks.cluster_name
vpc_id = module.vpc.vpc_id
vpc_id = module.vpc.vpc_id
region = var.region
}
4 changes: 1 addition & 3 deletions eks_fargate_cluster/modules/eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ module "eks" {
source = "terraform-aws-modules/eks/aws"
cluster_name = var.cluster_name
cluster_version = var.cluster_version
subnets = var.subnets
vpc_id = var.vpc_id

manage_aws_auth = true
subnet_ids = var.subnet_ids

tags = var.tags
}
6 changes: 3 additions & 3 deletions eks_fargate_cluster/modules/eks/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
variable "cluster_name" {
description = "The name of the EKS cluster"
type = string
default = "my-eks-cluster"
default = "production-eks-cluster"
}

variable "cluster_version" {
Expand All @@ -10,7 +10,7 @@ variable "cluster_version" {
default = "1.28"
}

variable "subnets" {
variable "subnet_ids" {
description = "A list of subnet IDs for the EKS cluster"
type = list(string)
}
Expand All @@ -24,6 +24,6 @@ variable "tags" {
description = "A map of tags to add to all resources"
type = map(string)
default = {
Name = "my-eks-cluster"
Name = "production-eks-cluster"
}
}
28 changes: 26 additions & 2 deletions eks_fargate_cluster/modules/fargate/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
resource "aws_eks_fargate_profile" "example" {
resource "aws_iam_role" "eks_fargate_pod_execution_role" {
name = "eks-fargate-pod-execution-role"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
Service = "eks-fargate-pods.amazonaws.com"
}
Action = "sts:AssumeRole"
}
]
})

tags = var.tags
}

resource "aws_iam_role_policy_attachment" "eks_fargate_pod_execution_role_policy" {
role = aws_iam_role.eks_fargate_pod_execution_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSFargatePodExecutionRolePolicy"
}

resource "aws_eks_fargate_profile" "production" {
cluster_name = var.cluster_name
fargate_profile_name = var.fargate_profile_name
pod_execution_role_arn = var.pod_execution_role_arn
pod_execution_role_arn = aws_iam_role.eks_fargate_pod_execution_role.arn
subnet_ids = var.subnet_ids

selector {
Expand Down
6 changes: 5 additions & 1 deletion eks_fargate_cluster/modules/fargate/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
output "fargate_profile_name" {
value = aws_eks_fargate_profile.example.fargate_profile_name
value = aws_eks_fargate_profile.production.fargate_profile_name
}

output "pod_execution_role_arn" {
value = aws_iam_role.eks_fargate_pod_execution_role.arn
}
15 changes: 8 additions & 7 deletions eks_fargate_cluster/modules/fargate/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ variable "cluster_name" {
variable "fargate_profile_name" {
description = "The name of the Fargate profile"
type = string
default = "example"
}

variable "pod_execution_role_arn" {
description = "The ARN of the pod execution role"
type = string
default = "production-fargate-profile"
}

variable "subnet_ids" {
Expand All @@ -22,5 +17,11 @@ variable "subnet_ids" {
variable "namespace" {
description = "The namespace for the Fargate profile"
type = string
default = "default"
default = "production"
}

variable "tags" {
description = "A map of tags to add to all resources"
type = map(string)
default = {}
}
6 changes: 3 additions & 3 deletions eks_fargate_cluster/modules/vpc/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
variable "vpc_name" {
description = "The name of the VPC"
type = string
default = "eks-vpc"
default = "production-vpc"
}

variable "vpc_cidr" {
Expand All @@ -13,7 +13,7 @@ variable "vpc_cidr" {
variable "azs" {
description = "A list of availability zones"
type = list(string)
default = ["us-west-2a", "us-west-2b", "us-west-2c"]
default = ["us-east-1a", "us-east-1b", "us-east-1c"]
}

variable "private_subnets" {
Expand Down Expand Up @@ -44,6 +44,6 @@ variable "tags" {
description = "A map of tags to add to all resources"
type = map(string)
default = {
Name = "eks-vpc"
Name = "production-vpc"
}
}
6 changes: 6 additions & 0 deletions eks_fargate_cluster/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
region = "us-east-1"
fargate_profile_name = "production-fargate-profile"
namespace = "production"
tags = {
Environment = "production"
}
20 changes: 20 additions & 0 deletions eks_fargate_cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@ variable "region" {
type = string
default = "us-east-1"
}

variable "fargate_profile_name" {
description = "The name of the Fargate profile"
type = string
default = "production-fargate-profile"
}

variable "namespace" {
description = "The namespace for the Fargate profile"
type = string
default = "production"
}

variable "tags" {
description = "A map of tags to add to all resources"
type = map(string)
default = {
Environment = "production"
}
}

0 comments on commit dcb6940

Please sign in to comment.