Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first commit #207

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8d1486e
first commit
sheikhug Aug 8, 2024
ef3d895
changed name
sheikhug Aug 8, 2024
5d883c4
corrected error
sheikhug Aug 8, 2024
a10570c
Update outputs.tf
sheikhug Aug 8, 2024
13d52e8
Update 2 to outputs.tf
sheikhug Aug 8, 2024
16f13c6
create security groups
sheikhug Aug 8, 2024
28153b8
corrected errors
sheikhug Aug 8, 2024
9c3fbf6
corrected_errors 2
sheikhug Aug 8, 2024
4ceeb37
corrected errors
sheikhug Aug 8, 2024
5b2b144
Use module for security group
sheikhug Aug 9, 2024
1c717ab
Use module for security group
sheikhug Aug 9, 2024
60a8f83
Use module for security group
sheikhug Aug 9, 2024
bc0ed9d
Use module for VPC
sheikhug Aug 9, 2024
fe468a4
load balancer
sheikhug Aug 9, 2024
d4318e2
Load balancer
sheikhug Aug 9, 2024
7c1add5
Load balancer 2
sheikhug Aug 9, 2024
2f2e614
load balancer
sheikhug Aug 9, 2024
2c915fa
load balancer
sheikhug Aug 9, 2024
2116f4b
load balancer
sheikhug Aug 9, 2024
026b5b6
load balancer 2
sheikhug Aug 9, 2024
2e5b29f
autoscaling
sheikhug Aug 9, 2024
8d99edf
autoscaling
sheikhug Aug 9, 2024
399c96f
autoscaling
sheikhug Aug 9, 2024
c2d1fdd
autoscaling
sheikhug Aug 9, 2024
74747f5
asg
sheikhug Aug 9, 2024
eb866da
asg
sheikhug Aug 9, 2024
22dec44
asg
sheikhug Aug 9, 2024
7693ba0
asg
sheikhug Aug 9, 2024
4d703fd
asg2
sheikhug Aug 9, 2024
e439a03
asg3
sheikhug Aug 9, 2024
8b0cc0c
asg 3
sheikhug Aug 9, 2024
6390943
Refactor to use variables
sheikhug Aug 9, 2024
505d984
Refactor to use variables 2
sheikhug Aug 9, 2024
7cc02c3
Modularise
sheikhug Aug 9, 2024
631d7f1
Define dev environment
sheikhug Aug 9, 2024
4bd4c9c
Define dev environment
sheikhug Aug 9, 2024
6c07215
Define dev environment 2
sheikhug Aug 9, 2024
14af538
Define QA Environment
sheikhug Aug 9, 2024
6bbb2f3
Define dev environment 2
sheikhug Aug 9, 2024
5d25c38
Define dev environment 4
sheikhug Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dev/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module "dev" {
source = "../modules/blog"
}
File renamed without changes.
24 changes: 0 additions & 24 deletions main.tf

This file was deleted.

101 changes: 101 additions & 0 deletions modules/blog/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
data "aws_ami" "app_ami" {
most_recent = true

filter {
name = "name"
values = [var.ami_filter.name]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = [var.ami_filter.owner]
}



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

name = var.environment.name
cidr = "${var.environment.network_prefix}.0.0/16"

azs = ["us-west-2a", "us-west-2b", "us-west-2c"]
public_subnets = ["${var.environment.network_prefix}.101.0/24", "${var.environment.network_prefix}.102.0/24", "${var.environment.network_prefix}.103.0/24"]

tags = {
Terraform = "true"
Environment = var.environment.name
}
}

module "blog_asg" {
source = "terraform-aws-modules/autoscaling/aws"

# Autoscaling group
name = "${var.environment.name}-blog"

min_size = var.asg_min_size
max_size = var.asg_max_size
vpc_zone_identifier = module.blog_vpc.public_subnets
target_group_arns = [module.blog_alb.target_groups["ex-instance"].arn]
security_groups = [module.blog_sg.security_group_id]


image_id = data.aws_ami.app_ami.id
instance_type = var.instance_type

}

module "blog_alb" {
source = "terraform-aws-modules/alb/aws"
version = "9.10.0"

name = "blog-alb"
vpc_id = module.blog_vpc.vpc_id
subnets = module.blog_vpc.public_subnets
security_groups = [module.blog_sg.security_group_id]


listeners = {
ex-http-https-redirect = {
port = 80
protocol = "HTTP"
redirect = {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
}

target_groups = {
ex-instance = {
name_prefix = "${var.environment.name}-"
protocol = "HTTP"
port = 80
target_type = "instance"
create_attachment = false
}
}

tags = {
Environment = var.environment.name
}
}

module "blog_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.2"

name = "${var.environment.name}-blog"
vpc_id = module.blog_vpc.vpc_id

ingress_rules = ["http-80-tcp", "https-443-tcp"]
ingress_cidr_blocks = ["0.0.0.0/0"]

egress_rules = ["all-all"]
egress_cidr_blocks = ["0.0.0.0/0"]
}
3 changes: 3 additions & 0 deletions modules/blog/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "environment_url" {
value = module.blog_alb.dns_name
}
44 changes: 44 additions & 0 deletions modules/blog/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
variable "instance_type" {
description = "Type of EC2 instance to provision"
default = "t3.nano"
}

variable "ami_filter" {
description = "Name filter and owner of AMI"

type = object({
name = string
owner = string
})

default = {
name = "bitnami-tomcat-*-x86_64-hvm-ebs-nami"
owner = "979382823631" # Bitnami
}

}

variable "environment" {
description = "Development environment"

type = object({
name = string
network_prefix = string
})

default = {
name = "dev"
network_prefix = "10.0"
}
}


variable "asg_min_size" {
description = "Minimum number of instances in ASG"
default = 1
}

variable "asg_max_size" {
description = "Maximum number of instances in ASG"
default = 2
}
7 changes: 0 additions & 7 deletions outputs.tf

This file was deleted.

12 changes: 12 additions & 0 deletions qa/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module "qa" {
source = "../modules/blog"

environment = {
name = "qa"
network_prefix = "10.1"
}

asg_min_size = 1
asg_max_size = 1

}
3 changes: 3 additions & 0 deletions qa/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "environment_url" {
value = module.qa.environment_url
}
11 changes: 11 additions & 0 deletions qa/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}

provider "aws" {
region = "us-west-2"
}
4 changes: 0 additions & 4 deletions variables.tf

This file was deleted.