Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a8176a7
Initial commit
JReaves10 May 7, 2025
f636aed
Update main.tf
JReaves10 May 7, 2025
377a228
Update outputs.tf
JReaves10 May 7, 2025
5703e6d
Update outputs.tf
JReaves10 May 7, 2025
583ad4e
Update outputs.tf
JReaves10 May 7, 2025
208e855
Create security group
JReaves10 May 7, 2025
26ed02f
Use module for security group
JReaves10 May 8, 2025
afa678b
Clear old security groups
JReaves10 May 8, 2025
730102f
create new dev vpc
JReaves10 May 8, 2025
dbc6520
load balancer
JReaves10 May 8, 2025
05cd785
array for sgs
JReaves10 May 8, 2025
e42fc01
load balancer
JReaves10 May 8, 2025
755ce74
change back to listeners block
JReaves10 May 8, 2025
7bf9ace
array sg
JReaves10 May 8, 2025
06727c6
back to west
JReaves10 May 8, 2025
9bb1deb
refactor to use variables + add autoscaling
JReaves10 May 8, 2025
1df81d2
add bracket
JReaves10 May 8, 2025
19ae111
spell check
JReaves10 May 8, 2025
dedfff3
updatea autoscaling
JReaves10 May 8, 2025
7a60a9e
fix errors
JReaves10 May 8, 2025
a83d1d9
id to identifier
JReaves10 May 8, 2025
0dff963
Modularize
JReaves10 May 8, 2025
03acaec
Define dev environment
JReaves10 May 8, 2025
4c9a26e
fix root directory
JReaves10 May 8, 2025
3b819cf
try this directory
JReaves10 May 8, 2025
b23b189
try this change
JReaves10 May 8, 2025
83628ef
whoops
JReaves10 May 8, 2025
f488bb7
Define QA Environment
JReaves10 May 8, 2025
4ad03c9
compile fixes
JReaves10 May 8, 2025
a3236b8
help delete
JReaves10 May 8, 2025
82316ba
trying things
JReaves10 May 8, 2025
17d4489
try this
JReaves10 May 8, 2025
0fa6c49
i give up
JReaves10 May 8, 2025
f27f0ca
delete plz
JReaves10 May 8, 2025
7a6620f
sure
JReaves10 May 8, 2025
e5901d6
pussh
JReaves10 May 8, 2025
16e63ab
.
JReaves10 May 8, 2025
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.

98 changes: 98 additions & 0 deletions modules/blog/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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]
}
data "aws_vpc" "default" {
default = true
}

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 "autoscaling" {
source = "terraform-aws-modules/autoscaling/aws"

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
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"

name = "${var.environment.name}-blog-alb"

vpc_id = module.blog_vpc.vpc_id
subnets = module.blog_vpc.public_subnets
security_groups = [module.blog_sg.security_group_id]
enable_deletion_protection = false

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"
}
}

tags = {
Environment = var.environment.name
Project = "Example"
}
}

module "blog_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.3.0"
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"]
}
11 changes: 11 additions & 0 deletions modules/blog/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#output "instance_ami" {
# value = aws_instance.blog.ami
#}

#output "instance_arn" {
# value = aws_instance.blog.arn
#}

#output "environment_url" {
# value = module.blog_alb.dns_name
#}
11 changes: 11 additions & 0 deletions modules/blog/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"
}
43 changes: 43 additions & 0 deletions modules/blog/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
variable "instance_type" {
description = "Type of EC2 instance to provision"
default = "t3.nano"
}

variable "ami_filter" {
description = "Name and owner filter for 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 the ASG"
default = 1
}

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

This file was deleted.

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

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

asg_min_size = 0
asg_max_size = 0
}
3 changes: 3 additions & 0 deletions qa/output.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.