Terraform network project sample code
Windows Server (AWS EC2 instance).
Palo Alto Firewall (AWS EC2 instance).
FortiGate Firewall (AWS EC2 instance).
Server Router (AWS EC2 instance).
VPC (AWS Virtual Private Cloud).
IPsec Tunnel between Palo Alto and FortiGate.
VPN Gateway for remote access.
******************************Terraform Code of AWS Project*************************
==>> Create Region
provider "aws" {
region = "us-west-2" # Change this to your desired region
}
==>> Create Resource and CIDR Block
resource "aws_vpc" "my_vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
}
==>> Create Sub CIDR Block
resource "aws_subnet" "public_subnet" {
vpc_id = aws_vpc.my_vpc.id
cidr_block = "10.0.1.0/24"
}
# Define additional subnets as needed (e.g., private subnet)
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.my_vpc.id
}
resource "aws_route_table" "public_route" {
vpc_id = aws_vpc.my_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
# Associate the public route table with the public subnet
resource "aws_route_table_association" "public_assoc" {
subnet_id = aws_subnet.public_subnet.id
route_table_id = aws_route_table.public_route.id
}
}
resource "aws_security_group" "windows_sg" {
name_prefix = "windows-sg-"
vpc_id = aws_vpc.my_vpc.id
# Define inbound and outbound rules as needed
}
# Define additional security groups for other instances (e.g., Palo Alto, FortiGate)
resource "aws_instance" "windows_server" {
ami = "ami-xxxxxxxxxxxxxxxxx" # Windows Server AMI ID
instance_type = "t2.micro"
subnet_id = aws_subnet.public_subnet.id
security_groups = [
aws_security_group.windows_sg.id,
]
# Other configurations such as IAM role, user_data, etc.
}
# Define other EC2 instances for Palo Alto, FortiGate, and Server Router
# Define the AWS VPN Gateway
resource "aws_vpn_gateway" "vpn_gw" {
vpc_id = aws_vpc.my_vpc.id
}
# Define the Customer Gateway for Palo Alto
resource "aws_customer_gateway" "palo_alto_cg" {
bgp_asn = 65000 # Replace with your Palo Alto BGP ASN
ip_address = "x.x.x.x" # Replace with your Palo Alto's public IP
}
# Define the VPN Connection for Palo Alto
resource "aws_vpn_connection" "palo_alto_vpn" {
customer_gateway_id = aws_customer_gateway.palo_alto_cg.id
vpn_gateway_id = aws_vpn_gateway.vpn_gw.id
type = "ipsec.1"
static_routes_only = true # Set to false if you want dynamic routing
tunnel1 {
pre_shared_key = "your_pre_shared_key_here"
# Other tunnel configurations as needed
}
tunnel2 {
pre_shared_key = "your_pre_shared_key_here"
# Other tunnel configurations as needed
}
}
# Define similar resources for FortiGate VPN Connection