This file contains hidden or 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
| # Private Subnet | |
| resource "aws_subnet" "private_subnet" { | |
| count = 2 | |
| cidr_block = "${var.private_cidrs[count.index]}" | |
| vpc_id = "${aws_vpc.main.id}" | |
| availability_zone = "${data.aws_availability_zones.available.names[count.index]}" | |
| tags { | |
| Name = "my-test-private-subnet.${count.index + 1}" | |
| } |
This file contains hidden or 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
| # Public Subnet | |
| resource "aws_subnet" "public_subnet" { | |
| count = 2 | |
| cidr_block = "${var.public_cidrs[count.index]}" | |
| vpc_id = "${aws_vpc.main.id}" | |
| map_public_ip_on_launch = true | |
| availability_zone = "${data.aws_availability_zones.available.names[count.index]}" | |
| tags { | |
| Name = "my-test-public-subnet.${count.index + 1}" |
This file contains hidden or 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
| # Private Route Table | |
| resource "aws_default_route_table" "private_route" { | |
| default_route_table_id = "${aws_vpc.main.default_route_table_id}" | |
| tags { | |
| Name = "my-private-route-table" | |
| } | |
| } |
This file contains hidden or 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
| # Public Route Table | |
| resource "aws_route_table" "public_route" { | |
| vpc_id = "${aws_vpc.main.id}" | |
| route { | |
| cidr_block = "0.0.0.0/0" | |
| gateway_id = "${aws_internet_gateway.gw.id}" | |
| } |
This file contains hidden or 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
| # Creating Internet Gateway | |
| resource "aws_internet_gateway" "gw" { | |
| vpc_id = "${aws_vpc.main.id}" | |
| tags { | |
| Name = "my-test-igw" | |
| } | |
| } |
This file contains hidden or 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
| # VPC Creation | |
| resource "aws_vpc" "main" { | |
| cidr_block = "${var.vpc_cidr}" | |
| enable_dns_hostnames = true | |
| enable_dns_support = true | |
| tags { | |
| Name = "my-test-vpc" | |
| } |
This file contains hidden or 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
| # Query all avilable Availibility Zone | |
| data "aws_availability_zones" "available" {} |
This file contains hidden or 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" "test_instance" { | |
| count = "${var.instance_count}" | |
| ami = "${data.aws_ami.centos.id}" | |
| instance_type = "${var.instance_type}" | |
| key_name = "${aws_key_pair.mytest-key.id}" | |
| vpc_security_group_ids = ["${var.security_group}"] | |
| subnet_id = "${element(var.subnet_mask, count.index )}" | |
| user_data = "${data.template_file.user-init.rendered}" | |
| tags { |
This file contains hidden or 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
| #!/bin/bash | |
| yum -y install httpd | |
| service httpd start | |
| chkconfig httpd on |
This file contains hidden or 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
| data "template_file" "user-init" { | |
| template = "${file("${path.module}/userdata.tpl")}" | |
| } |