From 058a556184ebd0f8fcb6c4f6d774bc1bf4dfe9bc Mon Sep 17 00:00:00 2001 From: ubaniobiajulumemmanuel Date: Mon, 8 Dec 2025 16:29:30 +0100 Subject: [PATCH 1/3] feat(bank31): add ECR module and root module call --- ecr-setup.tf | 8 ++++++++ modules/ecr/main.tf | 10 ++++++++++ modules/ecr/outputs.tf | 6 ++++++ modules/ecr/variables.tf | 3 +++ 4 files changed, 27 insertions(+) create mode 100644 ecr-setup.tf create mode 100644 modules/ecr/main.tf create mode 100644 modules/ecr/outputs.tf create mode 100644 modules/ecr/variables.tf diff --git a/ecr-setup.tf b/ecr-setup.tf new file mode 100644 index 0000000..1627c27 --- /dev/null +++ b/ecr-setup.tf @@ -0,0 +1,8 @@ +module "bank31_ecr" { + source = "./modules/ecr" + + repo_names = { + frontend = "bank31-frontend" + backend = "bank31-backend" + } +} diff --git a/modules/ecr/main.tf b/modules/ecr/main.tf new file mode 100644 index 0000000..fb7f81d --- /dev/null +++ b/modules/ecr/main.tf @@ -0,0 +1,10 @@ +resource "aws_ecr_repository" "this" { + for_each = var.repo_names + + name = each.value + image_tag_mutability = "MUTABLE" + + image_scanning_configuration { + scan_on_push = true + } +} diff --git a/modules/ecr/outputs.tf b/modules/ecr/outputs.tf new file mode 100644 index 0000000..fb367b5 --- /dev/null +++ b/modules/ecr/outputs.tf @@ -0,0 +1,6 @@ +output "repositories" { + value = { + for name, repo in aws_ecr_repository.this : + name => repo.repository_url + } +} diff --git a/modules/ecr/variables.tf b/modules/ecr/variables.tf new file mode 100644 index 0000000..2656ab4 --- /dev/null +++ b/modules/ecr/variables.tf @@ -0,0 +1,3 @@ +variable "repo_names" { + type = map(string) +} From 3453c24b76a9e819f68c2123a230e5816dbffb90 Mon Sep 17 00:00:00 2001 From: ubaniobiajulumemmanuel Date: Mon, 8 Dec 2025 20:06:09 +0100 Subject: [PATCH 2/3] feat(bank31): add ECR module and root module call --- 2MFA/main.tf | 30 +++--- 2MFA/mfa.tf | 2 +- bank-infra/backend.tf | 2 +- bank-infra/bootstrap/terraform.tfvars | 10 +- bank-infra/dev/01-provider.tf | 12 +-- bank-infra/dev/main.tf | 86 +++++++++--------- bank-infra/dev/terraform.tfvars | 32 +++---- bank-infra/dev/variable.tf | 16 ++-- bank-infra/modules/module-database/mysql.tf | 26 +++--- .../module-dns/namecheap-name-servers.tf | 6 +- bank-infra/modules/module-dns/output.tf | 4 +- bank-infra/modules/module-dns/provider.tf | 2 +- .../modules/module-dns/r52-hosted-zone.tf | 46 +++++----- bank-infra/modules/module-dns/variables.tf | 4 +- bank-infra/modules/module-eks/addons.tf | 66 +++++++------- .../modules/module-eks/eks-node-group.tf | 10 +- .../module-eks/eks-node-groups-role.tf | 10 +- bank-infra/modules/module-eks/eks-role.tf | 2 +- bank-infra/modules/module-eks/eks.tf | 32 +++---- bank-infra/modules/module-eks/variables.tf | 16 ++-- bank-infra/modules/module-vpc/02-vpc.tf | 10 +- bank-infra/modules/module-vpc/03-igt.tf | 2 +- .../modules/module-vpc/04-public_subnet.tf | 24 ++--- .../modules/module-vpc/05-private_subnets.tf | 24 ++--- bank-infra/modules/module-vpc/06-elp.tf | 12 +-- .../modules/module-vpc/07-nat-gateway.tf | 14 +-- .../module-vpc/08-private-route-table.tf | 10 +- .../module-vpc/09-public-route-table.tf | 6 +- .../module-vpc/10-public-route-associate.tf | 4 +- .../module-vpc/11-private-route-associate.tf | 12 +-- .../module-vpc/12-private-subnet-db.tf | 24 ++--- bank-infra/modules/module-vpc/13-mysql-sg.tf | 4 +- bank-infra/modules/module-vpc/output.tf | 6 +- bank-infra/modules/module-vpc/variables.tf | 6 +- bank-infra/prod/01-provider.tf | 12 +-- bank-infra/prod/main.tf | 86 +++++++++--------- bank-infra/prod/terraform.tfvars | 32 +++---- bank-infra/prod/variable.tf | 16 ++-- bank-infra/staging/01-provider.tf | 12 +-- bank-infra/staging/main.tf | 86 +++++++++--------- bank-infra/staging/terraform.tfvars | 32 +++---- bank-infra/staging/variable.tf | 16 ++-- bootstrap/s3.tf | 2 +- bootstrap/terraform.tfvars | 2 +- dev/01-provider.tf | 12 +-- dev/main.tf | 86 +++++++++--------- dev/terraform.tfvars | 32 +++---- dev/variable.tf | 16 ++-- ecrplan | Bin 0 -> 4449 bytes eks/cluster.tf | 8 ++ eks/eks.tf | 31 +++++++ eks/iam.tf | 51 +++++++++++ eks/main.tf | 8 ++ eks/nodeGroup.tf | 8 ++ eks/output.tf | 15 +++ eks/provider.tf | 10 ++ eks/variables.tf | 7 ++ eks/vpc.tf | 43 +++++++++ main.tf | 0 modules/module-database/mysql.tf | 26 +++--- modules/module-dns/namecheap-name-servers.tf | 6 +- modules/module-dns/output.tf | 4 +- modules/module-dns/provider.tf | 2 +- modules/module-dns/r52-hosted-zone.tf | 46 +++++----- modules/module-dns/variables.tf | 4 +- modules/module-eks/addons.tf | 66 +++++++------- modules/module-eks/eks-node-group.tf | 10 +- modules/module-eks/eks-node-groups-role.tf | 10 +- modules/module-eks/eks-role.tf | 2 +- modules/module-eks/eks.tf | 32 +++---- modules/module-eks/variables.tf | 16 ++-- modules/module-vpc/02-vpc.tf | 10 +- modules/module-vpc/03-igt.tf | 2 +- modules/module-vpc/04-public_subnet.tf | 24 ++--- modules/module-vpc/05-private_subnets.tf | 24 ++--- modules/module-vpc/06-elp.tf | 12 +-- modules/module-vpc/07-nat-gateway.tf | 14 +-- modules/module-vpc/08-private-route-table.tf | 10 +- modules/module-vpc/09-public-route-table.tf | 6 +- .../module-vpc/10-public-route-associate.tf | 4 +- .../module-vpc/11-private-route-associate.tf | 12 +-- modules/module-vpc/12-private-subnet-db.tf | 24 ++--- modules/module-vpc/13-mysql-sg.tf | 4 +- modules/module-vpc/output.tf | 6 +- modules/module-vpc/variables.tf | 6 +- prod/01-provider.tf | 12 +-- prod/main.tf | 86 +++++++++--------- prod/terraform.tfvars | 32 +++---- prod/variable.tf | 16 ++-- staging/01-provider.tf | 12 +-- staging/main.tf | 86 +++++++++--------- staging/terraform.tfvars | 32 +++---- staging/variable.tf | 16 ++-- tfplan | Bin 0 -> 2223 bytes variables.tf | 0 95 files changed, 1025 insertions(+), 844 deletions(-) create mode 100644 ecrplan create mode 100644 eks/cluster.tf create mode 100644 eks/eks.tf create mode 100644 eks/iam.tf create mode 100644 eks/main.tf create mode 100644 eks/nodeGroup.tf create mode 100644 eks/output.tf create mode 100644 eks/provider.tf create mode 100644 eks/variables.tf create mode 100644 eks/vpc.tf create mode 100644 main.tf create mode 100644 tfplan create mode 100644 variables.tf diff --git a/2MFA/main.tf b/2MFA/main.tf index 5a27725..0cbc183 100644 --- a/2MFA/main.tf +++ b/2MFA/main.tf @@ -38,7 +38,7 @@ variable "apply_to_all_users" { # ============================================================================ terraform { required_version = ">= 1.0" - + required_providers { aws = { source = "hashicorp/aws" @@ -66,7 +66,7 @@ data "aws_iam_policy_document" "require_mfa" { statement { sid = "DenyAllExceptMFASetupWithoutMFA" effect = "Deny" - + not_actions = [ "iam:CreateVirtualMFADevice", "iam:EnableMFADevice", @@ -80,52 +80,52 @@ data "aws_iam_policy_document" "require_mfa" { "iam:GetAccountSummary", "iam:ListAccountAliases", ] - + resources = ["*"] - + condition { test = "BoolIfExists" variable = "aws:MultiFactorAuthPresent" values = ["false"] } } - + # Allow viewing account information statement { sid = "AllowViewAccountInfo" effect = "Allow" - + actions = [ "iam:GetAccountPasswordPolicy", "iam:GetAccountSummary", "iam:ListVirtualMFADevices", "iam:ListAccountAliases", ] - + resources = ["*"] } - + # Allow managing own passwords and access keys statement { sid = "AllowManageOwnPasswordsAndAccessKeys" effect = "Allow" - + actions = [ "iam:ChangePassword", "iam:GetUser", "iam:GetLoginProfile", ] - + resources = [ "arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/$${aws:username}" ] } - + # Allow managing own MFA devices statement { sid = "AllowManageOwnMFADevices" effect = "Allow" - + actions = [ "iam:CreateVirtualMFADevice", "iam:DeleteVirtualMFADevice", @@ -134,7 +134,7 @@ data "aws_iam_policy_document" "require_mfa" { "iam:ResyncMFADevice", "iam:DeactivateMFADevice", ] - + resources = [ "arn:aws:iam::${data.aws_caller_identity.current.account_id}:mfa/$${aws:username}", "arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/$${aws:username}", @@ -175,7 +175,7 @@ resource "aws_iam_group_policy_attachment" "mfa_enforcement" { # ============================================================================ resource "aws_iam_group_membership" "mfa_required_users" { count = length(var.users_requiring_mfa) > 0 ? 1 : 0 - + name = "${var.mfa_required_group_name}-membership" group = aws_iam_group.mfa_required.name users = var.users_requiring_mfa @@ -185,7 +185,7 @@ resource "aws_iam_group_membership" "mfa_required_users" { # ============================================================================ resource "aws_iam_user_policy_attachment" "mfa_all_users" { for_each = var.apply_to_all_users ? toset(data.aws_iam_users.all[0].names) : toset([]) - + user = each.value policy_arn = aws_iam_policy.require_mfa.arn } diff --git a/2MFA/mfa.tf b/2MFA/mfa.tf index f2cb999..5094149 100644 --- a/2MFA/mfa.tf +++ b/2MFA/mfa.tf @@ -1,4 +1,4 @@ -aws_region = "us-east-1" +aws_region = "us-east-1" mfa_policy_name = "RequireMFAPolicy" mfa_required_group_name = "MFARequiredUsers" diff --git a/bank-infra/backend.tf b/bank-infra/backend.tf index 8aa45b9..45717d3 100644 --- a/bank-infra/backend.tf +++ b/bank-infra/backend.tf @@ -2,7 +2,7 @@ terraform { required_version = ">= 1.10.0" backend "s3" { - bucket = "pod4bankapp-tfstate-bucket" # must be created first + bucket = "pod4bankapp-tfstate-bucket" # must be created first key = "envs/dev/terraform.tfstate" region = "us-east-1" use_lockfile = true diff --git a/bank-infra/bootstrap/terraform.tfvars b/bank-infra/bootstrap/terraform.tfvars index 22534a8..6d4698e 100644 --- a/bank-infra/bootstrap/terraform.tfvars +++ b/bank-infra/bootstrap/terraform.tfvars @@ -1,5 +1,5 @@ -project = "pod4bankapp" -environment = "bootstrap" -aws_region = "us-east-1" -bucket_name = "pod4bankapp-tfstate-bucket" -dynamodb_table_name = "pod4bankapp-tf-locks" +project = "pod4bankapp" +environment = "bootstrap" +aws_region = "us-east-1" +bucket_name = "pod4bankapp-tfstate-bucket" +dynamodb_table_name = "pod4bankapp-tf-locks" diff --git a/bank-infra/dev/01-provider.tf b/bank-infra/dev/01-provider.tf index e987edf..db65d0a 100644 --- a/bank-infra/dev/01-provider.tf +++ b/bank-infra/dev/01-provider.tf @@ -6,21 +6,21 @@ terraform { required_providers { namecheap = { - source = "namecheap/namecheap" + source = "namecheap/namecheap" version = "2.2.0" } aws = { - source = "hashicorp/aws" + source = "hashicorp/aws" version = "6.0.0-beta2" } } } provider "namecheap" { - user_name = var.namecheap_username - api_user = var.namecheap_api_user - api_key = var.namecheap_api_key - client_ip = var.namecheap_client_ip + user_name = var.namecheap_username + api_user = var.namecheap_api_user + api_key = var.namecheap_api_key + client_ip = var.namecheap_client_ip use_sandbox = false } provider "aws" { diff --git a/bank-infra/dev/main.tf b/bank-infra/dev/main.tf index ecebd57..8fdb6b1 100644 --- a/bank-infra/dev/main.tf +++ b/bank-infra/dev/main.tf @@ -1,57 +1,57 @@ # Creating a VPC and EKS cluster using Terraform module "vpc-deployment" { - source = "./module-vpc" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - + source = "./module-vpc" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + } #creating an EKS cluster using Terraform # and deploying it in the VPC created above module "eks-deployment" { - source = "./module-eks" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - desired_size = var.desired_size - max_size = var.max_size - min_size = var.min_size - instance_types = var.instance_types - capacity_type = var.capacity_type - public_subnet_ids = module.vpc-deployment.public_subnet_ids - private_subnet_ids = module.vpc-deployment.private_subnet_ids - cluster_name = var.cluster_name - repository_name = var.repository_name - domain-name = var.domain-name - email = var.email - + source = "./module-eks" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + desired_size = var.desired_size + max_size = var.max_size + min_size = var.min_size + instance_types = var.instance_types + capacity_type = var.capacity_type + public_subnet_ids = module.vpc-deployment.public_subnet_ids + private_subnet_ids = module.vpc-deployment.private_subnet_ids + cluster_name = var.cluster_name + repository_name = var.repository_name + domain-name = var.domain-name + email = var.email + } module "namecheap-deployment" { - source = "./module-dns" - environment = var.environment - domain-name = var.domain-name - nginx_lb_ip = module.eks-deployment.nginx_lb_ip - nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname - nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns - + source = "./module-dns" + environment = var.environment + domain-name = var.domain-name + nginx_lb_ip = module.eks-deployment.nginx_lb_ip + nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname + nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns + } module "rds-mysql-deployment" { - source = "./module-database" - environment = var.environment - db_instance_class = var.db_instance_class - db_allocated_storage = var.db_allocated_storage - private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids - db_name = var.db_name - db_password = var.db_password - db_username = var.db_username - aws_security_group_ids = module.vpc-deployment.aws_security_group_ids + source = "./module-database" + environment = var.environment + db_instance_class = var.db_instance_class + db_allocated_storage = var.db_allocated_storage + private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids + db_name = var.db_name + db_password = var.db_password + db_username = var.db_username + aws_security_group_ids = module.vpc-deployment.aws_security_group_ids } \ No newline at end of file diff --git a/bank-infra/dev/terraform.tfvars b/bank-infra/dev/terraform.tfvars index 42fc12e..4a84a00 100644 --- a/bank-infra/dev/terraform.tfvars +++ b/bank-infra/dev/terraform.tfvars @@ -1,17 +1,17 @@ -environment = "production" -vpc_cidrblock = "192.168.0.0/16" -countsub = 2 -create_subnet = true +environment = "production" +vpc_cidrblock = "192.168.0.0/16" +countsub = 2 +create_subnet = true create_elastic_ip = true -desired_size = 2 -max_size = 6 -min_size = 2 -instance_types = ["t2.medium"] -capacity_type = "ON_DEMAND" -ami_type = "AL2_x86_64" -label_one = "system-nodepool" -eks_version = "1.32" -domain-name = "cloudwitches.online" -cluster_name = "eks-cluster" -repository_name = "eks-repository" -email = "support@digitalwitchng.online" +desired_size = 2 +max_size = 6 +min_size = 2 +instance_types = ["t2.medium"] +capacity_type = "ON_DEMAND" +ami_type = "AL2_x86_64" +label_one = "system-nodepool" +eks_version = "1.32" +domain-name = "cloudwitches.online" +cluster_name = "eks-cluster" +repository_name = "eks-repository" +email = "support@digitalwitchng.online" diff --git a/bank-infra/dev/variable.tf b/bank-infra/dev/variable.tf index f283b35..82bf36f 100644 --- a/bank-infra/dev/variable.tf +++ b/bank-infra/dev/variable.tf @@ -2,14 +2,14 @@ variable "vpc_cidrblock" { description = "CIDR block for the VPC" type = string default = "192.168.0.0/16" - + } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "staging" - + } variable "create_subnet" { @@ -22,7 +22,7 @@ variable "countsub" { description = "Number of subnets to create" type = number default = 2 - + } variable "create_elastic_ip" { description = "Flag to create Elastic IPs" @@ -46,14 +46,14 @@ variable "max_size" { variable "min_size" { description = "Minimum size of the EKS node group" type = number - default = 2 + default = 2 } variable "instance_types" { description = "Instance types for the EKS node group" type = list(string) - default = ["t2.micro"] -} + default = ["t2.micro"] +} variable "capacity_type" { description = "Capacity type for the EKS node group" @@ -115,7 +115,7 @@ variable "namecheap_client_ip" { variable "db_instance_class" { description = "Instance class for the RDS database" type = string - default = "db.t3.micro" + default = "db.t3.micro" } variable "db_allocated_storage" { @@ -158,7 +158,7 @@ variable "repository_name" { description = "Name of the ECR repository" type = string default = "eks-repository" - + } variable "email" { diff --git a/bank-infra/modules/module-database/mysql.tf b/bank-infra/modules/module-database/mysql.tf index 72e8c20..b22f6ab 100644 --- a/bank-infra/modules/module-database/mysql.tf +++ b/bank-infra/modules/module-database/mysql.tf @@ -8,18 +8,18 @@ resource "aws_db_subnet_group" "mysql_subnet_group" { } } resource "aws_db_instance" "mysql_db_instance" { - identifier = "${var.environment}-mysql-db" - engine = "mysql" - engine_version = "8.0" - instance_class = var.db_instance_class - allocated_storage = var.db_allocated_storage - storage_type = "gp2" - db_subnet_group_name = aws_db_subnet_group.mysql_subnet_group.name - vpc_security_group_ids = [var.aws_security_group_ids] - username = var.db_username - password = var.db_password - db_name = var.db_name - skip_final_snapshot = true + identifier = "${var.environment}-mysql-db" + engine = "mysql" + engine_version = "8.0" + instance_class = var.db_instance_class + allocated_storage = var.db_allocated_storage + storage_type = "gp2" + db_subnet_group_name = aws_db_subnet_group.mysql_subnet_group.name + vpc_security_group_ids = [var.aws_security_group_ids] + username = var.db_username + password = var.db_password + db_name = var.db_name + skip_final_snapshot = true tags = { Name = "${var.environment}-mysql-db-instance" @@ -29,5 +29,5 @@ resource "aws_db_instance" "mysql_db_instance" { lifecycle { ignore_changes = [password] } - + } \ No newline at end of file diff --git a/bank-infra/modules/module-dns/namecheap-name-servers.tf b/bank-infra/modules/module-dns/namecheap-name-servers.tf index aea16c8..59750eb 100644 --- a/bank-infra/modules/module-dns/namecheap-name-servers.tf +++ b/bank-infra/modules/module-dns/namecheap-name-servers.tf @@ -1,7 +1,7 @@ resource "namecheap_domain_records" "my-domain2-com" { domain = var.domain-name - mode = "OVERWRITE" // Warning: this will remove all manually set records + mode = "OVERWRITE" // Warning: this will remove all manually set records -nameservers = aws_route53_zone.r53_zone.name_servers -depends_on = [ aws_route53_zone.r53_zone ] + nameservers = aws_route53_zone.r53_zone.name_servers + depends_on = [aws_route53_zone.r53_zone] } \ No newline at end of file diff --git a/bank-infra/modules/module-dns/output.tf b/bank-infra/modules/module-dns/output.tf index af3324f..741017a 100644 --- a/bank-infra/modules/module-dns/output.tf +++ b/bank-infra/modules/module-dns/output.tf @@ -1,4 +1,4 @@ output "route53_name_servers" { - description = "The name servers of the Route 53 hosted zone" - value = aws_route53_zone.r53_zone.name_servers + description = "The name servers of the Route 53 hosted zone" + value = aws_route53_zone.r53_zone.name_servers } diff --git a/bank-infra/modules/module-dns/provider.tf b/bank-infra/modules/module-dns/provider.tf index f4a0a7d..ded4f97 100644 --- a/bank-infra/modules/module-dns/provider.tf +++ b/bank-infra/modules/module-dns/provider.tf @@ -1,7 +1,7 @@ terraform { required_providers { namecheap = { - source = "namecheap/namecheap" + source = "namecheap/namecheap" version = ">= 2.0.0" } } diff --git a/bank-infra/modules/module-dns/r52-hosted-zone.tf b/bank-infra/modules/module-dns/r52-hosted-zone.tf index e1b209c..cb44111 100644 --- a/bank-infra/modules/module-dns/r52-hosted-zone.tf +++ b/bank-infra/modules/module-dns/r52-hosted-zone.tf @@ -1,32 +1,32 @@ resource "aws_route53_zone" "r53_zone" { - name = var.domain-name - comment = "Managed by Terraform" - force_destroy = true - - tags = { - Name = "${var.environment}-hosted-zone" - Environment = var.environment - } + name = var.domain-name + comment = "Managed by Terraform" + force_destroy = true + + tags = { + Name = "${var.environment}-hosted-zone" + Environment = var.environment + } } resource "aws_route53_record" "name" { - zone_id = aws_route53_zone.r53_zone.zone_id - name = "bank.${var.domain-name}" # Use a subdomain for CNAME - type = "CNAME" - ttl = 300 - records = [var.nginx_lb_ip] + zone_id = aws_route53_zone.r53_zone.zone_id + name = "bank.${var.domain-name}" # Use a subdomain for CNAME + type = "CNAME" + ttl = 300 + records = [var.nginx_lb_ip] } resource "aws_route53_record" "name1" { - zone_id = aws_route53_zone.r53_zone.zone_id - name = "bankapi.${var.domain-name}" # Use a subdomain for CNAME - type = "CNAME" - ttl = 300 - records = [var.nginx_lb_ip] + zone_id = aws_route53_zone.r53_zone.zone_id + name = "bankapi.${var.domain-name}" # Use a subdomain for CNAME + type = "CNAME" + ttl = 300 + records = [var.nginx_lb_ip] } resource "aws_route53_record" "name2" { - zone_id = aws_route53_zone.r53_zone.zone_id - name = "argocd.${var.domain-name}" # Use a subdomain for CNAME - type = "CNAME" - ttl = 300 - records = [var.nginx_lb_ip] + zone_id = aws_route53_zone.r53_zone.zone_id + name = "argocd.${var.domain-name}" # Use a subdomain for CNAME + type = "CNAME" + ttl = 300 + records = [var.nginx_lb_ip] } \ No newline at end of file diff --git a/bank-infra/modules/module-dns/variables.tf b/bank-infra/modules/module-dns/variables.tf index a82a940..65906ab 100644 --- a/bank-infra/modules/module-dns/variables.tf +++ b/bank-infra/modules/module-dns/variables.tf @@ -2,8 +2,8 @@ variable "environment" {} variable "domain-name" {} variable "nginx_ingress_lb_dns" { description = "DNS name of the NGINX Ingress Load Balancer" - type = string - + type = string + } variable "nginx_lb_ip" { description = "IP address of the NGINX Ingress Load Balancer" diff --git a/bank-infra/modules/module-eks/addons.tf b/bank-infra/modules/module-eks/addons.tf index 02b6c6a..fdd09ea 100644 --- a/bank-infra/modules/module-eks/addons.tf +++ b/bank-infra/modules/module-eks/addons.tf @@ -1,9 +1,9 @@ provider "helm" { - kubernetes { - host = aws_eks_cluster.eks.endpoint - cluster_ca_certificate = base64decode(aws_eks_cluster.eks.certificate_authority[0].data) - token = data.aws_eks_cluster_auth.eks.token - } + kubernetes { + host = aws_eks_cluster.eks.endpoint + cluster_ca_certificate = base64decode(aws_eks_cluster.eks.certificate_authority[0].data) + token = data.aws_eks_cluster_auth.eks.token + } } provider "kubernetes" { @@ -14,18 +14,18 @@ provider "kubernetes" { } data "aws_eks_cluster_auth" "eks" { - name = aws_eks_cluster.eks.name + name = aws_eks_cluster.eks.name } resource "helm_release" "nginx_ingress" { - name = "nginx-ingress" - repository = "https://kubernetes.github.io/ingress-nginx" - chart = "ingress-nginx" - version = "4.12.0" - namespace = "ingress-nginx" - create_namespace = true + name = "nginx-ingress" + repository = "https://kubernetes.github.io/ingress-nginx" + chart = "ingress-nginx" + version = "4.12.0" + namespace = "ingress-nginx" + create_namespace = true - values = [file("${path.module}/nginx-ingress-values.yaml")] - depends_on = [ aws_eks_node_group.eks_node_group ] + values = [file("${path.module}/nginx-ingress-values.yaml")] + depends_on = [aws_eks_node_group.eks_node_group] } data "aws_lb" "nginx_ingress" { @@ -37,27 +37,27 @@ data "aws_lb" "nginx_ingress" { } resource "helm_release" "cert_manager" { - name = "cert-manager" - repository = "https://charts.jetstack.io" - chart = "cert-manager" - version = "1.14.5" - namespace = "cert-manager" - create_namespace = true - set { - name = "installCRDs" - value = "true" - } - depends_on = [ helm_release.nginx_ingress ] + name = "cert-manager" + repository = "https://charts.jetstack.io" + chart = "cert-manager" + version = "1.14.5" + namespace = "cert-manager" + create_namespace = true + set { + name = "installCRDs" + value = "true" + } + depends_on = [helm_release.nginx_ingress] } #================================================== resource "helm_release" "argocd" { - name = "argocd" - repository = "https://argoproj.github.io/argo-helm" - chart = "argo-cd" - version = "5.51.6" - namespace = "argocd" - create_namespace = true - values = [file("${path.module}/argocd-values.yaml")] - depends_on = [ helm_release.nginx_ingress, helm_release.cert_manager] + name = "argocd" + repository = "https://argoproj.github.io/argo-helm" + chart = "argo-cd" + version = "5.51.6" + namespace = "argocd" + create_namespace = true + values = [file("${path.module}/argocd-values.yaml")] + depends_on = [helm_release.nginx_ingress, helm_release.cert_manager] } \ No newline at end of file diff --git a/bank-infra/modules/module-eks/eks-node-group.tf b/bank-infra/modules/module-eks/eks-node-group.tf index b718f45..4dbf618 100644 --- a/bank-infra/modules/module-eks/eks-node-group.tf +++ b/bank-infra/modules/module-eks/eks-node-group.tf @@ -2,19 +2,19 @@ resource "aws_eks_node_group" "eks_node_group" { cluster_name = aws_eks_cluster.eks.id node_group_name = "${var.environment}-eks-node-group" node_role_arn = aws_iam_role.eks_node_group_role.arn - subnet_ids = concat(var.public_subnet_ids, var.private_subnet_ids) + subnet_ids = concat(var.public_subnet_ids, var.private_subnet_ids) version = var.eks_version capacity_type = var.capacity_type - ami_type = var.ami_type + ami_type = var.ami_type scaling_config { desired_size = var.desired_size max_size = var.max_size min_size = var.min_size } - + instance_types = var.instance_types labels = { - role = var.label_one + role = var.label_one environment = var.environment } @@ -30,5 +30,5 @@ resource "aws_eks_node_group" "eks_node_group" { aws_iam_role_policy_attachment.eks_fargate_pod_execution_role_policy, aws_iam_role_policy_attachment.ssm_managed_instance_core_policy ] - + } \ No newline at end of file diff --git a/bank-infra/modules/module-eks/eks-node-groups-role.tf b/bank-infra/modules/module-eks/eks-node-groups-role.tf index 0fc0aa6..05244dd 100644 --- a/bank-infra/modules/module-eks/eks-node-groups-role.tf +++ b/bank-infra/modules/module-eks/eks-node-groups-role.tf @@ -18,7 +18,7 @@ resource "aws_iam_role" "eks_node_group_role" { Name = "${var.environment}-eks-node_group-role" Environment = var.environment } - + } # Attach the AmazonEKSWorkerNodePolicy to the EKS node group role resource "aws_iam_role_policy_attachment" "eks_worker_node_policy" { @@ -33,8 +33,8 @@ resource "aws_iam_role_policy_attachment" "eks_cni_policy" { } # Attach the AmazonEC2ContainerRegistryReadOnly policy to the EKS node group role resource "aws_iam_role_policy_attachment" "ec2_container_registry_policy" { - role = aws_iam_role.eks_node_group_role.name - policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly" + role = aws_iam_role.eks_node_group_role.name + policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly" } # The AmazonEKSNodePolicy does not exist; skipping attachment. # Attach the AmazonEKSFargatePodExecutionRolePolicy to the EKS node group role @@ -44,8 +44,8 @@ resource "aws_iam_role_policy_attachment" "eks_fargate_pod_execution_role_policy } # Attach the AmazonSSMManagedInstanceCore policy to the EKS node group role resource "aws_iam_role_policy_attachment" "ssm_managed_instance_core_policy" { - role = aws_iam_role.eks_node_group_role.name - policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" + role = aws_iam_role.eks_node_group_role.name + policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" } resource "aws_iam_role_policy_attachment" "eks_elb_permissions" { diff --git a/bank-infra/modules/module-eks/eks-role.tf b/bank-infra/modules/module-eks/eks-role.tf index 6c69f75..9dc639c 100644 --- a/bank-infra/modules/module-eks/eks-role.tf +++ b/bank-infra/modules/module-eks/eks-role.tf @@ -15,7 +15,7 @@ resource "aws_iam_role" "eks_cluster_role" { } ] }) - tags = { + tags = { Name = "${var.environment}-eks-cluster-role" Environment = var.environment } diff --git a/bank-infra/modules/module-eks/eks.tf b/bank-infra/modules/module-eks/eks.tf index 357296e..b5f1dca 100644 --- a/bank-infra/modules/module-eks/eks.tf +++ b/bank-infra/modules/module-eks/eks.tf @@ -1,19 +1,19 @@ resource "aws_eks_cluster" "eks" { - name = "${var.environment}-${var.cluster_name}" - role_arn = aws_iam_role.eks_cluster_role.arn - version = var.eks_version - vpc_config { - subnet_ids = concat(var.public_subnet_ids, var.private_subnet_ids) - endpoint_public_access = true - endpoint_private_access = true - } + name = "${var.environment}-${var.cluster_name}" + role_arn = aws_iam_role.eks_cluster_role.arn + version = var.eks_version + vpc_config { + subnet_ids = concat(var.public_subnet_ids, var.private_subnet_ids) + endpoint_public_access = true + endpoint_private_access = true + } - depends_on = [ - aws_iam_role_policy_attachment.eks_cluster_policy, - aws_iam_role_policy_attachment.eks_vpc_resource_controller_policy - ] - tags = { - Name = "${var.environment}-${var.cluster_name}" - Environment = var.environment - } + depends_on = [ + aws_iam_role_policy_attachment.eks_cluster_policy, + aws_iam_role_policy_attachment.eks_vpc_resource_controller_policy + ] + tags = { + Name = "${var.environment}-${var.cluster_name}" + Environment = var.environment + } } \ No newline at end of file diff --git a/bank-infra/modules/module-eks/variables.tf b/bank-infra/modules/module-eks/variables.tf index 9c63260..48b21ad 100644 --- a/bank-infra/modules/module-eks/variables.tf +++ b/bank-infra/modules/module-eks/variables.tf @@ -2,14 +2,14 @@ variable "vpc_cidrblock" { description = "CIDR block for the VPC" type = string default = "192.168.0.0/16" - + } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "staging" - + } variable "create_subnet" { @@ -22,7 +22,7 @@ variable "countsub" { description = "Number of subnets to create" type = number default = 2 - + } variable "create_elastic_ip" { description = "Flag to create Elastic IPs" @@ -45,14 +45,14 @@ variable "max_size" { variable "min_size" { description = "Minimum size of the EKS node group" type = number - default = 2 + default = 2 } variable "instance_types" { description = "Instance types for the EKS node group" type = list(string) - default = ["t2.micro"] -} + default = ["t2.micro"] +} variable "capacity_type" { description = "Capacity type for the EKS node group" @@ -83,14 +83,14 @@ variable "public_subnet_ids" { type = list(string) } variable "private_subnet_ids" { - type = list(string) + type = list(string) description = "List of private subnet IDs" } variable "cluster_name" { } variable "repository_name" { - + } variable "domain-name" {} diff --git a/bank-infra/modules/module-vpc/02-vpc.tf b/bank-infra/modules/module-vpc/02-vpc.tf index 86274d3..f240633 100644 --- a/bank-infra/modules/module-vpc/02-vpc.tf +++ b/bank-infra/modules/module-vpc/02-vpc.tf @@ -1,11 +1,11 @@ resource "aws_vpc" "vpc-main" { - cidr_block = var.vpc_cidrblock - instance_tenancy = "default" - enable_dns_support = true - enable_dns_hostnames = true + cidr_block = var.vpc_cidrblock + instance_tenancy = "default" + enable_dns_support = true + enable_dns_hostnames = true assign_generated_ipv6_cidr_block = false tags = { - Name = "${var.environment}-vpc" + Name = "${var.environment}-vpc" Environment = var.environment } } \ No newline at end of file diff --git a/bank-infra/modules/module-vpc/03-igt.tf b/bank-infra/modules/module-vpc/03-igt.tf index 4c825a3..d774f5b 100644 --- a/bank-infra/modules/module-vpc/03-igt.tf +++ b/bank-infra/modules/module-vpc/03-igt.tf @@ -2,7 +2,7 @@ resource "aws_internet_gateway" "gw" { vpc_id = aws_vpc.vpc-main.id tags = { - Name = "${var.environment}-internet-gateway" + Name = "${var.environment}-internet-gateway" Environment = var.environment } } \ No newline at end of file diff --git a/bank-infra/modules/module-vpc/04-public_subnet.tf b/bank-infra/modules/module-vpc/04-public_subnet.tf index 10ed48f..bc23b28 100644 --- a/bank-infra/modules/module-vpc/04-public_subnet.tf +++ b/bank-infra/modules/module-vpc/04-public_subnet.tf @@ -9,18 +9,18 @@ data "aws_availability_zones" "available" { # Public Subnet Configuration #============================ resource "aws_subnet" "public_subnet" { - count = var.create_subnet ? var.countsub : 0 - vpc_id = aws_vpc.vpc-main.id - availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = "192.168.${count.index}.0/24" - map_public_ip_on_launch = true + count = var.create_subnet ? var.countsub : 0 + vpc_id = aws_vpc.vpc-main.id + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = "192.168.${count.index}.0/24" + map_public_ip_on_launch = true - tags = { - Name = "${var.environment}-public-subnet-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" - Environment = var.environment - "kubernetes.io/cluster/eks" = "1" - "kubernetes.io/role/elb" = "1" - "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" - } + tags = { + Name = "${var.environment}-public-subnet-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" + Environment = var.environment + "kubernetes.io/cluster/eks" = "1" + "kubernetes.io/role/elb" = "1" + "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" + } } diff --git a/bank-infra/modules/module-vpc/05-private_subnets.tf b/bank-infra/modules/module-vpc/05-private_subnets.tf index 9a732fb..b2ccace 100644 --- a/bank-infra/modules/module-vpc/05-private_subnets.tf +++ b/bank-infra/modules/module-vpc/05-private_subnets.tf @@ -1,17 +1,17 @@ # private Subnet Configuration #============================ resource "aws_subnet" "private_subnet" { - count = var.create_subnet ? var.countsub : 0 - vpc_id = aws_vpc.vpc-main.id - availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = "192.168.${count.index + 3}.0/24" - #map_public_ip_on_launch = true + count = var.create_subnet ? var.countsub : 0 + vpc_id = aws_vpc.vpc-main.id + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = "192.168.${count.index + 3}.0/24" + #map_public_ip_on_launch = true - tags = { - Name = "${var.environment}-private-subnet-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" - Environment = var.environment - "kubernetes.io/cluster/eks" = "shared" - "kubernetes.io/role/internal-elb" = "1" - "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" - } + tags = { + Name = "${var.environment}-private-subnet-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" + Environment = var.environment + "kubernetes.io/cluster/eks" = "shared" + "kubernetes.io/role/internal-elb" = "1" + "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" + } } diff --git a/bank-infra/modules/module-vpc/06-elp.tf b/bank-infra/modules/module-vpc/06-elp.tf index c1f2d5c..41c30fc 100644 --- a/bank-infra/modules/module-vpc/06-elp.tf +++ b/bank-infra/modules/module-vpc/06-elp.tf @@ -1,9 +1,9 @@ resource "aws_eip" "elastic-ip" { - count = var.create_elastic_ip ? var.countsub : 0 - tags = { - Name = "${var.environment}-elastic-ip-nat-gateway-${count.index + 1}" - Environment = var.environment - } + count = var.create_elastic_ip ? var.countsub : 0 + tags = { + Name = "${var.environment}-elastic-ip-nat-gateway-${count.index + 1}" + Environment = var.environment + } - depends_on = [ aws_internet_gateway.gw ] + depends_on = [aws_internet_gateway.gw] } \ No newline at end of file diff --git a/bank-infra/modules/module-vpc/07-nat-gateway.tf b/bank-infra/modules/module-vpc/07-nat-gateway.tf index 72240d9..9cde6bc 100644 --- a/bank-infra/modules/module-vpc/07-nat-gateway.tf +++ b/bank-infra/modules/module-vpc/07-nat-gateway.tf @@ -1,9 +1,9 @@ resource "aws_nat_gateway" "name" { - count = var.create_elastic_ip ? var.countsub : 0 - allocation_id = aws_eip.elastic-ip[count.index].id - subnet_id = aws_subnet.public_subnet[count.index].id - tags = { - Name = "${var.environment}-nat-gateway-${count.index + 1}" - Environment = var.environment - } + count = var.create_elastic_ip ? var.countsub : 0 + allocation_id = aws_eip.elastic-ip[count.index].id + subnet_id = aws_subnet.public_subnet[count.index].id + tags = { + Name = "${var.environment}-nat-gateway-${count.index + 1}" + Environment = var.environment + } } \ No newline at end of file diff --git a/bank-infra/modules/module-vpc/08-private-route-table.tf b/bank-infra/modules/module-vpc/08-private-route-table.tf index 6e9347c..bd1466c 100644 --- a/bank-infra/modules/module-vpc/08-private-route-table.tf +++ b/bank-infra/modules/module-vpc/08-private-route-table.tf @@ -1,16 +1,16 @@ resource "aws_route_table" "private_route_table" { - count = true ? var.countsub : 0 + count = true ? var.countsub : 0 vpc_id = aws_vpc.vpc-main.id tags = { - Name = "${var.environment}-private-route-table-${count.index + 1}" + Name = "${var.environment}-private-route-table-${count.index + 1}" Environment = var.environment } } resource "aws_route" "private_route" { - count = true ? var.countsub : 0 - route_table_id = aws_route_table.private_route_table[count.index].id + count = true ? var.countsub : 0 + route_table_id = aws_route_table.private_route_table[count.index].id destination_cidr_block = "0.0.0.0/0" - nat_gateway_id = aws_nat_gateway.name[count.index].id + nat_gateway_id = aws_nat_gateway.name[count.index].id } \ No newline at end of file diff --git a/bank-infra/modules/module-vpc/09-public-route-table.tf b/bank-infra/modules/module-vpc/09-public-route-table.tf index 68eef41..32891ae 100644 --- a/bank-infra/modules/module-vpc/09-public-route-table.tf +++ b/bank-infra/modules/module-vpc/09-public-route-table.tf @@ -19,7 +19,7 @@ resource "aws_main_route_table_association" "main" { } # add a route to the default route table to allow internet access resource "aws_route" "default-route-table" { - route_table_id = data.aws_route_table.default-route-table.id - destination_cidr_block = "0.0.0.0/0" - gateway_id = aws_internet_gateway.gw.id + route_table_id = data.aws_route_table.default-route-table.id + destination_cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.gw.id } \ No newline at end of file diff --git a/bank-infra/modules/module-vpc/10-public-route-associate.tf b/bank-infra/modules/module-vpc/10-public-route-associate.tf index 92c1027..5540d7a 100644 --- a/bank-infra/modules/module-vpc/10-public-route-associate.tf +++ b/bank-infra/modules/module-vpc/10-public-route-associate.tf @@ -1,8 +1,8 @@ resource "aws_route_table_association" "public_route_table_association" { - count = true ? var.countsub : 0 + count = true ? var.countsub : 0 subnet_id = aws_subnet.public_subnet[count.index].id route_table_id = data.aws_route_table.default-route-table.id depends_on = [aws_internet_gateway.gw] - + } \ No newline at end of file diff --git a/bank-infra/modules/module-vpc/11-private-route-associate.tf b/bank-infra/modules/module-vpc/11-private-route-associate.tf index ed93a7b..b4a8d77 100644 --- a/bank-infra/modules/module-vpc/11-private-route-associate.tf +++ b/bank-infra/modules/module-vpc/11-private-route-associate.tf @@ -1,17 +1,17 @@ resource "aws_route_table_association" "private_route_association" { - count = true ? var.countsub : 0 + count = true ? var.countsub : 0 subnet_id = aws_subnet.private_subnet[count.index].id route_table_id = aws_route_table.private_route_table[count.index].id - depends_on = [aws_nat_gateway.name] - + depends_on = [aws_nat_gateway.name] + } resource "aws_route_table_association" "private_route_association_db" { - count = true ? var.countsub : 0 + count = true ? var.countsub : 0 subnet_id = aws_subnet.private_subnet_db[count.index].id route_table_id = aws_route_table.private_route_table[count.index].id - depends_on = [aws_nat_gateway.name] - + depends_on = [aws_nat_gateway.name] + } \ No newline at end of file diff --git a/bank-infra/modules/module-vpc/12-private-subnet-db.tf b/bank-infra/modules/module-vpc/12-private-subnet-db.tf index 4bf0c35..7187304 100644 --- a/bank-infra/modules/module-vpc/12-private-subnet-db.tf +++ b/bank-infra/modules/module-vpc/12-private-subnet-db.tf @@ -1,17 +1,17 @@ # private Subnet Configuration #============================ resource "aws_subnet" "private_subnet_db" { - count = var.create_subnet ? var.countsub : 0 - vpc_id = aws_vpc.vpc-main.id - availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = "192.168.${count.index + 5}.0/24" - #map_public_ip_on_launch = true + count = var.create_subnet ? var.countsub : 0 + vpc_id = aws_vpc.vpc-main.id + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = "192.168.${count.index + 5}.0/24" + #map_public_ip_on_launch = true - tags = { - Name = "${var.environment}-private-subnet-db-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" - Environment = var.environment - "kubernetes.io/cluster/eks" = "shared" - "kubernetes.io/role/internal-elb" = "1" - "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" - } + tags = { + Name = "${var.environment}-private-subnet-db-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" + Environment = var.environment + "kubernetes.io/cluster/eks" = "shared" + "kubernetes.io/role/internal-elb" = "1" + "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" + } } diff --git a/bank-infra/modules/module-vpc/13-mysql-sg.tf b/bank-infra/modules/module-vpc/13-mysql-sg.tf index 4d8a9f0..7e1e4ec 100644 --- a/bank-infra/modules/module-vpc/13-mysql-sg.tf +++ b/bank-infra/modules/module-vpc/13-mysql-sg.tf @@ -15,7 +15,7 @@ resource "aws_security_group" "mysql_sg" { to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] - -} + + } } \ No newline at end of file diff --git a/bank-infra/modules/module-vpc/output.tf b/bank-infra/modules/module-vpc/output.tf index 0dc0b1d..1725e5d 100644 --- a/bank-infra/modules/module-vpc/output.tf +++ b/bank-infra/modules/module-vpc/output.tf @@ -1,8 +1,8 @@ output "vpc_id" { description = "The ID of the VPC" value = aws_vpc.vpc-main.id - sensitive = true - + sensitive = true + } output "private_subnet_ids" { @@ -23,5 +23,5 @@ output "private_subnet_db_ids" { output "aws_security_group_ids" { description = "List of security group IDs" value = aws_security_group.mysql_sg.id - + } \ No newline at end of file diff --git a/bank-infra/modules/module-vpc/variables.tf b/bank-infra/modules/module-vpc/variables.tf index d52e293..2e6c284 100644 --- a/bank-infra/modules/module-vpc/variables.tf +++ b/bank-infra/modules/module-vpc/variables.tf @@ -2,14 +2,14 @@ variable "vpc_cidrblock" { description = "CIDR block for the VPC" type = string default = "192.168.0.0/16" - + } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "staging" - + } variable "create_subnet" { @@ -22,7 +22,7 @@ variable "countsub" { description = "Number of subnets to create" type = number default = 2 - + } variable "create_elastic_ip" { description = "Flag to create Elastic IPs" diff --git a/bank-infra/prod/01-provider.tf b/bank-infra/prod/01-provider.tf index e987edf..db65d0a 100644 --- a/bank-infra/prod/01-provider.tf +++ b/bank-infra/prod/01-provider.tf @@ -6,21 +6,21 @@ terraform { required_providers { namecheap = { - source = "namecheap/namecheap" + source = "namecheap/namecheap" version = "2.2.0" } aws = { - source = "hashicorp/aws" + source = "hashicorp/aws" version = "6.0.0-beta2" } } } provider "namecheap" { - user_name = var.namecheap_username - api_user = var.namecheap_api_user - api_key = var.namecheap_api_key - client_ip = var.namecheap_client_ip + user_name = var.namecheap_username + api_user = var.namecheap_api_user + api_key = var.namecheap_api_key + client_ip = var.namecheap_client_ip use_sandbox = false } provider "aws" { diff --git a/bank-infra/prod/main.tf b/bank-infra/prod/main.tf index ecebd57..8fdb6b1 100644 --- a/bank-infra/prod/main.tf +++ b/bank-infra/prod/main.tf @@ -1,57 +1,57 @@ # Creating a VPC and EKS cluster using Terraform module "vpc-deployment" { - source = "./module-vpc" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - + source = "./module-vpc" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + } #creating an EKS cluster using Terraform # and deploying it in the VPC created above module "eks-deployment" { - source = "./module-eks" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - desired_size = var.desired_size - max_size = var.max_size - min_size = var.min_size - instance_types = var.instance_types - capacity_type = var.capacity_type - public_subnet_ids = module.vpc-deployment.public_subnet_ids - private_subnet_ids = module.vpc-deployment.private_subnet_ids - cluster_name = var.cluster_name - repository_name = var.repository_name - domain-name = var.domain-name - email = var.email - + source = "./module-eks" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + desired_size = var.desired_size + max_size = var.max_size + min_size = var.min_size + instance_types = var.instance_types + capacity_type = var.capacity_type + public_subnet_ids = module.vpc-deployment.public_subnet_ids + private_subnet_ids = module.vpc-deployment.private_subnet_ids + cluster_name = var.cluster_name + repository_name = var.repository_name + domain-name = var.domain-name + email = var.email + } module "namecheap-deployment" { - source = "./module-dns" - environment = var.environment - domain-name = var.domain-name - nginx_lb_ip = module.eks-deployment.nginx_lb_ip - nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname - nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns - + source = "./module-dns" + environment = var.environment + domain-name = var.domain-name + nginx_lb_ip = module.eks-deployment.nginx_lb_ip + nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname + nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns + } module "rds-mysql-deployment" { - source = "./module-database" - environment = var.environment - db_instance_class = var.db_instance_class - db_allocated_storage = var.db_allocated_storage - private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids - db_name = var.db_name - db_password = var.db_password - db_username = var.db_username - aws_security_group_ids = module.vpc-deployment.aws_security_group_ids + source = "./module-database" + environment = var.environment + db_instance_class = var.db_instance_class + db_allocated_storage = var.db_allocated_storage + private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids + db_name = var.db_name + db_password = var.db_password + db_username = var.db_username + aws_security_group_ids = module.vpc-deployment.aws_security_group_ids } \ No newline at end of file diff --git a/bank-infra/prod/terraform.tfvars b/bank-infra/prod/terraform.tfvars index 42fc12e..4a84a00 100644 --- a/bank-infra/prod/terraform.tfvars +++ b/bank-infra/prod/terraform.tfvars @@ -1,17 +1,17 @@ -environment = "production" -vpc_cidrblock = "192.168.0.0/16" -countsub = 2 -create_subnet = true +environment = "production" +vpc_cidrblock = "192.168.0.0/16" +countsub = 2 +create_subnet = true create_elastic_ip = true -desired_size = 2 -max_size = 6 -min_size = 2 -instance_types = ["t2.medium"] -capacity_type = "ON_DEMAND" -ami_type = "AL2_x86_64" -label_one = "system-nodepool" -eks_version = "1.32" -domain-name = "cloudwitches.online" -cluster_name = "eks-cluster" -repository_name = "eks-repository" -email = "support@digitalwitchng.online" +desired_size = 2 +max_size = 6 +min_size = 2 +instance_types = ["t2.medium"] +capacity_type = "ON_DEMAND" +ami_type = "AL2_x86_64" +label_one = "system-nodepool" +eks_version = "1.32" +domain-name = "cloudwitches.online" +cluster_name = "eks-cluster" +repository_name = "eks-repository" +email = "support@digitalwitchng.online" diff --git a/bank-infra/prod/variable.tf b/bank-infra/prod/variable.tf index f283b35..82bf36f 100644 --- a/bank-infra/prod/variable.tf +++ b/bank-infra/prod/variable.tf @@ -2,14 +2,14 @@ variable "vpc_cidrblock" { description = "CIDR block for the VPC" type = string default = "192.168.0.0/16" - + } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "staging" - + } variable "create_subnet" { @@ -22,7 +22,7 @@ variable "countsub" { description = "Number of subnets to create" type = number default = 2 - + } variable "create_elastic_ip" { description = "Flag to create Elastic IPs" @@ -46,14 +46,14 @@ variable "max_size" { variable "min_size" { description = "Minimum size of the EKS node group" type = number - default = 2 + default = 2 } variable "instance_types" { description = "Instance types for the EKS node group" type = list(string) - default = ["t2.micro"] -} + default = ["t2.micro"] +} variable "capacity_type" { description = "Capacity type for the EKS node group" @@ -115,7 +115,7 @@ variable "namecheap_client_ip" { variable "db_instance_class" { description = "Instance class for the RDS database" type = string - default = "db.t3.micro" + default = "db.t3.micro" } variable "db_allocated_storage" { @@ -158,7 +158,7 @@ variable "repository_name" { description = "Name of the ECR repository" type = string default = "eks-repository" - + } variable "email" { diff --git a/bank-infra/staging/01-provider.tf b/bank-infra/staging/01-provider.tf index e987edf..db65d0a 100644 --- a/bank-infra/staging/01-provider.tf +++ b/bank-infra/staging/01-provider.tf @@ -6,21 +6,21 @@ terraform { required_providers { namecheap = { - source = "namecheap/namecheap" + source = "namecheap/namecheap" version = "2.2.0" } aws = { - source = "hashicorp/aws" + source = "hashicorp/aws" version = "6.0.0-beta2" } } } provider "namecheap" { - user_name = var.namecheap_username - api_user = var.namecheap_api_user - api_key = var.namecheap_api_key - client_ip = var.namecheap_client_ip + user_name = var.namecheap_username + api_user = var.namecheap_api_user + api_key = var.namecheap_api_key + client_ip = var.namecheap_client_ip use_sandbox = false } provider "aws" { diff --git a/bank-infra/staging/main.tf b/bank-infra/staging/main.tf index ecebd57..8fdb6b1 100644 --- a/bank-infra/staging/main.tf +++ b/bank-infra/staging/main.tf @@ -1,57 +1,57 @@ # Creating a VPC and EKS cluster using Terraform module "vpc-deployment" { - source = "./module-vpc" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - + source = "./module-vpc" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + } #creating an EKS cluster using Terraform # and deploying it in the VPC created above module "eks-deployment" { - source = "./module-eks" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - desired_size = var.desired_size - max_size = var.max_size - min_size = var.min_size - instance_types = var.instance_types - capacity_type = var.capacity_type - public_subnet_ids = module.vpc-deployment.public_subnet_ids - private_subnet_ids = module.vpc-deployment.private_subnet_ids - cluster_name = var.cluster_name - repository_name = var.repository_name - domain-name = var.domain-name - email = var.email - + source = "./module-eks" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + desired_size = var.desired_size + max_size = var.max_size + min_size = var.min_size + instance_types = var.instance_types + capacity_type = var.capacity_type + public_subnet_ids = module.vpc-deployment.public_subnet_ids + private_subnet_ids = module.vpc-deployment.private_subnet_ids + cluster_name = var.cluster_name + repository_name = var.repository_name + domain-name = var.domain-name + email = var.email + } module "namecheap-deployment" { - source = "./module-dns" - environment = var.environment - domain-name = var.domain-name - nginx_lb_ip = module.eks-deployment.nginx_lb_ip - nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname - nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns - + source = "./module-dns" + environment = var.environment + domain-name = var.domain-name + nginx_lb_ip = module.eks-deployment.nginx_lb_ip + nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname + nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns + } module "rds-mysql-deployment" { - source = "./module-database" - environment = var.environment - db_instance_class = var.db_instance_class - db_allocated_storage = var.db_allocated_storage - private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids - db_name = var.db_name - db_password = var.db_password - db_username = var.db_username - aws_security_group_ids = module.vpc-deployment.aws_security_group_ids + source = "./module-database" + environment = var.environment + db_instance_class = var.db_instance_class + db_allocated_storage = var.db_allocated_storage + private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids + db_name = var.db_name + db_password = var.db_password + db_username = var.db_username + aws_security_group_ids = module.vpc-deployment.aws_security_group_ids } \ No newline at end of file diff --git a/bank-infra/staging/terraform.tfvars b/bank-infra/staging/terraform.tfvars index 42fc12e..4a84a00 100644 --- a/bank-infra/staging/terraform.tfvars +++ b/bank-infra/staging/terraform.tfvars @@ -1,17 +1,17 @@ -environment = "production" -vpc_cidrblock = "192.168.0.0/16" -countsub = 2 -create_subnet = true +environment = "production" +vpc_cidrblock = "192.168.0.0/16" +countsub = 2 +create_subnet = true create_elastic_ip = true -desired_size = 2 -max_size = 6 -min_size = 2 -instance_types = ["t2.medium"] -capacity_type = "ON_DEMAND" -ami_type = "AL2_x86_64" -label_one = "system-nodepool" -eks_version = "1.32" -domain-name = "cloudwitches.online" -cluster_name = "eks-cluster" -repository_name = "eks-repository" -email = "support@digitalwitchng.online" +desired_size = 2 +max_size = 6 +min_size = 2 +instance_types = ["t2.medium"] +capacity_type = "ON_DEMAND" +ami_type = "AL2_x86_64" +label_one = "system-nodepool" +eks_version = "1.32" +domain-name = "cloudwitches.online" +cluster_name = "eks-cluster" +repository_name = "eks-repository" +email = "support@digitalwitchng.online" diff --git a/bank-infra/staging/variable.tf b/bank-infra/staging/variable.tf index f283b35..82bf36f 100644 --- a/bank-infra/staging/variable.tf +++ b/bank-infra/staging/variable.tf @@ -2,14 +2,14 @@ variable "vpc_cidrblock" { description = "CIDR block for the VPC" type = string default = "192.168.0.0/16" - + } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "staging" - + } variable "create_subnet" { @@ -22,7 +22,7 @@ variable "countsub" { description = "Number of subnets to create" type = number default = 2 - + } variable "create_elastic_ip" { description = "Flag to create Elastic IPs" @@ -46,14 +46,14 @@ variable "max_size" { variable "min_size" { description = "Minimum size of the EKS node group" type = number - default = 2 + default = 2 } variable "instance_types" { description = "Instance types for the EKS node group" type = list(string) - default = ["t2.micro"] -} + default = ["t2.micro"] +} variable "capacity_type" { description = "Capacity type for the EKS node group" @@ -115,7 +115,7 @@ variable "namecheap_client_ip" { variable "db_instance_class" { description = "Instance class for the RDS database" type = string - default = "db.t3.micro" + default = "db.t3.micro" } variable "db_allocated_storage" { @@ -158,7 +158,7 @@ variable "repository_name" { description = "Name of the ECR repository" type = string default = "eks-repository" - + } variable "email" { diff --git a/bootstrap/s3.tf b/bootstrap/s3.tf index ddea672..e4ab0e9 100644 --- a/bootstrap/s3.tf +++ b/bootstrap/s3.tf @@ -5,7 +5,7 @@ resource "aws_s3_bucket" "tf_state" { bucket = var.bucket_name tags = { - Name = "Terraform State Bucket" + Name = "Terraform State Bucket" Environment = "bootstrap" } } diff --git a/bootstrap/terraform.tfvars b/bootstrap/terraform.tfvars index 63d6995..8ce7206 100644 --- a/bootstrap/terraform.tfvars +++ b/bootstrap/terraform.tfvars @@ -1,3 +1,3 @@ bucket_name = "pod4bankapp-tfstate-bucket" dynamodb_table_name = "pod4bankapp-tf-locks" -aws_region = "us-east-1" +aws_region = "us-east-1" diff --git a/dev/01-provider.tf b/dev/01-provider.tf index e987edf..db65d0a 100644 --- a/dev/01-provider.tf +++ b/dev/01-provider.tf @@ -6,21 +6,21 @@ terraform { required_providers { namecheap = { - source = "namecheap/namecheap" + source = "namecheap/namecheap" version = "2.2.0" } aws = { - source = "hashicorp/aws" + source = "hashicorp/aws" version = "6.0.0-beta2" } } } provider "namecheap" { - user_name = var.namecheap_username - api_user = var.namecheap_api_user - api_key = var.namecheap_api_key - client_ip = var.namecheap_client_ip + user_name = var.namecheap_username + api_user = var.namecheap_api_user + api_key = var.namecheap_api_key + client_ip = var.namecheap_client_ip use_sandbox = false } provider "aws" { diff --git a/dev/main.tf b/dev/main.tf index ecebd57..8fdb6b1 100644 --- a/dev/main.tf +++ b/dev/main.tf @@ -1,57 +1,57 @@ # Creating a VPC and EKS cluster using Terraform module "vpc-deployment" { - source = "./module-vpc" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - + source = "./module-vpc" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + } #creating an EKS cluster using Terraform # and deploying it in the VPC created above module "eks-deployment" { - source = "./module-eks" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - desired_size = var.desired_size - max_size = var.max_size - min_size = var.min_size - instance_types = var.instance_types - capacity_type = var.capacity_type - public_subnet_ids = module.vpc-deployment.public_subnet_ids - private_subnet_ids = module.vpc-deployment.private_subnet_ids - cluster_name = var.cluster_name - repository_name = var.repository_name - domain-name = var.domain-name - email = var.email - + source = "./module-eks" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + desired_size = var.desired_size + max_size = var.max_size + min_size = var.min_size + instance_types = var.instance_types + capacity_type = var.capacity_type + public_subnet_ids = module.vpc-deployment.public_subnet_ids + private_subnet_ids = module.vpc-deployment.private_subnet_ids + cluster_name = var.cluster_name + repository_name = var.repository_name + domain-name = var.domain-name + email = var.email + } module "namecheap-deployment" { - source = "./module-dns" - environment = var.environment - domain-name = var.domain-name - nginx_lb_ip = module.eks-deployment.nginx_lb_ip - nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname - nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns - + source = "./module-dns" + environment = var.environment + domain-name = var.domain-name + nginx_lb_ip = module.eks-deployment.nginx_lb_ip + nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname + nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns + } module "rds-mysql-deployment" { - source = "./module-database" - environment = var.environment - db_instance_class = var.db_instance_class - db_allocated_storage = var.db_allocated_storage - private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids - db_name = var.db_name - db_password = var.db_password - db_username = var.db_username - aws_security_group_ids = module.vpc-deployment.aws_security_group_ids + source = "./module-database" + environment = var.environment + db_instance_class = var.db_instance_class + db_allocated_storage = var.db_allocated_storage + private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids + db_name = var.db_name + db_password = var.db_password + db_username = var.db_username + aws_security_group_ids = module.vpc-deployment.aws_security_group_ids } \ No newline at end of file diff --git a/dev/terraform.tfvars b/dev/terraform.tfvars index 42fc12e..4a84a00 100644 --- a/dev/terraform.tfvars +++ b/dev/terraform.tfvars @@ -1,17 +1,17 @@ -environment = "production" -vpc_cidrblock = "192.168.0.0/16" -countsub = 2 -create_subnet = true +environment = "production" +vpc_cidrblock = "192.168.0.0/16" +countsub = 2 +create_subnet = true create_elastic_ip = true -desired_size = 2 -max_size = 6 -min_size = 2 -instance_types = ["t2.medium"] -capacity_type = "ON_DEMAND" -ami_type = "AL2_x86_64" -label_one = "system-nodepool" -eks_version = "1.32" -domain-name = "cloudwitches.online" -cluster_name = "eks-cluster" -repository_name = "eks-repository" -email = "support@digitalwitchng.online" +desired_size = 2 +max_size = 6 +min_size = 2 +instance_types = ["t2.medium"] +capacity_type = "ON_DEMAND" +ami_type = "AL2_x86_64" +label_one = "system-nodepool" +eks_version = "1.32" +domain-name = "cloudwitches.online" +cluster_name = "eks-cluster" +repository_name = "eks-repository" +email = "support@digitalwitchng.online" diff --git a/dev/variable.tf b/dev/variable.tf index f283b35..82bf36f 100644 --- a/dev/variable.tf +++ b/dev/variable.tf @@ -2,14 +2,14 @@ variable "vpc_cidrblock" { description = "CIDR block for the VPC" type = string default = "192.168.0.0/16" - + } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "staging" - + } variable "create_subnet" { @@ -22,7 +22,7 @@ variable "countsub" { description = "Number of subnets to create" type = number default = 2 - + } variable "create_elastic_ip" { description = "Flag to create Elastic IPs" @@ -46,14 +46,14 @@ variable "max_size" { variable "min_size" { description = "Minimum size of the EKS node group" type = number - default = 2 + default = 2 } variable "instance_types" { description = "Instance types for the EKS node group" type = list(string) - default = ["t2.micro"] -} + default = ["t2.micro"] +} variable "capacity_type" { description = "Capacity type for the EKS node group" @@ -115,7 +115,7 @@ variable "namecheap_client_ip" { variable "db_instance_class" { description = "Instance class for the RDS database" type = string - default = "db.t3.micro" + default = "db.t3.micro" } variable "db_allocated_storage" { @@ -158,7 +158,7 @@ variable "repository_name" { description = "Name of the ECR repository" type = string default = "eks-repository" - + } variable "email" { diff --git a/ecrplan b/ecrplan new file mode 100644 index 0000000000000000000000000000000000000000..25410838ffcbb0500a06194c62fe0e65410f1b18 GIT binary patch literal 4449 zcmbtXc{CJi8y{OT#+pKrorqz`zOPwpns8;S!HA3*F(|SdduUOTCAqdVRD_Z(%e9Ps zDP@wVtTT2Yd^7icWjW=3=X}38Gv~a2yubN9&-*;@^LwEtG_)Lm{p62qNR$m=8}(HsbUc=t&@f2 z{&GY2ug!jMVJ|UEFvPk2^e9Rn-Zx?dgVKEy{~NO+EPnKCbgoIHT0b6 zAQPGIzX0M+#PP^^0`24eUxpJxOP88Mv1k&mYH_Z`_N+~s`AhU zv6!q$f@KstKeBArx|~N^I+D;pe2x+>YSkYAS}KHHrU^^($(3J6x)ZGNk0oHp_!kVf z3mIr6f*MLTM3?0WAkq4;=PN^-VG~2Q9}T6uUR&CPtxrZzJS~pMI5Kc|13PsQANJg) z8n57-r@B0X9Elt_?*>1o#2!r>8F<8Lf=?^u9hC$Gp%=&!6$8Q+i?51tf*_rPoHTLa zmM&KFokOv}d;FU1IBQ9_Ff|rs(S3~`Al{bHx6V4DQNS$N!pTc6{KXRNF6OA`@E{MO zLljJ{Div&sGaX}SiEm2OrV8W7Oj>_B(NO#mefh>YY~V%N+S9%rBgBlfrl2D>oUYlO zwiAC1Un%$cSjB%dXY6Fa7u(Tx6lmT4YEJaiB7ysNN(z`VC3#k-X(Pqjt?iQw2mdt7 z5-y+>k93s|V;W9OGnlJrJoSt?+TN(5&R0Axnb6W&2PtFA#55(9v*fWb_c?uSS=X9l z=}2WhzQUgkoK4uE=HKKMQK=q1A8B523AL z71s`XOAN<-J~Ex1)IWKgK&02~o78+W8AJ;JY;HnL==bwHjCdVN0|2Db0|3z9wlDqP z?dyesV-P?4S1+!WIaG#KfBBleoSO;PQH^g09Sv1^Z(HTxgDHjwDfVJpy@<_rjM*RS z*mGrci{90>GsY%En%urg2aA*<=#--*Z_Rcd$B*USYfD>x)R5z47SPo@P)wYPN+EQO zwZw(@tDMYTU1sZ^J7p4XkFz=S8X_$4p>OfdLG|SHFb`9WyIyluZ)4EpYv!L=3igRP z#FJOg$=~0{0@{j2%EJ@kvlUQG8}PLZD3}xwlUN+bd3;<-mBB8oyme@_Y{3#muPpmD{8x5svmS@762XPhm7AJ+U^|qz&%~z4oHO8|G{}^ zmqZ7+qZ+xp?#ulF^)M+qxkn{6T znZMY_)JCb8`8_knzcV@qILb{9a-Li}(r9mthc{+N=JZe#PtFF`sD3w+QVwP< zdL}9RNedso0@Yh0KC?+C9<0vg_TMKuVrQpg_Ezi~!<9aH?pBwNg%LQ7l{m1#k%{+= zLyy0AbnviTwv8YiYV{sl;TLfic|a~5=^x7F)kDCJWYzwADi{2%@?W01go$K}scDOm z1ysUVswttv1aBr~3CsHegC5J5G_-hP(PSpsc?>Mxf;V|H`snj#>YsPtWmz^`1+o;G zJ>~HJR?hC4wvB&!sa}Rv&tH23-bw$B#a1{GJbu$};DFoJ+B061I#SvFG?L{p*I~cRKjyTEoMr4SYN>LHQ0V8oh^;e$38_# z>yLPyBq1Db&WsaBZ}4qsv$~@w15L6wWk|i5V$(zz+m%PwhzAc8FSxR=vm^+0te+GlXx_0<KY=rDs4eth3_elaSSPMytc@x2Pr~om25wv(o^n>O@3#S$j82(!}Y?fvQ2$SKLzM z;L`k3-dd0Ta&Da2d2mO9-+&$8QF}#yLi}B|w377G3GX*b&d2*kD!$KH9M|V7ja&D0 z4*V1$6H@=qyyp5kM9I;b9S~_ig_v>`s5~;4#{r&9G51W&p9oOEg zrlYIl)_XKJt|nw`EX>ZoudZ5mR0~vJx8Inl?wB6Q+W73b;=ktcosdwvIaG}nDbQsz z^h58@cb2s~V}7w#E9F)`o+<=%1;gzXYy$eib4_vkT?D$;IZM zBx(C9#T(Dud5`vR4>IgiM9Qu5-X=iJ#j{<7?4{k8K~^=y)I8)dC}Spr$_+@iIcZ;+ zIacDK(oN?J3+Gg*2~Y_d5dqFv-zbH0hq&xI^9XMzR2J$OOvf<6GGO@67lO|BS#g$6 zO!Mjjew3IX7qcm= zSaG)EZ7z&dW3vgu)xaZhro^%VpyIy7Q_FMsK^D?aZuF4*o%TT0q}rAnb^`>ApM8R) z$E8$kZ@|QBBu@L1d~{>BjCw)H;lx4cu%uHZldPOXy!_>Hb1aC6g6Il?#$J}(JD4=( zevDm^jZk&LiOEURti=ajx3#!v}r z(V==cnc|eMd#sGL4^AGzP!lR@4#3v?ZM!w3yx(?W*K2O~ z=IvgL;vTn9P5wKK^G+|hd-rx@MDc4|h$Y|N|J}XQz3ryhZc`}kVGC;HSTWB3;-_}g zQMUiEDU>T{3$wfEc29-9n05-&+P72KFUQ?(y6tX&;%K&Tdl%g={LOB%?E{)(AhzI1 zejjX0+TM0zH|_R8OPTIlklg<}+W#r|?K6!sr?*h?TjGB^pY3CaG7YzoPhM>0;8(M8 jci`LGYiHFM0|9%EF{lY0`S<_;5czYR+%Z*5l+}L#;*5{s literal 0 HcmV?d00001 diff --git a/eks/cluster.tf b/eks/cluster.tf new file mode 100644 index 0000000..a11f76a --- /dev/null +++ b/eks/cluster.tf @@ -0,0 +1,8 @@ +resource "aws_eks_cluster" "main" { + name = var.cluster_name + role_arn = var.cluster_role_arn + + vpc_config { + subnet_ids = var.subnet_ids + } +} diff --git a/eks/eks.tf b/eks/eks.tf new file mode 100644 index 0000000..ef2ba72 --- /dev/null +++ b/eks/eks.tf @@ -0,0 +1,31 @@ +resource "aws_eks_cluster" "this" { + name = var.cluster_name + role_arn = aws_iam_role.eks_cluster_role.arn + version = "1.28" + + vpc_config { + subnet_ids = concat(aws_subnet.public[*].id, aws_subnet.private[*].id) + } +} + +resource "aws_eks_node_group" "managed_nodes" { + cluster_name = aws_eks_cluster.this.name + node_group_name = var.node_group_name + node_role_arn = aws_iam_role.eks_node_role.arn + subnet_ids = aws_subnet.private[*].id + + scaling_config { + desired_size = var.node_desired_capacity + max_size = var.node_max_capacity + min_size = var.node_min_capacity + } + + instance_types = var.node_instance_types + + depends_on = [ + aws_iam_role_policy_attachment.node_worker_policy, + aws_iam_role_policy_attachment.node_cni_policy, + aws_iam_role_policy_attachment.node_ecr_readonly + ] +} + diff --git a/eks/iam.tf b/eks/iam.tf new file mode 100644 index 0000000..0a384d3 --- /dev/null +++ b/eks/iam.tf @@ -0,0 +1,51 @@ +data "aws_iam_policy_document" "eks_cluster_assume" { + statement { + effect = "Allow" + principals { + type = "Service" + identifiers = ["eks.amazonaws.com"] + } + actions = ["sts:AssumeRole"] + } +} + +resource "aws_iam_role" "eks_cluster_role" { + name = "${var.cluster_name}-cluster-role" + assume_role_policy = data.aws_iam_policy_document.eks_cluster_assume.json +} + +resource "aws_iam_role_policy_attachment" "cluster_policy" { + role = aws_iam_role.eks_cluster_role.name + policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy" +} + +resource "aws_iam_role" "eks_node_role" { + name = "${var.cluster_name}-node-role" + assume_role_policy = data.aws_iam_policy_document.eks_node_assume.json +} + +data "aws_iam_policy_document" "eks_node_assume" { + statement { + effect = "Allow" + principals { + type = "Service" + identifiers = ["ec2.amazonaws.com"] + } + actions = ["sts:AssumeRole"] + } +} + +resource "aws_iam_role_policy_attachment" "node_worker_policy" { + role = aws_iam_role.eks_node_role.name + policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy" +} + +resource "aws_iam_role_policy_attachment" "node_cni_policy" { + role = aws_iam_role.eks_node_role.name + policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy" +} + +resource "aws_iam_role_policy_attachment" "node_ecr_readonly" { + role = aws_iam_role.eks_node_role.name + policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly" +} diff --git a/eks/main.tf b/eks/main.tf new file mode 100644 index 0000000..3ad9cbe --- /dev/null +++ b/eks/main.tf @@ -0,0 +1,8 @@ +module "eks_cluster" { + source = "./eks" + cluster_name = "bank23-eks" + cluster_role_arn = "arn:aws:iam::ACCOUNT_ID:role/EKSClusterRole" + node_group_name = "bank23-ng" + node_role_arn = "arn:aws:iam::ACCOUNT_ID:role/EKSNodeRole" + subnet_ids = ["subnet-xxxx", "subnet-yyyy"] +} diff --git a/eks/nodeGroup.tf b/eks/nodeGroup.tf new file mode 100644 index 0000000..e42f0fa --- /dev/null +++ b/eks/nodeGroup.tf @@ -0,0 +1,8 @@ +resource "aws_eks_node_group" "nodes" { + cluster_name = aws_eks_cluster.main.name + node_group_name = var.node_group_name + node_role_arn = var.node_role_arn + subnet_ids = var.subnet_ids + instance_types = ["t3.medium"] + desired_size = 2 +} diff --git a/eks/output.tf b/eks/output.tf new file mode 100644 index 0000000..c69e9d7 --- /dev/null +++ b/eks/output.tf @@ -0,0 +1,15 @@ +output "cluster_name" { + value = aws_eks_cluster.this.name +} + +output "cluster_endpoint" { + value = aws_eks_cluster.this.endpoint +} + +output "kubeconfig_command" { + value = "aws eks update-kubeconfig --region ${var.region} --name ${aws_eks_cluster.this.name}" +} + +output "node_group" { + value = aws_eks_node_group.managed_nodes.node_group_name +} diff --git a/eks/provider.tf b/eks/provider.tf new file mode 100644 index 0000000..31060c5 --- /dev/null +++ b/eks/provider.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.0" + required_providers { + aws = { source = "hashicorp/aws" } + } +} + +provider "aws" { + region = var.region +} diff --git a/eks/variables.tf b/eks/variables.tf new file mode 100644 index 0000000..92d6e01 --- /dev/null +++ b/eks/variables.tf @@ -0,0 +1,7 @@ +variable "cluster_name" {} +variable "cluster_role_arn" {} +variable "node_group_name" {} +variable "node_role_arn" {} +variable "subnet_ids" { + type = list(string) +} diff --git a/eks/vpc.tf b/eks/vpc.tf new file mode 100644 index 0000000..3fbd3f7 --- /dev/null +++ b/eks/vpc.tf @@ -0,0 +1,43 @@ +data "aws_availability_zones" "available" {} + +resource "aws_vpc" "eks_vpc" { + cidr_block = var.vpc_cidr + tags = { Name = "${var.cluster_name}-vpc" } +} + +resource "aws_internet_gateway" "igw" { + vpc_id = aws_vpc.eks_vpc.id + tags = { Name = "${var.cluster_name}-igw" } +} + +resource "aws_subnet" "public" { + count = length(var.public_subnet_cidrs) + vpc_id = aws_vpc.eks_vpc.id + cidr_block = var.public_subnet_cidrs[count.index] + map_public_ip_on_launch = true + availability_zone = data.aws_availability_zones.available.names[count.index] + tags = { Name = "${var.cluster_name}-public-${count.index}" } +} + +resource "aws_subnet" "private" { + count = length(var.private_subnet_cidrs) + vpc_id = aws_vpc.eks_vpc.id + cidr_block = var.private_subnet_cidrs[count.index] + availability_zone = data.aws_availability_zones.available.names[count.index] + tags = { Name = "${var.cluster_name}-private-${count.index}" } +} + +resource "aws_route_table" "public_rt" { + vpc_id = aws_vpc.eks_vpc.id + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.igw.id + } + tags = { Name = "${var.cluster_name}-public-rt" } +} + +resource "aws_route_table_association" "public_assoc" { + count = length(aws_subnet.public) + subnet_id = aws_subnet.public[count.index].id + route_table_id = aws_route_table.public_rt.id +} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/module-database/mysql.tf b/modules/module-database/mysql.tf index 72e8c20..b22f6ab 100644 --- a/modules/module-database/mysql.tf +++ b/modules/module-database/mysql.tf @@ -8,18 +8,18 @@ resource "aws_db_subnet_group" "mysql_subnet_group" { } } resource "aws_db_instance" "mysql_db_instance" { - identifier = "${var.environment}-mysql-db" - engine = "mysql" - engine_version = "8.0" - instance_class = var.db_instance_class - allocated_storage = var.db_allocated_storage - storage_type = "gp2" - db_subnet_group_name = aws_db_subnet_group.mysql_subnet_group.name - vpc_security_group_ids = [var.aws_security_group_ids] - username = var.db_username - password = var.db_password - db_name = var.db_name - skip_final_snapshot = true + identifier = "${var.environment}-mysql-db" + engine = "mysql" + engine_version = "8.0" + instance_class = var.db_instance_class + allocated_storage = var.db_allocated_storage + storage_type = "gp2" + db_subnet_group_name = aws_db_subnet_group.mysql_subnet_group.name + vpc_security_group_ids = [var.aws_security_group_ids] + username = var.db_username + password = var.db_password + db_name = var.db_name + skip_final_snapshot = true tags = { Name = "${var.environment}-mysql-db-instance" @@ -29,5 +29,5 @@ resource "aws_db_instance" "mysql_db_instance" { lifecycle { ignore_changes = [password] } - + } \ No newline at end of file diff --git a/modules/module-dns/namecheap-name-servers.tf b/modules/module-dns/namecheap-name-servers.tf index aea16c8..59750eb 100644 --- a/modules/module-dns/namecheap-name-servers.tf +++ b/modules/module-dns/namecheap-name-servers.tf @@ -1,7 +1,7 @@ resource "namecheap_domain_records" "my-domain2-com" { domain = var.domain-name - mode = "OVERWRITE" // Warning: this will remove all manually set records + mode = "OVERWRITE" // Warning: this will remove all manually set records -nameservers = aws_route53_zone.r53_zone.name_servers -depends_on = [ aws_route53_zone.r53_zone ] + nameservers = aws_route53_zone.r53_zone.name_servers + depends_on = [aws_route53_zone.r53_zone] } \ No newline at end of file diff --git a/modules/module-dns/output.tf b/modules/module-dns/output.tf index af3324f..741017a 100644 --- a/modules/module-dns/output.tf +++ b/modules/module-dns/output.tf @@ -1,4 +1,4 @@ output "route53_name_servers" { - description = "The name servers of the Route 53 hosted zone" - value = aws_route53_zone.r53_zone.name_servers + description = "The name servers of the Route 53 hosted zone" + value = aws_route53_zone.r53_zone.name_servers } diff --git a/modules/module-dns/provider.tf b/modules/module-dns/provider.tf index f4a0a7d..ded4f97 100644 --- a/modules/module-dns/provider.tf +++ b/modules/module-dns/provider.tf @@ -1,7 +1,7 @@ terraform { required_providers { namecheap = { - source = "namecheap/namecheap" + source = "namecheap/namecheap" version = ">= 2.0.0" } } diff --git a/modules/module-dns/r52-hosted-zone.tf b/modules/module-dns/r52-hosted-zone.tf index e1b209c..cb44111 100644 --- a/modules/module-dns/r52-hosted-zone.tf +++ b/modules/module-dns/r52-hosted-zone.tf @@ -1,32 +1,32 @@ resource "aws_route53_zone" "r53_zone" { - name = var.domain-name - comment = "Managed by Terraform" - force_destroy = true - - tags = { - Name = "${var.environment}-hosted-zone" - Environment = var.environment - } + name = var.domain-name + comment = "Managed by Terraform" + force_destroy = true + + tags = { + Name = "${var.environment}-hosted-zone" + Environment = var.environment + } } resource "aws_route53_record" "name" { - zone_id = aws_route53_zone.r53_zone.zone_id - name = "bank.${var.domain-name}" # Use a subdomain for CNAME - type = "CNAME" - ttl = 300 - records = [var.nginx_lb_ip] + zone_id = aws_route53_zone.r53_zone.zone_id + name = "bank.${var.domain-name}" # Use a subdomain for CNAME + type = "CNAME" + ttl = 300 + records = [var.nginx_lb_ip] } resource "aws_route53_record" "name1" { - zone_id = aws_route53_zone.r53_zone.zone_id - name = "bankapi.${var.domain-name}" # Use a subdomain for CNAME - type = "CNAME" - ttl = 300 - records = [var.nginx_lb_ip] + zone_id = aws_route53_zone.r53_zone.zone_id + name = "bankapi.${var.domain-name}" # Use a subdomain for CNAME + type = "CNAME" + ttl = 300 + records = [var.nginx_lb_ip] } resource "aws_route53_record" "name2" { - zone_id = aws_route53_zone.r53_zone.zone_id - name = "argocd.${var.domain-name}" # Use a subdomain for CNAME - type = "CNAME" - ttl = 300 - records = [var.nginx_lb_ip] + zone_id = aws_route53_zone.r53_zone.zone_id + name = "argocd.${var.domain-name}" # Use a subdomain for CNAME + type = "CNAME" + ttl = 300 + records = [var.nginx_lb_ip] } \ No newline at end of file diff --git a/modules/module-dns/variables.tf b/modules/module-dns/variables.tf index a82a940..65906ab 100644 --- a/modules/module-dns/variables.tf +++ b/modules/module-dns/variables.tf @@ -2,8 +2,8 @@ variable "environment" {} variable "domain-name" {} variable "nginx_ingress_lb_dns" { description = "DNS name of the NGINX Ingress Load Balancer" - type = string - + type = string + } variable "nginx_lb_ip" { description = "IP address of the NGINX Ingress Load Balancer" diff --git a/modules/module-eks/addons.tf b/modules/module-eks/addons.tf index 02b6c6a..fdd09ea 100644 --- a/modules/module-eks/addons.tf +++ b/modules/module-eks/addons.tf @@ -1,9 +1,9 @@ provider "helm" { - kubernetes { - host = aws_eks_cluster.eks.endpoint - cluster_ca_certificate = base64decode(aws_eks_cluster.eks.certificate_authority[0].data) - token = data.aws_eks_cluster_auth.eks.token - } + kubernetes { + host = aws_eks_cluster.eks.endpoint + cluster_ca_certificate = base64decode(aws_eks_cluster.eks.certificate_authority[0].data) + token = data.aws_eks_cluster_auth.eks.token + } } provider "kubernetes" { @@ -14,18 +14,18 @@ provider "kubernetes" { } data "aws_eks_cluster_auth" "eks" { - name = aws_eks_cluster.eks.name + name = aws_eks_cluster.eks.name } resource "helm_release" "nginx_ingress" { - name = "nginx-ingress" - repository = "https://kubernetes.github.io/ingress-nginx" - chart = "ingress-nginx" - version = "4.12.0" - namespace = "ingress-nginx" - create_namespace = true + name = "nginx-ingress" + repository = "https://kubernetes.github.io/ingress-nginx" + chart = "ingress-nginx" + version = "4.12.0" + namespace = "ingress-nginx" + create_namespace = true - values = [file("${path.module}/nginx-ingress-values.yaml")] - depends_on = [ aws_eks_node_group.eks_node_group ] + values = [file("${path.module}/nginx-ingress-values.yaml")] + depends_on = [aws_eks_node_group.eks_node_group] } data "aws_lb" "nginx_ingress" { @@ -37,27 +37,27 @@ data "aws_lb" "nginx_ingress" { } resource "helm_release" "cert_manager" { - name = "cert-manager" - repository = "https://charts.jetstack.io" - chart = "cert-manager" - version = "1.14.5" - namespace = "cert-manager" - create_namespace = true - set { - name = "installCRDs" - value = "true" - } - depends_on = [ helm_release.nginx_ingress ] + name = "cert-manager" + repository = "https://charts.jetstack.io" + chart = "cert-manager" + version = "1.14.5" + namespace = "cert-manager" + create_namespace = true + set { + name = "installCRDs" + value = "true" + } + depends_on = [helm_release.nginx_ingress] } #================================================== resource "helm_release" "argocd" { - name = "argocd" - repository = "https://argoproj.github.io/argo-helm" - chart = "argo-cd" - version = "5.51.6" - namespace = "argocd" - create_namespace = true - values = [file("${path.module}/argocd-values.yaml")] - depends_on = [ helm_release.nginx_ingress, helm_release.cert_manager] + name = "argocd" + repository = "https://argoproj.github.io/argo-helm" + chart = "argo-cd" + version = "5.51.6" + namespace = "argocd" + create_namespace = true + values = [file("${path.module}/argocd-values.yaml")] + depends_on = [helm_release.nginx_ingress, helm_release.cert_manager] } \ No newline at end of file diff --git a/modules/module-eks/eks-node-group.tf b/modules/module-eks/eks-node-group.tf index b718f45..4dbf618 100644 --- a/modules/module-eks/eks-node-group.tf +++ b/modules/module-eks/eks-node-group.tf @@ -2,19 +2,19 @@ resource "aws_eks_node_group" "eks_node_group" { cluster_name = aws_eks_cluster.eks.id node_group_name = "${var.environment}-eks-node-group" node_role_arn = aws_iam_role.eks_node_group_role.arn - subnet_ids = concat(var.public_subnet_ids, var.private_subnet_ids) + subnet_ids = concat(var.public_subnet_ids, var.private_subnet_ids) version = var.eks_version capacity_type = var.capacity_type - ami_type = var.ami_type + ami_type = var.ami_type scaling_config { desired_size = var.desired_size max_size = var.max_size min_size = var.min_size } - + instance_types = var.instance_types labels = { - role = var.label_one + role = var.label_one environment = var.environment } @@ -30,5 +30,5 @@ resource "aws_eks_node_group" "eks_node_group" { aws_iam_role_policy_attachment.eks_fargate_pod_execution_role_policy, aws_iam_role_policy_attachment.ssm_managed_instance_core_policy ] - + } \ No newline at end of file diff --git a/modules/module-eks/eks-node-groups-role.tf b/modules/module-eks/eks-node-groups-role.tf index 0fc0aa6..05244dd 100644 --- a/modules/module-eks/eks-node-groups-role.tf +++ b/modules/module-eks/eks-node-groups-role.tf @@ -18,7 +18,7 @@ resource "aws_iam_role" "eks_node_group_role" { Name = "${var.environment}-eks-node_group-role" Environment = var.environment } - + } # Attach the AmazonEKSWorkerNodePolicy to the EKS node group role resource "aws_iam_role_policy_attachment" "eks_worker_node_policy" { @@ -33,8 +33,8 @@ resource "aws_iam_role_policy_attachment" "eks_cni_policy" { } # Attach the AmazonEC2ContainerRegistryReadOnly policy to the EKS node group role resource "aws_iam_role_policy_attachment" "ec2_container_registry_policy" { - role = aws_iam_role.eks_node_group_role.name - policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly" + role = aws_iam_role.eks_node_group_role.name + policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly" } # The AmazonEKSNodePolicy does not exist; skipping attachment. # Attach the AmazonEKSFargatePodExecutionRolePolicy to the EKS node group role @@ -44,8 +44,8 @@ resource "aws_iam_role_policy_attachment" "eks_fargate_pod_execution_role_policy } # Attach the AmazonSSMManagedInstanceCore policy to the EKS node group role resource "aws_iam_role_policy_attachment" "ssm_managed_instance_core_policy" { - role = aws_iam_role.eks_node_group_role.name - policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" + role = aws_iam_role.eks_node_group_role.name + policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" } resource "aws_iam_role_policy_attachment" "eks_elb_permissions" { diff --git a/modules/module-eks/eks-role.tf b/modules/module-eks/eks-role.tf index 6c69f75..9dc639c 100644 --- a/modules/module-eks/eks-role.tf +++ b/modules/module-eks/eks-role.tf @@ -15,7 +15,7 @@ resource "aws_iam_role" "eks_cluster_role" { } ] }) - tags = { + tags = { Name = "${var.environment}-eks-cluster-role" Environment = var.environment } diff --git a/modules/module-eks/eks.tf b/modules/module-eks/eks.tf index 357296e..b5f1dca 100644 --- a/modules/module-eks/eks.tf +++ b/modules/module-eks/eks.tf @@ -1,19 +1,19 @@ resource "aws_eks_cluster" "eks" { - name = "${var.environment}-${var.cluster_name}" - role_arn = aws_iam_role.eks_cluster_role.arn - version = var.eks_version - vpc_config { - subnet_ids = concat(var.public_subnet_ids, var.private_subnet_ids) - endpoint_public_access = true - endpoint_private_access = true - } + name = "${var.environment}-${var.cluster_name}" + role_arn = aws_iam_role.eks_cluster_role.arn + version = var.eks_version + vpc_config { + subnet_ids = concat(var.public_subnet_ids, var.private_subnet_ids) + endpoint_public_access = true + endpoint_private_access = true + } - depends_on = [ - aws_iam_role_policy_attachment.eks_cluster_policy, - aws_iam_role_policy_attachment.eks_vpc_resource_controller_policy - ] - tags = { - Name = "${var.environment}-${var.cluster_name}" - Environment = var.environment - } + depends_on = [ + aws_iam_role_policy_attachment.eks_cluster_policy, + aws_iam_role_policy_attachment.eks_vpc_resource_controller_policy + ] + tags = { + Name = "${var.environment}-${var.cluster_name}" + Environment = var.environment + } } \ No newline at end of file diff --git a/modules/module-eks/variables.tf b/modules/module-eks/variables.tf index 9c63260..48b21ad 100644 --- a/modules/module-eks/variables.tf +++ b/modules/module-eks/variables.tf @@ -2,14 +2,14 @@ variable "vpc_cidrblock" { description = "CIDR block for the VPC" type = string default = "192.168.0.0/16" - + } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "staging" - + } variable "create_subnet" { @@ -22,7 +22,7 @@ variable "countsub" { description = "Number of subnets to create" type = number default = 2 - + } variable "create_elastic_ip" { description = "Flag to create Elastic IPs" @@ -45,14 +45,14 @@ variable "max_size" { variable "min_size" { description = "Minimum size of the EKS node group" type = number - default = 2 + default = 2 } variable "instance_types" { description = "Instance types for the EKS node group" type = list(string) - default = ["t2.micro"] -} + default = ["t2.micro"] +} variable "capacity_type" { description = "Capacity type for the EKS node group" @@ -83,14 +83,14 @@ variable "public_subnet_ids" { type = list(string) } variable "private_subnet_ids" { - type = list(string) + type = list(string) description = "List of private subnet IDs" } variable "cluster_name" { } variable "repository_name" { - + } variable "domain-name" {} diff --git a/modules/module-vpc/02-vpc.tf b/modules/module-vpc/02-vpc.tf index 86274d3..f240633 100644 --- a/modules/module-vpc/02-vpc.tf +++ b/modules/module-vpc/02-vpc.tf @@ -1,11 +1,11 @@ resource "aws_vpc" "vpc-main" { - cidr_block = var.vpc_cidrblock - instance_tenancy = "default" - enable_dns_support = true - enable_dns_hostnames = true + cidr_block = var.vpc_cidrblock + instance_tenancy = "default" + enable_dns_support = true + enable_dns_hostnames = true assign_generated_ipv6_cidr_block = false tags = { - Name = "${var.environment}-vpc" + Name = "${var.environment}-vpc" Environment = var.environment } } \ No newline at end of file diff --git a/modules/module-vpc/03-igt.tf b/modules/module-vpc/03-igt.tf index 4c825a3..d774f5b 100644 --- a/modules/module-vpc/03-igt.tf +++ b/modules/module-vpc/03-igt.tf @@ -2,7 +2,7 @@ resource "aws_internet_gateway" "gw" { vpc_id = aws_vpc.vpc-main.id tags = { - Name = "${var.environment}-internet-gateway" + Name = "${var.environment}-internet-gateway" Environment = var.environment } } \ No newline at end of file diff --git a/modules/module-vpc/04-public_subnet.tf b/modules/module-vpc/04-public_subnet.tf index 10ed48f..bc23b28 100644 --- a/modules/module-vpc/04-public_subnet.tf +++ b/modules/module-vpc/04-public_subnet.tf @@ -9,18 +9,18 @@ data "aws_availability_zones" "available" { # Public Subnet Configuration #============================ resource "aws_subnet" "public_subnet" { - count = var.create_subnet ? var.countsub : 0 - vpc_id = aws_vpc.vpc-main.id - availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = "192.168.${count.index}.0/24" - map_public_ip_on_launch = true + count = var.create_subnet ? var.countsub : 0 + vpc_id = aws_vpc.vpc-main.id + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = "192.168.${count.index}.0/24" + map_public_ip_on_launch = true - tags = { - Name = "${var.environment}-public-subnet-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" - Environment = var.environment - "kubernetes.io/cluster/eks" = "1" - "kubernetes.io/role/elb" = "1" - "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" - } + tags = { + Name = "${var.environment}-public-subnet-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" + Environment = var.environment + "kubernetes.io/cluster/eks" = "1" + "kubernetes.io/role/elb" = "1" + "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" + } } diff --git a/modules/module-vpc/05-private_subnets.tf b/modules/module-vpc/05-private_subnets.tf index 9a732fb..b2ccace 100644 --- a/modules/module-vpc/05-private_subnets.tf +++ b/modules/module-vpc/05-private_subnets.tf @@ -1,17 +1,17 @@ # private Subnet Configuration #============================ resource "aws_subnet" "private_subnet" { - count = var.create_subnet ? var.countsub : 0 - vpc_id = aws_vpc.vpc-main.id - availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = "192.168.${count.index + 3}.0/24" - #map_public_ip_on_launch = true + count = var.create_subnet ? var.countsub : 0 + vpc_id = aws_vpc.vpc-main.id + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = "192.168.${count.index + 3}.0/24" + #map_public_ip_on_launch = true - tags = { - Name = "${var.environment}-private-subnet-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" - Environment = var.environment - "kubernetes.io/cluster/eks" = "shared" - "kubernetes.io/role/internal-elb" = "1" - "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" - } + tags = { + Name = "${var.environment}-private-subnet-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" + Environment = var.environment + "kubernetes.io/cluster/eks" = "shared" + "kubernetes.io/role/internal-elb" = "1" + "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" + } } diff --git a/modules/module-vpc/06-elp.tf b/modules/module-vpc/06-elp.tf index c1f2d5c..41c30fc 100644 --- a/modules/module-vpc/06-elp.tf +++ b/modules/module-vpc/06-elp.tf @@ -1,9 +1,9 @@ resource "aws_eip" "elastic-ip" { - count = var.create_elastic_ip ? var.countsub : 0 - tags = { - Name = "${var.environment}-elastic-ip-nat-gateway-${count.index + 1}" - Environment = var.environment - } + count = var.create_elastic_ip ? var.countsub : 0 + tags = { + Name = "${var.environment}-elastic-ip-nat-gateway-${count.index + 1}" + Environment = var.environment + } - depends_on = [ aws_internet_gateway.gw ] + depends_on = [aws_internet_gateway.gw] } \ No newline at end of file diff --git a/modules/module-vpc/07-nat-gateway.tf b/modules/module-vpc/07-nat-gateway.tf index 72240d9..9cde6bc 100644 --- a/modules/module-vpc/07-nat-gateway.tf +++ b/modules/module-vpc/07-nat-gateway.tf @@ -1,9 +1,9 @@ resource "aws_nat_gateway" "name" { - count = var.create_elastic_ip ? var.countsub : 0 - allocation_id = aws_eip.elastic-ip[count.index].id - subnet_id = aws_subnet.public_subnet[count.index].id - tags = { - Name = "${var.environment}-nat-gateway-${count.index + 1}" - Environment = var.environment - } + count = var.create_elastic_ip ? var.countsub : 0 + allocation_id = aws_eip.elastic-ip[count.index].id + subnet_id = aws_subnet.public_subnet[count.index].id + tags = { + Name = "${var.environment}-nat-gateway-${count.index + 1}" + Environment = var.environment + } } \ No newline at end of file diff --git a/modules/module-vpc/08-private-route-table.tf b/modules/module-vpc/08-private-route-table.tf index 6e9347c..bd1466c 100644 --- a/modules/module-vpc/08-private-route-table.tf +++ b/modules/module-vpc/08-private-route-table.tf @@ -1,16 +1,16 @@ resource "aws_route_table" "private_route_table" { - count = true ? var.countsub : 0 + count = true ? var.countsub : 0 vpc_id = aws_vpc.vpc-main.id tags = { - Name = "${var.environment}-private-route-table-${count.index + 1}" + Name = "${var.environment}-private-route-table-${count.index + 1}" Environment = var.environment } } resource "aws_route" "private_route" { - count = true ? var.countsub : 0 - route_table_id = aws_route_table.private_route_table[count.index].id + count = true ? var.countsub : 0 + route_table_id = aws_route_table.private_route_table[count.index].id destination_cidr_block = "0.0.0.0/0" - nat_gateway_id = aws_nat_gateway.name[count.index].id + nat_gateway_id = aws_nat_gateway.name[count.index].id } \ No newline at end of file diff --git a/modules/module-vpc/09-public-route-table.tf b/modules/module-vpc/09-public-route-table.tf index 68eef41..32891ae 100644 --- a/modules/module-vpc/09-public-route-table.tf +++ b/modules/module-vpc/09-public-route-table.tf @@ -19,7 +19,7 @@ resource "aws_main_route_table_association" "main" { } # add a route to the default route table to allow internet access resource "aws_route" "default-route-table" { - route_table_id = data.aws_route_table.default-route-table.id - destination_cidr_block = "0.0.0.0/0" - gateway_id = aws_internet_gateway.gw.id + route_table_id = data.aws_route_table.default-route-table.id + destination_cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.gw.id } \ No newline at end of file diff --git a/modules/module-vpc/10-public-route-associate.tf b/modules/module-vpc/10-public-route-associate.tf index 92c1027..5540d7a 100644 --- a/modules/module-vpc/10-public-route-associate.tf +++ b/modules/module-vpc/10-public-route-associate.tf @@ -1,8 +1,8 @@ resource "aws_route_table_association" "public_route_table_association" { - count = true ? var.countsub : 0 + count = true ? var.countsub : 0 subnet_id = aws_subnet.public_subnet[count.index].id route_table_id = data.aws_route_table.default-route-table.id depends_on = [aws_internet_gateway.gw] - + } \ No newline at end of file diff --git a/modules/module-vpc/11-private-route-associate.tf b/modules/module-vpc/11-private-route-associate.tf index ed93a7b..b4a8d77 100644 --- a/modules/module-vpc/11-private-route-associate.tf +++ b/modules/module-vpc/11-private-route-associate.tf @@ -1,17 +1,17 @@ resource "aws_route_table_association" "private_route_association" { - count = true ? var.countsub : 0 + count = true ? var.countsub : 0 subnet_id = aws_subnet.private_subnet[count.index].id route_table_id = aws_route_table.private_route_table[count.index].id - depends_on = [aws_nat_gateway.name] - + depends_on = [aws_nat_gateway.name] + } resource "aws_route_table_association" "private_route_association_db" { - count = true ? var.countsub : 0 + count = true ? var.countsub : 0 subnet_id = aws_subnet.private_subnet_db[count.index].id route_table_id = aws_route_table.private_route_table[count.index].id - depends_on = [aws_nat_gateway.name] - + depends_on = [aws_nat_gateway.name] + } \ No newline at end of file diff --git a/modules/module-vpc/12-private-subnet-db.tf b/modules/module-vpc/12-private-subnet-db.tf index 4bf0c35..7187304 100644 --- a/modules/module-vpc/12-private-subnet-db.tf +++ b/modules/module-vpc/12-private-subnet-db.tf @@ -1,17 +1,17 @@ # private Subnet Configuration #============================ resource "aws_subnet" "private_subnet_db" { - count = var.create_subnet ? var.countsub : 0 - vpc_id = aws_vpc.vpc-main.id - availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = "192.168.${count.index + 5}.0/24" - #map_public_ip_on_launch = true + count = var.create_subnet ? var.countsub : 0 + vpc_id = aws_vpc.vpc-main.id + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = "192.168.${count.index + 5}.0/24" + #map_public_ip_on_launch = true - tags = { - Name = "${var.environment}-private-subnet-db-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" - Environment = var.environment - "kubernetes.io/cluster/eks" = "shared" - "kubernetes.io/role/internal-elb" = "1" - "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" - } + tags = { + Name = "${var.environment}-private-subnet-db-${count.index + 1}-${data.aws_availability_zones.available.names[count.index]}" + Environment = var.environment + "kubernetes.io/cluster/eks" = "shared" + "kubernetes.io/role/internal-elb" = "1" + "kubernetes.io/cluster/${var.environment}-${var.cluster_name}" = "owned" + } } diff --git a/modules/module-vpc/13-mysql-sg.tf b/modules/module-vpc/13-mysql-sg.tf index 4d8a9f0..7e1e4ec 100644 --- a/modules/module-vpc/13-mysql-sg.tf +++ b/modules/module-vpc/13-mysql-sg.tf @@ -15,7 +15,7 @@ resource "aws_security_group" "mysql_sg" { to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] - -} + + } } \ No newline at end of file diff --git a/modules/module-vpc/output.tf b/modules/module-vpc/output.tf index 0dc0b1d..1725e5d 100644 --- a/modules/module-vpc/output.tf +++ b/modules/module-vpc/output.tf @@ -1,8 +1,8 @@ output "vpc_id" { description = "The ID of the VPC" value = aws_vpc.vpc-main.id - sensitive = true - + sensitive = true + } output "private_subnet_ids" { @@ -23,5 +23,5 @@ output "private_subnet_db_ids" { output "aws_security_group_ids" { description = "List of security group IDs" value = aws_security_group.mysql_sg.id - + } \ No newline at end of file diff --git a/modules/module-vpc/variables.tf b/modules/module-vpc/variables.tf index d52e293..2e6c284 100644 --- a/modules/module-vpc/variables.tf +++ b/modules/module-vpc/variables.tf @@ -2,14 +2,14 @@ variable "vpc_cidrblock" { description = "CIDR block for the VPC" type = string default = "192.168.0.0/16" - + } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "staging" - + } variable "create_subnet" { @@ -22,7 +22,7 @@ variable "countsub" { description = "Number of subnets to create" type = number default = 2 - + } variable "create_elastic_ip" { description = "Flag to create Elastic IPs" diff --git a/prod/01-provider.tf b/prod/01-provider.tf index e987edf..db65d0a 100644 --- a/prod/01-provider.tf +++ b/prod/01-provider.tf @@ -6,21 +6,21 @@ terraform { required_providers { namecheap = { - source = "namecheap/namecheap" + source = "namecheap/namecheap" version = "2.2.0" } aws = { - source = "hashicorp/aws" + source = "hashicorp/aws" version = "6.0.0-beta2" } } } provider "namecheap" { - user_name = var.namecheap_username - api_user = var.namecheap_api_user - api_key = var.namecheap_api_key - client_ip = var.namecheap_client_ip + user_name = var.namecheap_username + api_user = var.namecheap_api_user + api_key = var.namecheap_api_key + client_ip = var.namecheap_client_ip use_sandbox = false } provider "aws" { diff --git a/prod/main.tf b/prod/main.tf index ecebd57..8fdb6b1 100644 --- a/prod/main.tf +++ b/prod/main.tf @@ -1,57 +1,57 @@ # Creating a VPC and EKS cluster using Terraform module "vpc-deployment" { - source = "./module-vpc" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - + source = "./module-vpc" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + } #creating an EKS cluster using Terraform # and deploying it in the VPC created above module "eks-deployment" { - source = "./module-eks" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - desired_size = var.desired_size - max_size = var.max_size - min_size = var.min_size - instance_types = var.instance_types - capacity_type = var.capacity_type - public_subnet_ids = module.vpc-deployment.public_subnet_ids - private_subnet_ids = module.vpc-deployment.private_subnet_ids - cluster_name = var.cluster_name - repository_name = var.repository_name - domain-name = var.domain-name - email = var.email - + source = "./module-eks" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + desired_size = var.desired_size + max_size = var.max_size + min_size = var.min_size + instance_types = var.instance_types + capacity_type = var.capacity_type + public_subnet_ids = module.vpc-deployment.public_subnet_ids + private_subnet_ids = module.vpc-deployment.private_subnet_ids + cluster_name = var.cluster_name + repository_name = var.repository_name + domain-name = var.domain-name + email = var.email + } module "namecheap-deployment" { - source = "./module-dns" - environment = var.environment - domain-name = var.domain-name - nginx_lb_ip = module.eks-deployment.nginx_lb_ip - nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname - nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns - + source = "./module-dns" + environment = var.environment + domain-name = var.domain-name + nginx_lb_ip = module.eks-deployment.nginx_lb_ip + nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname + nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns + } module "rds-mysql-deployment" { - source = "./module-database" - environment = var.environment - db_instance_class = var.db_instance_class - db_allocated_storage = var.db_allocated_storage - private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids - db_name = var.db_name - db_password = var.db_password - db_username = var.db_username - aws_security_group_ids = module.vpc-deployment.aws_security_group_ids + source = "./module-database" + environment = var.environment + db_instance_class = var.db_instance_class + db_allocated_storage = var.db_allocated_storage + private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids + db_name = var.db_name + db_password = var.db_password + db_username = var.db_username + aws_security_group_ids = module.vpc-deployment.aws_security_group_ids } \ No newline at end of file diff --git a/prod/terraform.tfvars b/prod/terraform.tfvars index 42fc12e..4a84a00 100644 --- a/prod/terraform.tfvars +++ b/prod/terraform.tfvars @@ -1,17 +1,17 @@ -environment = "production" -vpc_cidrblock = "192.168.0.0/16" -countsub = 2 -create_subnet = true +environment = "production" +vpc_cidrblock = "192.168.0.0/16" +countsub = 2 +create_subnet = true create_elastic_ip = true -desired_size = 2 -max_size = 6 -min_size = 2 -instance_types = ["t2.medium"] -capacity_type = "ON_DEMAND" -ami_type = "AL2_x86_64" -label_one = "system-nodepool" -eks_version = "1.32" -domain-name = "cloudwitches.online" -cluster_name = "eks-cluster" -repository_name = "eks-repository" -email = "support@digitalwitchng.online" +desired_size = 2 +max_size = 6 +min_size = 2 +instance_types = ["t2.medium"] +capacity_type = "ON_DEMAND" +ami_type = "AL2_x86_64" +label_one = "system-nodepool" +eks_version = "1.32" +domain-name = "cloudwitches.online" +cluster_name = "eks-cluster" +repository_name = "eks-repository" +email = "support@digitalwitchng.online" diff --git a/prod/variable.tf b/prod/variable.tf index f283b35..82bf36f 100644 --- a/prod/variable.tf +++ b/prod/variable.tf @@ -2,14 +2,14 @@ variable "vpc_cidrblock" { description = "CIDR block for the VPC" type = string default = "192.168.0.0/16" - + } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "staging" - + } variable "create_subnet" { @@ -22,7 +22,7 @@ variable "countsub" { description = "Number of subnets to create" type = number default = 2 - + } variable "create_elastic_ip" { description = "Flag to create Elastic IPs" @@ -46,14 +46,14 @@ variable "max_size" { variable "min_size" { description = "Minimum size of the EKS node group" type = number - default = 2 + default = 2 } variable "instance_types" { description = "Instance types for the EKS node group" type = list(string) - default = ["t2.micro"] -} + default = ["t2.micro"] +} variable "capacity_type" { description = "Capacity type for the EKS node group" @@ -115,7 +115,7 @@ variable "namecheap_client_ip" { variable "db_instance_class" { description = "Instance class for the RDS database" type = string - default = "db.t3.micro" + default = "db.t3.micro" } variable "db_allocated_storage" { @@ -158,7 +158,7 @@ variable "repository_name" { description = "Name of the ECR repository" type = string default = "eks-repository" - + } variable "email" { diff --git a/staging/01-provider.tf b/staging/01-provider.tf index e987edf..db65d0a 100644 --- a/staging/01-provider.tf +++ b/staging/01-provider.tf @@ -6,21 +6,21 @@ terraform { required_providers { namecheap = { - source = "namecheap/namecheap" + source = "namecheap/namecheap" version = "2.2.0" } aws = { - source = "hashicorp/aws" + source = "hashicorp/aws" version = "6.0.0-beta2" } } } provider "namecheap" { - user_name = var.namecheap_username - api_user = var.namecheap_api_user - api_key = var.namecheap_api_key - client_ip = var.namecheap_client_ip + user_name = var.namecheap_username + api_user = var.namecheap_api_user + api_key = var.namecheap_api_key + client_ip = var.namecheap_client_ip use_sandbox = false } provider "aws" { diff --git a/staging/main.tf b/staging/main.tf index ecebd57..8fdb6b1 100644 --- a/staging/main.tf +++ b/staging/main.tf @@ -1,57 +1,57 @@ # Creating a VPC and EKS cluster using Terraform module "vpc-deployment" { - source = "./module-vpc" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - + source = "./module-vpc" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + } #creating an EKS cluster using Terraform # and deploying it in the VPC created above module "eks-deployment" { - source = "./module-eks" - - environment = var.environment - vpc_cidrblock = var.vpc_cidrblock - countsub = var.countsub - create_subnet = var.create_subnet - create_elastic_ip = var.create_elastic_ip - desired_size = var.desired_size - max_size = var.max_size - min_size = var.min_size - instance_types = var.instance_types - capacity_type = var.capacity_type - public_subnet_ids = module.vpc-deployment.public_subnet_ids - private_subnet_ids = module.vpc-deployment.private_subnet_ids - cluster_name = var.cluster_name - repository_name = var.repository_name - domain-name = var.domain-name - email = var.email - + source = "./module-eks" + + environment = var.environment + vpc_cidrblock = var.vpc_cidrblock + countsub = var.countsub + create_subnet = var.create_subnet + create_elastic_ip = var.create_elastic_ip + desired_size = var.desired_size + max_size = var.max_size + min_size = var.min_size + instance_types = var.instance_types + capacity_type = var.capacity_type + public_subnet_ids = module.vpc-deployment.public_subnet_ids + private_subnet_ids = module.vpc-deployment.private_subnet_ids + cluster_name = var.cluster_name + repository_name = var.repository_name + domain-name = var.domain-name + email = var.email + } module "namecheap-deployment" { - source = "./module-dns" - environment = var.environment - domain-name = var.domain-name - nginx_lb_ip = module.eks-deployment.nginx_lb_ip - nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname - nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns - + source = "./module-dns" + environment = var.environment + domain-name = var.domain-name + nginx_lb_ip = module.eks-deployment.nginx_lb_ip + nginx_ingress_load_balancer_hostname = module.eks-deployment.nginx_ingress_load_balancer_hostname + nginx_ingress_lb_dns = module.eks-deployment.nginx_ingress_lb_dns + } module "rds-mysql-deployment" { - source = "./module-database" - environment = var.environment - db_instance_class = var.db_instance_class - db_allocated_storage = var.db_allocated_storage - private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids - db_name = var.db_name - db_password = var.db_password - db_username = var.db_username - aws_security_group_ids = module.vpc-deployment.aws_security_group_ids + source = "./module-database" + environment = var.environment + db_instance_class = var.db_instance_class + db_allocated_storage = var.db_allocated_storage + private_subnet_db_ids = module.vpc-deployment.private_subnet_db_ids + db_name = var.db_name + db_password = var.db_password + db_username = var.db_username + aws_security_group_ids = module.vpc-deployment.aws_security_group_ids } \ No newline at end of file diff --git a/staging/terraform.tfvars b/staging/terraform.tfvars index 42fc12e..4a84a00 100644 --- a/staging/terraform.tfvars +++ b/staging/terraform.tfvars @@ -1,17 +1,17 @@ -environment = "production" -vpc_cidrblock = "192.168.0.0/16" -countsub = 2 -create_subnet = true +environment = "production" +vpc_cidrblock = "192.168.0.0/16" +countsub = 2 +create_subnet = true create_elastic_ip = true -desired_size = 2 -max_size = 6 -min_size = 2 -instance_types = ["t2.medium"] -capacity_type = "ON_DEMAND" -ami_type = "AL2_x86_64" -label_one = "system-nodepool" -eks_version = "1.32" -domain-name = "cloudwitches.online" -cluster_name = "eks-cluster" -repository_name = "eks-repository" -email = "support@digitalwitchng.online" +desired_size = 2 +max_size = 6 +min_size = 2 +instance_types = ["t2.medium"] +capacity_type = "ON_DEMAND" +ami_type = "AL2_x86_64" +label_one = "system-nodepool" +eks_version = "1.32" +domain-name = "cloudwitches.online" +cluster_name = "eks-cluster" +repository_name = "eks-repository" +email = "support@digitalwitchng.online" diff --git a/staging/variable.tf b/staging/variable.tf index f283b35..82bf36f 100644 --- a/staging/variable.tf +++ b/staging/variable.tf @@ -2,14 +2,14 @@ variable "vpc_cidrblock" { description = "CIDR block for the VPC" type = string default = "192.168.0.0/16" - + } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "staging" - + } variable "create_subnet" { @@ -22,7 +22,7 @@ variable "countsub" { description = "Number of subnets to create" type = number default = 2 - + } variable "create_elastic_ip" { description = "Flag to create Elastic IPs" @@ -46,14 +46,14 @@ variable "max_size" { variable "min_size" { description = "Minimum size of the EKS node group" type = number - default = 2 + default = 2 } variable "instance_types" { description = "Instance types for the EKS node group" type = list(string) - default = ["t2.micro"] -} + default = ["t2.micro"] +} variable "capacity_type" { description = "Capacity type for the EKS node group" @@ -115,7 +115,7 @@ variable "namecheap_client_ip" { variable "db_instance_class" { description = "Instance class for the RDS database" type = string - default = "db.t3.micro" + default = "db.t3.micro" } variable "db_allocated_storage" { @@ -158,7 +158,7 @@ variable "repository_name" { description = "Name of the ECR repository" type = string default = "eks-repository" - + } variable "email" { diff --git a/tfplan b/tfplan new file mode 100644 index 0000000000000000000000000000000000000000..51a3a1ebb5d631ebe7078d4729a7974e584983d6 GIT binary patch literal 2223 zcmWIWW@Zs#-~htUmF>|CNPvxjlc6N7ASW>|G=!Cbk*mivvnI$kU&K&ARY6umbUMxg>cEG!AXaHr3Oq+y6^{{i=ij zzKgG~xcsXtS#P~BdSZ>9)2X$FFXW#X>N;Ioq4Xg_(423ntg*Xj@Qv&zOQJ8=SZoc@ zU00G~yKtTGsk+Xyp-e-J+9ueS+;G>FQ+M{ML`GWd7U_^baEnp@%6(qoDyYE zIUbUg{!{2H$y8{Tv-|AXH@UhC{Z7>G6gO#WaeMiId-q~1!;@cSXKYx{FY~ph<|n)3 zr>S1j@(*@DSi`vO;OSETd+K}_wQSvDPlfuQdACbv$IQp_*(%%W(lt|Oev`>PqqAaN zidRe4w@QPr>#bCmx$ep}Kg&1KU&iZ8QK+z1aI-R7tlqYH!*s!7c)2EdOnX-;&8pKHFty{ZYTi@;V;@=KBb}GWzkQqe zy?y_8Zu(@-!0`WnfHynGr<$%Pb|waf8fFHD0Gw%v9h`=WOA<>`;fctl=QLlFfq?7x z8du|NZwWcOAEL<~*0NI~R?ZAEZ>cxG(t5i1-N{()r4J4ZEjMspf9vo$?(P|eC$fL& zH>hq)Wwq?knf&pB_L&#UXP%w=ebv!r#lE!{uiV`H?oG$6yBA-a>S?)V<-Yvacfm`a z{JdM@)<%mRGE`B#clGNuQQH~wnhSjFrWb$OccUvGnARbFSH**!*>$ zCV$En4obFPZP>2-2N>KC2iF!^7v}*TI}xvgCBP0&&d*EBOxMrV)h|md%1lhkNiEhZ zNrO9{5oRXPC((j<(G)#sdrcr!dVZGJDH za6NPLRgB2goZw}lN}(1hOv-0|{g3>1J$f$p-FI{PYP6?qSYcZ#n007s^KPwOt#$bu zxPM1jEqk&w?QdW3%@<#{_8+$6I}h{=B*b>I@ty^R)@QuF6Gro0ZenI0ve!rqEKwBW z@>5DdVV_l;k0?;Po&^Q00Ae8cUT#W Date: Tue, 9 Dec 2025 17:11:38 +0100 Subject: [PATCH 3/3] Add Fluent Bit DaemonSet Terraform configuration --- READme.m | 39 +++++++ iam.tf | 45 ++++++++ kubernetes.tf | 170 ++++++++++++++++++++++++++++++ outputs.tf | 19 ++++ terraform.tfvars | 3 + terraform/fluent-bit/main.tf | 18 ++++ terraform/fluent-bit/variables.tf | 33 ++++++ variables.tf | 33 ++++++ 8 files changed, 360 insertions(+) create mode 100644 READme.m create mode 100644 iam.tf create mode 100644 kubernetes.tf create mode 100644 outputs.tf create mode 100644 terraform.tfvars create mode 100644 terraform/fluent-bit/main.tf create mode 100644 terraform/fluent-bit/variables.tf diff --git a/READme.m b/READme.m new file mode 100644 index 0000000..3900ecb --- /dev/null +++ b/READme.m @@ -0,0 +1,39 @@ + Fluent Bit DaemonSet Deployment +This deploys Fluent Bit as a DaemonSet to collect logs from all Kubernetes pods and send them to AWS CloudWatch. + +Prerequisites +- AWS CLI configured +- kubectl configured for dev-test-eks cluster +- Terraform installed + +Deployment Steps + +1. Update `terraform.tfvars` with your node group name +2. Initialize Terraform: +```bash + terraform init +``` +3. Validate configuration: +```bash + terraform validate +``` +4. Deploy: +```bash + terraform apply +``` + +Verification +```bash +kubectl get daemonset fluent-bit -n kube-system +kubectl get pods -n kube-system -l k8s-app=fluent-bit +kubectl logs -n kube-system -l k8s-app=fluent-bit --tail=50 +``` + +Check CloudWatch: https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logsV2:log-groups/log-group/kubernetes-logs + +Resources Created +- CloudWatch Log Group: kubernetes-logs +- IAM Policy: FluentBitCloudWatchPolicy +- Kubernetes ServiceAccount, ClusterRole, ClusterRoleBinding +- ConfigMap with Fluent Bit configuration +- DaemonSet running Fluent Bit on all nodes \ No newline at end of file diff --git a/iam.tf b/iam.tf new file mode 100644 index 0000000..a6121f9 --- /dev/null +++ b/iam.tf @@ -0,0 +1,45 @@ +data "aws_eks_cluster" "cluster" { + name = var.cluster_name +} + +data "aws_eks_node_group" "node_group" { + cluster_name = var.cluster_name + node_group_name = var.node_group_name +} + +data "aws_caller_identity" "current" {} + +data "aws_iam_role" "node_role" { + name = split("/", data.aws_eks_node_group.node_group.node_role_arn)[1] +} + +resource "aws_iam_policy" "fluent_bit_cloudwatch" { + name = "FluentBitCloudWatchPolicy" + description = "Policy for Fluent Bit to write logs to CloudWatch" + + policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Effect = "Allow" + Action = [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents", + "logs:DescribeLogStreams" + ] + Resource = "arn:aws:logs:${var.aws_region}:${data.aws_caller_identity.current.account_id}:log-group:${var.log_group_name}:*" + } + ] + }) +} + +resource "aws_iam_role_policy_attachment" "fluent_bit_cloudwatch" { + policy_arn = aws_iam_policy.fluent_bit_cloudwatch.arn + role = data.aws_iam_role.node_role.name +} + +resource "aws_cloudwatch_log_group" "kubernetes_logs" { + name = var.log_group_name + retention_in_days = var.log_retention_days +} \ No newline at end of file diff --git a/kubernetes.tf b/kubernetes.tf new file mode 100644 index 0000000..e735943 --- /dev/null +++ b/kubernetes.tf @@ -0,0 +1,170 @@ +provider "kubernetes" { + host = data.aws_eks_cluster.cluster.endpoint + cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority[0].data) + + exec { + api_version = "client.authentication.k8s.io/v1beta1" + args = ["eks", "get-token", "--cluster-name", var.cluster_name] + command = "aws" + } +} + +resource "kubernetes_service_account_v1" "fluent_bit" { + metadata { + name = "fluent-bit" + namespace = var.fluent_bit_namespace + } +} + +resource "kubernetes_cluster_role_v1" "fluent_bit" { + metadata { + name = "fluent-bit-read" + } + + rule { + api_groups = [""] + resources = ["namespaces", "pods"] + verbs = ["get", "list", "watch"] + } +} + +resource "kubernetes_cluster_role_binding_v1" "fluent_bit" { + metadata { + name = "fluent-bit-read" + } + + role_ref { + api_group = "rbac.authorization.k8s.io" + kind = "ClusterRole" + name = kubernetes_cluster_role_v1.fluent_bit.metadata[0].name + } + + subject { + kind = "ServiceAccount" + name = kubernetes_service_account_v1.fluent_bit.metadata[0].name + namespace = var.fluent_bit_namespace + } +} + +resource "kubernetes_config_map_v1" "fluent_bit" { + metadata { + name = "fluent-bit-config" + namespace = var.fluent_bit_namespace + } + + data = { + "fluent-bit.conf" = <<-EOT + [SERVICE] + Flush 5 + Log_Level info + Daemon off + + [INPUT] + Name tail + Path /var/log/containers/*.log + Parser docker + Tag kube.* + Refresh_Interval 5 + Mem_Buf_Limit 5MB + Skip_Long_Lines On + + [FILTER] + Name kubernetes + Match kube.* + Kube_URL https://kubernetes.default.svc:443 + Kube_CA_File /var/run/secrets/kubernetes.io/serviceaccount/ca.crt + Kube_Token_File /var/run/secrets/kubernetes.io/serviceaccount/token + Merge_Log On + Keep_Log Off + + [OUTPUT] + Name cloudwatch_logs + Match * + region ${var.aws_region} + log_group_name ${var.log_group_name} + log_stream_prefix fluentbit- + auto_create_group true + EOT + + "parsers.conf" = <<-EOT + [PARSER] + Name docker + Format json + Time_Key time + Time_Format %Y-%m-%dT%H:%M:%S.%L + Time_Keep On + EOT + } +} + +resource "kubernetes_daemon_set_v1" "fluent_bit" { + metadata { + name = "fluent-bit" + namespace = var.fluent_bit_namespace + labels = { + k8s-app = "fluent-bit" + } + } + + spec { + selector { + match_labels = { + k8s-app = "fluent-bit" + } + } + + template { + metadata { + labels = { + k8s-app = "fluent-bit" + } + } + + spec { + service_account_name = kubernetes_service_account_v1.fluent_bit.metadata[0].name + + container { + name = "fluent-bit" + image = "fluent/fluent-bit:2.1" + + volume_mount { + name = "varlog" + mount_path = "/var/log" + } + + volume_mount { + name = "varlibdockercontainers" + mount_path = "/var/lib/docker/containers" + read_only = true + } + + volume_mount { + name = "fluent-bit-config" + mount_path = "/fluent-bit/etc/" + } + } + + volume { + name = "varlog" + host_path { + path = "/var/log" + } + } + + volume { + name = "varlibdockercontainers" + host_path { + path = "/var/lib/docker/containers" + } + } + + volume { + name = "fluent-bit-config" + config_map { + name = kubernetes_config_map_v1.fluent_bit.metadata[0].name + } + } + } + } + } +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..bf13928 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,19 @@ +output "cloudwatch_log_group_name" { + value = aws_cloudwatch_log_group.kubernetes_logs.name +} + +output "cloudwatch_log_group_arn" { + value = aws_cloudwatch_log_group.kubernetes_logs.arn +} + +output "iam_policy_arn" { + value = aws_iam_policy.fluent_bit_cloudwatch.arn +} + +output "verification_commands" { + value = <<-EOT + kubectl get daemonset fluent-bit -n kube-system + kubectl get pods -n kube-system -l k8s-app=fluent-bit + kubectl logs -n kube-system -l k8s-app=fluent-bit --tail=50 + EOT +} \ No newline at end of file diff --git a/terraform.tfvars b/terraform.tfvars new file mode 100644 index 0000000..571bb8c --- /dev/null +++ b/terraform.tfvars @@ -0,0 +1,3 @@ +aws_region = "us-east-1" +cluster_name = "dev-test-eks" +node_group_name = "dev-eks-node-group" \ No newline at end of file diff --git a/terraform/fluent-bit/main.tf b/terraform/fluent-bit/main.tf new file mode 100644 index 0000000..e2b9550 --- /dev/null +++ b/terraform/fluent-bit/main.tf @@ -0,0 +1,18 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } + kubernetes = { + source = "hashicorp/kubernetes" + version = "~> 2.23" + } + } +} + +provider "aws" { + region = var.aws_region +} \ No newline at end of file diff --git a/terraform/fluent-bit/variables.tf b/terraform/fluent-bit/variables.tf new file mode 100644 index 0000000..f93df90 --- /dev/null +++ b/terraform/fluent-bit/variables.tf @@ -0,0 +1,33 @@ +variable "aws_region" { + description = "AWS region for CloudWatch" + type = string + default = "us-east-1" +} + +variable "cluster_name" { + description = "dev-test-eks" + type = string +} + +variable "log_group_name" { + description = "CloudWatch log group name" + type = string + default = "kubernetes-logs" +} + +variable "log_retention_days" { + description = "Number of days to retain logs" + type = number + default = 7 +} + +variable "fluent_bit_namespace" { + description = "Kubernetes namespace for Fluent Bit" + type = string + default = "kube-system" +} + +variable "node_group_name" { + description = "dev-eks-node-group" + type = string +}|C \ No newline at end of file diff --git a/variables.tf b/variables.tf index e69de29..85c092c 100644 --- a/variables.tf +++ b/variables.tf @@ -0,0 +1,33 @@ +variable "aws_region" { + description = "AWS region for CloudWatch" + type = string + default = "us-east-1" +} + +variable "cluster_name" { + description = "dev-test-eks" + type = string +} + +variable "log_group_name" { + description = "CloudWatch log group name" + type = string + default = "kubernetes-logs" +} + +variable "log_retention_days" { + description = "Number of days to retain logs" + type = number + default = 7 +} + +variable "fluent_bit_namespace" { + description = "Kubernetes namespace for Fluent Bit" + type = string + default = "kube-system" +} + +variable "node_group_name" { + description = "dev-eks-node-group" + type = string +} \ No newline at end of file