Skip to content

Instantly share code, notes, and snippets.

View 100daysofdevops's full-sized avatar
🎯
Focusing

100daysofdevops

🎯
Focusing
View GitHub Profile
# 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}"
}
# 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}"
# 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"
}
}
# 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}"
}
# Creating Internet Gateway
resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.main.id}"
tags {
Name = "my-test-igw"
}
}
# VPC Creation
resource "aws_vpc" "main" {
cidr_block = "${var.vpc_cidr}"
enable_dns_hostnames = true
enable_dns_support = true
tags {
Name = "my-test-vpc"
}
# Query all avilable Availibility Zone
data "aws_availability_zones" "available" {}
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 {
#!/bin/bash
yum -y install httpd
service httpd start
chkconfig httpd on
data "template_file" "user-init" {
template = "${file("${path.module}/userdata.tpl")}"
}