Last active
January 30, 2020 08:35
-
-
Save BacancyPratik/92298f928e8d6cd475eef06fa59feb9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_instance" "gate" { | |
ami = "${var.nat_ami}" | |
instance_type = "t2.small" | |
key_name = "${var.aws_key_name}" | |
vpc_security_group_ids = ["${aws_security_group.gate.id}"] | |
subnet_id = "${aws_subnet.eu-west-1-public.id}" | |
associate_public_ip_address = true | |
source_dest_check = false | |
tags { | |
Name = "VPC NAT" | |
} | |
} | |
resource "aws_instance" "web-instance" { | |
ami = "${lookup(var.amis, var.aws_region)}" | |
instance_type = "t2.small" | |
key_name = "${var.aws_key_name}" | |
vpc_security_group_ids = ["${aws_security_group.web.id}"] | |
subnet_id = "${aws_subnet.eu-west-1-public.id}" | |
associate_public_ip_address = true | |
source_dest_check = false | |
tags { | |
Name = "Web Server" | |
} | |
} | |
resource "aws_instance" "db-instance" { | |
ami = "${lookup(var.amis, var.aws_region)}" | |
instance_type = "t2.small" | |
key_name = "${var.aws_key_name}" | |
vpc_security_group_ids = ["${aws_security_group.db.id}"] | |
subnet_id = "${aws_subnet.eu-west-1-private.id}" | |
source_dest_check = false | |
tags { | |
Name = "DB Server" | |
} | |
} | |
resource "aws_vpc" "main_vpc" { | |
cidr_block = "${var.vpc_cidr}" | |
enable_dns_hostnames = true | |
tags { | |
Name = "bacancy-blog-vpc" | |
} | |
} | |
resource "aws_eip" "gate" { | |
instance = "${aws_instance.gate.id}" | |
vpc = true | |
} | |
resource "aws_eip" "web-instance" { | |
instance = "${aws_instance.web-instance.id}" | |
vpc = true | |
} | |
resource "aws_route_table" "eu-west-1-public" { | |
vpc_id = "${aws_vpc.main_vpc.id}" | |
route { | |
cidr_block = "0.0.0.0/0" | |
gateway_id = "${aws_internet_gateway.ig-main.id}" | |
} | |
tags { | |
Name = "Public Subnet" | |
} | |
} | |
resource "aws_route_table_association" "eu-west-1-public" { | |
subnet_id = "${aws_subnet.eu-west-1-public.id}" | |
route_table_id = "${aws_route_table.eu-west-1-public.id}" | |
} | |
resource "aws_route_table" "eu-west-1-private" { | |
vpc_id = "${aws_vpc.main_vpc.id}" | |
route { | |
cidr_block = "0.0.0.0/0" | |
instance_id = "${aws_instance.gate.id}" | |
} | |
tags { | |
Name = "Private Subnet" | |
} | |
} | |
resource "aws_route_table_association" "eu-west-1-private" { | |
subnet_id = "${aws_subnet.eu-west-1-private.id}" | |
route_table_id = "${aws_route_table.eu-west-1-private.id}" | |
} | |
resource "aws_subnet" "eu-west-1-public" { | |
vpc_id = "${aws_vpc.main_vpc.id}" | |
cidr_block = "${var.public_subnet_cidr}" | |
tags { | |
Name = "Public Subnet" | |
} | |
} | |
resource "aws_subnet" "eu-west-1-private" { | |
vpc_id = "${aws_vpc.main_vpc.id}" | |
cidr_block = "${var.private_subnet_cidr}" | |
tags { | |
Name = "Private Subnet" | |
} | |
} | |
resource "aws_internet_gateway" "ig-main" { | |
vpc_id = "${aws_vpc.main_vpc.id}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment