Skip to content

Commit

Permalink
Changed the solution stack
Browse files Browse the repository at this point in the history
  • Loading branch information
prashansa joshi committed Nov 7, 2024
1 parent 2c606a7 commit d0aef3f
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 140 deletions.
7 changes: 4 additions & 3 deletions terraform/alb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ module "alb" {

source = "./modules/terraform-aws-elb-module"

name = local.alb.alb_name
vpc_id = data.aws_vpc.adex_poc_default_vpc.id
name = local.alb.alb_name
# vpc_id = data.aws_vpc.adex_poc_default_vpc.id
vpc_id = module.vpc.vpc_id

subnets = local.alb.subnets
subnets = local.alb.public_subnets
internal = local.alb.internal
load_balancer_type = local.alb.load_balancer_type
enable_cross_zone_load_balancing = local.alb.enable_cross_zone_load_balancing
Expand Down
7 changes: 4 additions & 3 deletions terraform/backend.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
terraform {
backend "s3" {
region = "us-east-1"
key = "beanstalk/beanstalk_project.tfstate"
bucket = "beanstalk-development-ebs-ue1-eb-d-s3"
dynamodb_table = "beanstalk-development-ebs-ue1-eb-d-s3"
key = "675738512763/beanstalk_project.tfstate"
bucket = "adex-terraform-state"
dynamodb_table = "adex-terraform-state"
acl = "bucket-owner-full-control"
encrypt = true
}
}
28 changes: 14 additions & 14 deletions terraform/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ data "aws_availability_zones" "available" {}

data "aws_ami" "ami_id" {
most_recent = true
owners = ["099720109477"]
owners = ["amazon"]
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
Expand All @@ -15,24 +15,24 @@ data "aws_ami" "ami_id" {
}


data "aws_vpc" "adex_poc_default_vpc" {
id = var.vpc_id
}
# data "aws_vpc" "adex_poc_default_vpc" {
# id = var.vpc_id
# }

# data "aws_subnets" "default" {
# vpc_id = data.aws_vpc.adex_poc_default_vpc.id
# }
data "aws_subnets" "subnets" {
filter {
name = "vpc-id"
values = [var.vpc_id]
}
}
# data "aws_subnets" "subnets" {
# filter {
# name = "vpc-id"
# values = [var.vpc_id]
# }
# }

data "aws_subnet" "subnet" {
for_each = toset(data.aws_subnets.subnets.ids)
id = each.value
}
# data "aws_subnet" "subnet" {
# for_each = toset(data.aws_subnets.subnets.ids)
# id = each.value
# }

data "aws_iam_policy_document" "minimal_s3_permissions" {

Expand Down
8 changes: 4 additions & 4 deletions terraform/eb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ module "elastic_beanstalk_environment" {
autoscale_upper_bound = var.autoscale_upper_bound
autoscale_upper_increment = var.autoscale_upper_increment

# vpc_id = module.vpc.vpc_id
vpc_id = data.aws_vpc.adex_poc_default_vpc.id
loadbalancer_subnets = var.public_subnets
application_subnets = var.private_subnets
vpc_id = module.vpc.vpc_id
# vpc_id = data.aws_vpc.adex_poc_default_vpc.id
loadbalancer_subnets = module.vpc.public_subnets
application_subnets = module.vpc.private_subnets

rolling_update_enabled = var.rolling_update_enabled
rolling_update_type = var.rolling_update_type
Expand Down
23 changes: 11 additions & 12 deletions terraform/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@ locals {
environment = var.naming_environment
name = var.project

# # VPC
# vpc = {
# vpc_name = module.naming.resources.vpc.name
# vpc_cidr = var.vpc_cidr
# azs = slice(data.aws_availability_zones.available.names, 0, var.number_of_azs)
# }
# VPC
vpc = {
vpc_name = module.naming.resources.vpc.name
vpc_cidr = var.vpc_cidr
azs = slice(data.aws_availability_zones.available.names, 0, var.number_of_azs)
}

# Application load balancer
alb = {
alb_name = module.naming.resources.alb.name
vpc_id = data.aws_vpc.adex_poc_default_vpc
# public_subnets = [data.aws_subnets.private_subnets.id[0], data.aws_subnets.private_subnets.id[1]]
# vpc_id = module.vpc.vpc_id
# public_subnets = [module.vpc.private_subnets[0], module.vpc.private_subnets[1]]
subnets = var.private_subnets
# vpc_id = data.aws_vpc.adex_poc_default_vpc
vpc_id = module.vpc.vpc_id
public_subnets = [module.vpc.private_subnets[0], module.vpc.private_subnets[1]]
# subnets = var.private_subnets
internal = var.internal
load_balancer_type = var.load_balancer_type
enable_cross_zone_load_balancing = var.enable_cross_zone_load_balancing
enable_deletion_protection = var.enable_deletion_protection
backend_port = var.backend_port
backend_protocol = var.backend_protocol
target_group_name = "${var.environment}-ebs-alb"
target_group_name = "${var.environment}-eb-alb"
target_group_index = var.target_group_index
target_type = var.target_type
create_attachment = var.create_attachment
Expand Down
6 changes: 3 additions & 3 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ output "latest_ubuntu_ami_id" {
value = data.aws_ami.ami_id.id
}

output "subnet_cidr_blocks" {
value = [for s in data.aws_subnet.subnet : s.cidr_block]
}
# output "subnet_cidr_blocks" {
# value = [for s in data.aws_subnet.subnet : s.cidr_block]
# }

output "alb_arn" {
value = module.alb.lb_arn
Expand Down
56 changes: 28 additions & 28 deletions terraform/prod.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ naming_environment = "development"
environment = "dev"

## Variables for VPC
vpc_id = "vpc-03d964f7cd3fa2c74"
# vpc_cidr = "10.0.0.0/16"
# number_of_azs = 2
# vpc_id = "vpc-03d964f7cd3fa2c74"
vpc_cidr = "10.0.0.0/16"
number_of_azs = 2

## Variables for ALB
internal = false
load_balancer_type = "application"
enable_cross_zone_load_balancing = true
enable_deletion_protection = false
private_subnets = ["subnet-094222bc07bb63e74", "subnet-0a6f15fc861987834"]
# private_subnets = ["subnet-094222bc07bb63e74", "subnet-0a6f15fc861987834"]
backend_port = 80
backend_protocol = "HTTP"
target_group_index = 0
Expand All @@ -27,27 +27,27 @@ environment_type = "LoadBalanced"
loadbalancer_type = "application"
loadbalancer_is_shared = true
availability_zone_selector = "Any 2"
availability_zones = ["us-east-1a", "us-east-1b"]
wait_for_ready_timeout = "20m"
version_label = ""
solution_stack_name = "64bit Amazon Linux 2023 v6.2.0 running Node.js 20"
instance_type = "t2.micro"
root_volume_size = 8
root_volume_type = "gp2"
autoscale_min = 1
autoscale_max = 2
autoscale_measure_name = "CPUUtilization"
autoscale_statistic = "Average"
autoscale_unit = "Percent"
autoscale_lower_bound = 20
autoscale_lower_increment = -1
autoscale_upper_bound = 80
autoscale_upper_increment = 1
rolling_update_enabled = true
rolling_update_type = "Health"
updating_min_in_service = 0
updating_max_batch = 1
public_subnets = ["subnet-0f97b0bb45cdeb3b7", "subnet-0cd1b0c6e27ef5b97"]
# availability_zones = ["us-east-1a", "us-east-1b"]
wait_for_ready_timeout = "20m"
version_label = ""
solution_stack_name = "64bit Amazon Linux 2 v5.9.7 running Node.js 18"
instance_type = "t2.micro"
root_volume_size = 8
root_volume_type = "gp2"
autoscale_min = 1
autoscale_max = 2
autoscale_measure_name = "CPUUtilization"
autoscale_statistic = "Average"
autoscale_unit = "Percent"
autoscale_lower_bound = 20
autoscale_lower_increment = -1
autoscale_upper_bound = 80
autoscale_upper_increment = 1
rolling_update_enabled = true
rolling_update_type = "Health"
updating_min_in_service = 0
updating_max_batch = 1
# public_subnets = module.vpc.public_subnets
additional_settings = [
{
namespace = "aws:elasticbeanstalk:managedactions"
Expand All @@ -62,10 +62,10 @@ additional_settings = [
]

env_vars = {
"DB_HOST" = "ebs-ue1-eb-d-rds.cmuokqciitb8.us-east-1.rds.amazonaws.com"
"DB_HOST" = "ebs-as1-eb-d-rds.cuz4tzfo0b5i.ap-south-1.rds.amazonaws.com"
"DB_PORT" = "3306"
"DB_USERNAME" = "elasticbeanstalk"
"DB_PASSWORD" = "AlXmBgEuzUl3h3qA"
"DB_PASSWORD" = "L64w19vAGVYBOSCe"
"DB_NAME" = "elasticbeanstalk"
}

Expand All @@ -75,7 +75,7 @@ scheduled_actions = [
minsize = "1"
maxsize = "2"
desiredcapacity = "2"
starttime = "2015-05-14T07:00:00Z"
starttime = "2024-05-14T07:00:00Z"
endtime = "2025-01-12T07:00:00Z"
recurrence = "*/20 * * * *"
suspend = false
Expand Down
11 changes: 1 addition & 10 deletions terraform/rds.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module "rds" {
multi_az = local.rds.multi_az
skip_final_snapshot = local.rds.skip_final_snapshot
deletion_protection = false
db_subnet_group_name = aws_db_subnet_group.ebs_db_subnet.id
db_subnet_group_name = module.vpc.database_subnet_group
vpc_security_group_ids = [aws_security_group.database.id]
apply_immediately = local.rds.apply_immediately
create_random_password = local.rds.create_random_password
Expand All @@ -28,12 +28,3 @@ module "rds" {

}


resource "aws_db_subnet_group" "ebs_db_subnet" {
name = "main"
subnet_ids = ["subnet-094222bc07bb63e74", "subnet-0a6f15fc861987834 "]

tags = {
Name = "My DB subnet group"
}
}
11 changes: 6 additions & 5 deletions terraform/sg.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
resource "aws_security_group" "alb" {
name = "${module.naming.resources.sg.name}-alb-sg"
description = "Allow traffic to and from loadbalancer"
vpc_id = data.aws_vpc.adex_poc_default_vpc.id
# vpc_id = module.vpc.vpc_id
# vpc_id = data.aws_vpc.adex_poc_default_vpc.id
vpc_id = module.vpc.vpc_id

# HTTP rule
ingress {
Expand Down Expand Up @@ -50,8 +50,8 @@ resource "aws_security_group" "alb" {
resource "aws_security_group" "database" {
name = "${module.naming.resources.rds.name}-sg"
description = "Security group for database"
vpc_id = data.aws_vpc.adex_poc_default_vpc.id
# vpc_id = module.vpc.vpc_id
# vpc_id = data.aws_vpc.adex_poc_default_vpc.id
vpc_id = module.vpc.vpc_id

ingress {
description = "TLS from VPC"
Expand Down Expand Up @@ -82,7 +82,8 @@ resource "aws_security_group" "database" {
resource "aws_security_group" "eb_instances" {
name = "${local.elastic_beanstalk_application.name}-sg"
description = "Security group for Elastic Beanstalk instances"
vpc_id = data.aws_vpc.adex_poc_default_vpc.id
# vpc_id = data.aws_vpc.adex_poc_default_vpc.id
vpc_id = module.vpc.vpc_id

ingress {
from_port = 80
Expand Down
44 changes: 22 additions & 22 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ variable "project" {
# variables for VPC
#################################################################################

# variable "vpc_cidr" {
# description = "cidr of vpc"
# }
variable "vpc_cidr" {
description = "cidr of vpc"
}

# variable "vpc_name" {
# description = "name of vpc"
# }

# variable "number_of_azs" {
# description = "number of availability zones"
# type = number
# }

variable "vpc_id" {
description = "The default VPC"
# default = "vpc-03d964f7cd3fa2c74"
variable "number_of_azs" {
description = "number of availability zones"
type = number
}

# variable "vpc_id" {
# description = "The default VPC"
# # default = "vpc-03d964f7cd3fa2c74"
# }

################################################################################
# variables for elastic beanstalk environment
###############################################################################
Expand Down Expand Up @@ -175,9 +175,9 @@ variable "updating_max_batch" {
description = "Maximum number of instances to update at once"
}

variable "public_subnets" {
description = "loadbalancer subnets"
}
# variable "public_subnets" {
# description = "loadbalancer subnets"
# }

variable "additional_settings" {
type = list(object({
Expand Down Expand Up @@ -211,10 +211,10 @@ variable "scheduled_actions" {
description = "Define a list of scheduled actions"
}

variable "availability_zones" {
type = list(string)
description = "List of availability zones"
}
# variable "availability_zones" {
# type = list(string)
# description = "List of availability zones"
# }

#################################################################################
# Variables for ALB
Expand All @@ -240,10 +240,10 @@ variable "enable_deletion_protection" {
type = bool
}

variable "private_subnets" {
description = "Subnets ids for alb"
# type = string
}
# variable "private_subnets" {
# description = "Subnets ids for alb"
# # type = string
# }

variable "backend_port" {
description = "value of the backend port"
Expand Down
Loading

0 comments on commit d0aef3f

Please sign in to comment.