Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 15 additions & 18 deletions AWS_Workshop/AWS_Workshop_Code/Working_Directory/Resources/apps.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ locals {
app_subnet = var.app_subnet_cidr != [] ? aws_subnet.app_subnet : data.aws_subnet.appftd
}

data "template_file" "apache_install" {
template = file("${path.module}/apache_install.tpl")
}

data "aws_subnet" "appftd" {
count = var.app_subnet_cidr == [] ? length(var.app_subnet_name) : 0
filter {
Expand Down Expand Up @@ -34,8 +30,8 @@ resource "aws_network_interface" "ftd_app" {
}

resource "aws_security_group" "app_sg" {
name = "App SG"
vpc_id = module.network.vpc_id
name = "App SG"
vpc_id = module.network.vpc_id


dynamic "ingress" {
Expand All @@ -50,10 +46,10 @@ resource "aws_security_group" "app_sg" {
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

Expand Down Expand Up @@ -82,18 +78,19 @@ resource "aws_instance" "EC2-Ubuntu" {
aws_instance.testLinux
]
count = 2
ami = "ami-0851b76e8b1bce90b"
ami = data.aws_ami.ubuntu.image_id
instance_type = "t2.micro"
key_name = var.keyname

user_data = data.template_file.apache_install.rendered

user_data = base64encode(templatefile("${path.module}/apache_install.tpl", {}))

network_interface {
network_interface_id = aws_network_interface.ftd_app[count.index].id
device_index = 0
}

tags = {
Name = "Ec2-Ubuntu${count.index+1}"
Name = "Ec2-Ubuntu${count.index + 1}"
}
}

Expand All @@ -114,19 +111,19 @@ resource "aws_lb" "app-lb" {
}

resource "aws_lb_listener" "app_listener" {
for_each = { for k, v in var.internal_listener_ports : k => v }
for_each = { for k, v in var.internal_listener_ports : k => v }
load_balancer_arn = aws_lb.app-lb.arn
port = each.value.port
protocol = each.value.protocol
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.app_front_end[each.key].arn
}
}
}

resource "aws_lb_target_group" "app_front_end" {
#for_each = var.create == "both" || var.create == "internal" ? var.internal_listener_ports : []
for_each = { for k, v in var.internal_listener_ports : k => v }
for_each = { for k, v in var.internal_listener_ports : k => v }
name = tostring("fe2-1-${each.key}")
port = each.value.port
protocol = each.value.protocol
Expand Down Expand Up @@ -157,4 +154,4 @@ output "app_subnet" {

output "app_interface_ip" {
value = aws_network_interface.ftd_app.*.private_ip_list
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
data "template_file" "bastion_install" {
template = file("${path.module}/bastion_install.tpl")
}

data "aws_availability_zones" "available" {}

resource "aws_subnet" "bastion_subnet" {
vpc_id = module.network.vpc_id
cidr_block = var.bastion_subnet_cidr
availability_zone = data.aws_availability_zones.available.names[0]
vpc_id = module.network.vpc_id
cidr_block = var.bastion_subnet_cidr
availability_zone = data.aws_availability_zones.available.names[0]
map_public_ip_on_launch = true

tags = merge({
Expand All @@ -16,9 +12,9 @@ resource "aws_subnet" "bastion_subnet" {
}

resource "aws_network_interface" "bastion_interface" {
description = "bastion-interface"
subnet_id = aws_subnet.bastion_subnet.id
private_ips = [var.bastion_ip]
description = "bastion-interface"
subnet_id = aws_subnet.bastion_subnet.id
private_ips = [var.bastion_ip]
}

resource "aws_network_interface_sg_attachment" "bastion_attachment" {
Expand Down Expand Up @@ -46,10 +42,10 @@ resource "aws_route" "bastion_default_route" {
}

resource "aws_instance" "testLinux" {
ami = "ami-0851b76e8b1bce90b"
ami = data.aws_ami.ubuntu.image_id
instance_type = "t2.micro"
key_name = var.keyname
user_data = data.template_file.bastion_install.rendered
key_name = var.keyname
user_data = base64encode(templatefile("${path.module}/bastion_install.tfpl", {}))
network_interface {
network_interface_id = aws_network_interface.bastion_interface.id
device_index = 0
Expand All @@ -61,8 +57,8 @@ resource "aws_instance" "testLinux" {
}

resource "aws_security_group" "bastion_sg" {
name = "Bastion SG"
vpc_id = module.network.vpc_id
name = "Bastion SG"
vpc_id = module.network.vpc_id


dynamic "ingress" {
Expand All @@ -77,10 +73,10 @@ resource "aws_security_group" "bastion_sg" {
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ sudo wget --input-file /todownload.txt
sudo wget --input-file /todownload1.txt
cd ..
tar -czvf archive.tar.gz /web
python3 -m http.server --bind 0.0.0.0 9000
python3 -m http.server --bind 0.0.0.0 9000
16 changes: 16 additions & 0 deletions AWS_Workshop/AWS_Workshop_Code/Working_Directory/Resources/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data "aws_ami" "ubuntu" {

most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}

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

owners = ["099720109477"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ module "instance" {
ftd_inside_interface = module.network.inside_interface
ftd_diag_interface = module.network.diag_interface
fmcmgmt_interface = module.network.fmcmgmt_interface
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,121 +6,121 @@
#############################################################
aws_access_key = ""
aws_secret_key = ""
region = "ap-south-1"
region = "ap-south-1"

############################################################
#Define New VPC in a specific Region and Avilability Zone
#############################################################
vpc_name = "IAC-VPC"
vpc_cidr = ""
vpc_name = "IAC-VPC"
vpc_cidr = "10.0.0.0/16"
create_igw = false
# Generate the key if you want to login thru the key
keyname = "lx1"
keyname = "lx1"
instances_per_az = 1
availability_zone_count = 2

##################################################################################
#Define CIDR, Subnets for managment and three for Inside, Outisde and Diag
###################################################################################

mgmt_subnet_cidr = ["10.0.1.0/24","10.0.10.0/24"]
outside_subnet_cidr = ["10.0.2.0/24","10.0.20.0/24"]
inside_subnet_cidr = ["10.0.3.0/24","10.0.30.0/24"]
diag_subnet_cidr = ["10.0.4.0/24","10.0.40.0/24"]
app_subnet_cidr = ["10.0.5.0/24","10.0.50.0/24"]
mgmt_subnet_cidr = ["10.0.1.0/24", "10.0.10.0/24"]
outside_subnet_cidr = ["10.0.2.0/24", "10.0.20.0/24"]
inside_subnet_cidr = ["10.0.3.0/24", "10.0.30.0/24"]
diag_subnet_cidr = ["10.0.4.0/24", "10.0.40.0/24"]
app_subnet_cidr = ["10.0.5.0/24", "10.0.50.0/24"]
bastion_subnet_cidr = "10.0.6.0/24"

ftd_mgmt_ip = ["10.0.1.10","10.0.10.10"]
ftd_outside_ip = ["10.0.2.10","10.0.20.10"]
ftd_inside_ip = ["10.0.3.10","10.0.30.10"]
ftd_diag_ip = ["10.0.4.10","10.0.40.10"]
ftd_app_ip = ["10.0.5.10","10.0.50.10"]
bastion_ip = "10.0.6.10"
fmc_ip = "10.0.1.50"
ftd_mgmt_ip = ["10.0.1.10", "10.0.10.10"]
ftd_outside_ip = ["10.0.2.10", "10.0.20.10"]
ftd_inside_ip = ["10.0.3.10", "10.0.30.10"]
ftd_diag_ip = ["10.0.4.10", "10.0.40.10"]
ftd_app_ip = ["10.0.5.10", "10.0.50.10"]
bastion_ip = "10.0.6.10"
fmc_ip = "10.0.1.50"

inside_subnet_name = ["inside1","inside2"]
outside_subnet_name = ["outside1","outside2"]
mgmt_subnet_name = ["mgmt1","mgmt2"]
diag_subnet_name = ["diag1","diag2"]
app_subnet_name = ["app1","app2"]
inside_subnet_name = ["inside1", "inside2"]
outside_subnet_name = ["outside1", "outside2"]
mgmt_subnet_name = ["mgmt1", "mgmt2"]
diag_subnet_name = ["diag1", "diag2"]
app_subnet_name = ["app1", "app2"]
bastion_subnet_name = "bastion"

create = "external"

outside_interface_sg = [
{
from_port = 80
protocol = "TCP"
to_port = 80
cidr_blocks = ["10.0.2.0/24","10.0.20.0/24"]
},
{
from_port = 22
protocol = "TCP"
to_port = 22
cidr_blocks = ["10.0.2.0/24","10.0.20.0/24"]
}
{
from_port = 80
protocol = "TCP"
to_port = 80
cidr_blocks = ["10.0.2.0/24", "10.0.20.0/24"]
},
{
from_port = 22
protocol = "TCP"
to_port = 22
cidr_blocks = ["10.0.2.0/24", "10.0.20.0/24"]
}
]

inside_interface_sg = [
{
from_port = 80
protocol = "TCP"
to_port = 80
cidr_blocks = ["10.0.5.10/32","10.0.50.10/32"]
}
{
from_port = 80
protocol = "TCP"
to_port = 80
cidr_blocks = ["10.0.5.10/32", "10.0.50.10/32"]
}
]

mgmt_interface_sg = [
{
from_port = 8305
protocol = "TCP"
to_port = 8305
cidr_blocks = ["10.0.1.50/32"]
}
{
from_port = 8305
protocol = "TCP"
to_port = 8305
cidr_blocks = ["10.0.1.50/32"]
}
]

fmc_mgmt_interface_sg = [
{
from_port = 443
protocol = "TCP"
to_port = 443
cidr_blocks = ["0.0.0.0/0"]
},
{
from_port = 8305
protocol = "TCP"
to_port = 8305
cidr_blocks = ["10.0.1.10/32","10.0.10.10/32"]
}
{
from_port = 443
protocol = "TCP"
to_port = 443
cidr_blocks = ["0.0.0.0/0"]
},
{
from_port = 8305
protocol = "TCP"
to_port = 8305
cidr_blocks = ["10.0.1.10/32", "10.0.10.10/32"]
}
]

bastion_interface_sg = [
{
from_port = 80
protocol = "TCP"
to_port = 80
cidr_blocks = ["10.0.5.10/32","10.0.50.10/32"]
},
{
from_port = 22
protocol = "TCP"
to_port = 22
cidr_blocks = ["10.0.5.10/32","10.0.50.10/32"]
}
{
from_port = 80
protocol = "TCP"
to_port = 80
cidr_blocks = ["10.0.5.10/32", "10.0.50.10/32"]
},
{
from_port = 22
protocol = "TCP"
to_port = 22
cidr_blocks = ["10.0.5.10/32", "10.0.50.10/32"]
}
]

app_interface_sg = [
{
from_port = 80
protocol = "TCP"
to_port = 80
cidr_blocks = ["10.0.5.100/32","10.0.50.100/32"]
},
{
from_port = 22
protocol = "TCP"
to_port = 22
cidr_blocks = ["10.0.5.100/32","10.0.50.100/32"]
}
]
{
from_port = 80
protocol = "TCP"
to_port = 80
cidr_blocks = ["10.0.5.100/32", "10.0.50.100/32"]
},
{
from_port = 22
protocol = "TCP"
to_port = 22
cidr_blocks = ["10.0.5.100/32", "10.0.50.100/32"]
}
]
Loading