Created
July 8, 2015 07:21
-
-
Save suizman/8b356041806a02edb8f3 to your computer and use it in GitHub Desktop.
aws_interfaces bug terraform
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
# Create infrastructure in AWS | |
provider "aws" { | |
access_key = "${var.aws_access_key}" | |
secret_key = "${var.aws_secret_key}" | |
region = "${var.aws_region}" | |
} | |
resource "aws_vpc" "test" { | |
cidr_block = "172.18.0.0/16" | |
tags { | |
Name = "${var.test_name}" | |
Greenbox = "${var.test_name}" | |
} | |
} | |
resource "aws_internet_gateway" "test" { | |
vpc_id = "${aws_vpc.test.id}" | |
tags { | |
Name = "${var.test_name}" | |
Greenbox = "${var.test_name}" | |
} | |
} | |
# Create new route table and connect it to the rest of Test | |
resource "aws_route_table" "test" { | |
vpc_id = "${aws_vpc.test.id}" | |
route { | |
cidr_block = "0.0.0.0/0" | |
gateway_id = "${aws_internet_gateway.test.id}" | |
} | |
tags { | |
Name = "${var.test_name}" | |
Greenbox = "${var.test_name}" | |
} | |
} | |
# Make the new route table default | |
resource "aws_main_route_table_association" "test" { | |
vpc_id = "${aws_vpc.test.id}" | |
route_table_id = "${aws_route_table.test.id}" | |
} | |
resource "aws_subnet" "management" { | |
vpc_id = "${aws_vpc.test.id}" | |
availability_zone = "${var.aws_zone}" | |
cidr_block = "172.18.0.0/24" | |
map_public_ip_on_launch = "false" | |
tags { | |
Name = "management-${var.test_name}" | |
Greenbox = "${var.test_name}" | |
} | |
} | |
resource "aws_subnet" "service" { | |
vpc_id = "${aws_vpc.test.id}" | |
availability_zone = "${var.aws_zone}" | |
cidr_block = "172.18.1.0/24" | |
map_public_ip_on_launch = "false" | |
tags { | |
Name = "service-${var.test_name}" | |
Greenbox = "${var.test_name}" | |
} | |
} | |
resource "aws_subnet" "storage_service" { | |
vpc_id = "${aws_vpc.test.id}" | |
availability_zone = "${var.aws_zone}" | |
cidr_block = "172.18.2.0/24" | |
map_public_ip_on_launch = "false" | |
tags { | |
Name = "storage_replica-${var.test_name}" | |
Greenbox = "${var.test_name}" | |
} | |
} | |
resource "aws_subnet" "storage_replica" { | |
vpc_id = "${aws_vpc.test.id}" | |
availability_zone = "${var.aws_zone}" | |
cidr_block = "172.18.3.0/24" | |
map_public_ip_on_launch = "false" | |
tags { | |
Name = "storage_replica-${var.test_name}" | |
Greenbox = "${var.test_name}" | |
} | |
} | |
resource "aws_security_group" "test" { | |
name = "sg_${var.test_name}_default" | |
description = "The default security group for ${var.test_name}" | |
vpc_id = "${aws_vpc.test.id}" | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
from_port = -1 | |
to_port = -1 | |
protocol = "icmp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { | |
from_port = 0 | |
to_port = 0 | |
self = "true" | |
protocol = "-1" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
tags { | |
Name = "sg_${var.test_name}_default" | |
Greenbox = "${var.test_name}" | |
} | |
} |
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
# proxy + DNS | |
resource "aws_security_group" "proxy" { | |
name = "sg_${var.test_name}_proxy" | |
description = "The default security group for proxy" | |
vpc_id = "${aws_vpc.test.id}" | |
# DNS >>> | |
ingress { | |
from_port = 53 | |
to_port = 53 | |
protocol = "tcp" | |
cidr_blocks = ["${aws_vpc.test.cidr_block}"] | |
} | |
ingress { | |
from_port = 53 | |
to_port = 53 | |
protocol = "udp" | |
cidr_blocks = ["${aws_vpc.test.cidr_block}"] | |
} | |
# HTTP/S >>> | |
ingress { | |
from_port = 80 | |
to_port = 80 | |
protocol = "tcp" | |
cidr_blocks = ["${aws_vpc.test.cidr_block}"] | |
} | |
ingress { | |
from_port = 443 | |
to_port = 443 | |
protocol = "tcp" | |
cidr_blocks = ["${aws_vpc.test.cidr_block}"] | |
} | |
# Consul >>> | |
ingress { | |
from_port = 8300 | |
to_port = 8302 | |
protocol = "tcp" | |
cidr_blocks = ["${aws_vpc.test.cidr_block}"] | |
} | |
ingress { | |
from_port = 8400 | |
to_port = 8400 | |
protocol = "tcp" | |
cidr_blocks = ["${aws_vpc.test.cidr_block}"] | |
} | |
ingress { | |
from_port = 8500 | |
to_port = 8500 | |
protocol = "tcp" | |
cidr_blocks = ["${aws_vpc.test.cidr_block}"] | |
} | |
ingress { | |
from_port = 8600 | |
to_port = 8600 | |
protocol = "tcp" | |
cidr_blocks = ["${aws_vpc.test.cidr_block}"] | |
} | |
# Etcd >>> | |
ingress { | |
from_port = 2380 | |
to_port = 2380 | |
protocol = "tcp" | |
cidr_blocks = ["${aws_vpc.test.cidr_block}"] | |
} | |
tags { | |
Name = "sg_${var.test_name}_proxy" | |
Greenbox = "${var.test_name}" | |
} | |
} | |
resource "aws_instance" "proxy" { | |
ami = "${var.aws_ami.base}" | |
count = "2" | |
instance_type = "t2.micro" # m3.medium | |
availability_zone = "${var.aws_zone}" | |
subnet_id = "${aws_subnet.management.id}" | |
vpc_security_group_ids = [ "${aws_security_group.test.id}", "${aws_security_group.proxy.id}" ] | |
associate_public_ip_address = "true" | |
source_dest_check = "false" | |
tags { | |
Name = "${var.test_name}-proxy${count.index}" | |
Hostname = "proxy${count.index}" | |
Greenbox = "${var.test_name}" | |
} | |
} | |
resource "aws_network_interface" "proxy0-service" { | |
subnet_id = "${aws_subnet.service.id}" | |
security_groups = [ "${aws_security_group.proxy.id}" ] | |
attachment { | |
instance = "${aws_instance.proxy.0.id}" | |
device_index = 1 | |
} | |
tags { | |
Name = "${var.test_name}-proxy0-service" | |
Greenbox = "${var.test_name}" | |
} | |
} | |
resource "aws_network_interface" "proxy1-service" { | |
subnet_id = "${aws_subnet.service.id}" | |
security_groups = [ "${aws_security_group.proxy.id}" ] | |
attachment { | |
instance = "${aws_instance.proxy.1.id}" | |
device_index = 1 | |
} | |
tags { | |
Name = "${var.test_name}-proxy1-service" | |
Greenbox = "${var.test_name}" | |
} | |
} |
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
### Requirements | |
# AWS account credentials [ The Environment Variables below must be exported] | |
# export TF_VAR_aws_access_key="AKXXXXX" | |
# export TF_VAR_aws_secret_key="AeXXXXX" | |
# export TF_VAR_aws_owner_id="NaNaNaNa" | |
# export TF_VAR_ssh_key="~/.ssh/id_rsa" | |
### Test Global vars | |
variable "test_name" { | |
default = "test-vpc" | |
description = "The Test name [version]" | |
} | |
variable "Test_search" { | |
default = "Test1.mydomain.com" | |
description = "The Test search name" | |
} | |
variable "ssh_user" { | |
default = { | |
centos = "centos" | |
ubuntu = "ubuntu" | |
debian = "admin" | |
} | |
} | |
### AWS Variables | |
variable "aws_access_key" { | |
} | |
variable "aws_secret_key" { | |
} | |
# AWS VPC settings | |
variable "aws_vpc" { | |
default = "Test1" | |
description = "The VPC name" | |
} | |
# AWS VPC Gateway settings | |
variable "aws_inter_gateway" { | |
default = "Test1" | |
description = "The Internet Gateway name" | |
} | |
# AWS Availability Zones settings | |
variable "aws_zone" { | |
default = "eu-west-1a" | |
description = "Availability AWS EU Zones " | |
} | |
# AWS Availability Zones settings | |
variable "aws_instance_size" { | |
default = { | |
consul = "t2.micro" | |
mesos = "t2.micro" | |
dockerhost = "t2.micro" | |
kafka = "t2.micro" | |
mongot1 = "t2.micro" | |
mongot2 = "t2.micro" | |
redis = "t2.micro" | |
helix = "t2.micro" | |
description = "AWS instance size" | |
} | |
} | |
# AWS Region settings | |
variable "aws_region" { | |
default = "eu-west-1" | |
description = "The Regions to use" | |
} | |
# AWS Security groups | |
variable "aws_sg" { | |
default = "sg_Test1" | |
description = "The Security groups to use" | |
} | |
# AWS AMI to use | |
variable "aws_ami" { | |
default = { | |
base = "ami-20410357" | |
description = "The AMI to use"} | |
} | |
# AWS VPC settings | |
variable "aws_vpc" { | |
default = "Test1" | |
description = "The VPC name" | |
} | |
# AWS VPC Gateway settings | |
variable "aws_inter_gateway" { | |
default = "Test1" | |
description = "The Internet Gateway name" | |
} | |
# AWS Availability Zones settings | |
variable "aws_zone" { | |
default = "eu-west-1a" | |
description = "Availability AWS EU Zones " | |
} | |
# AWS Availability Zones settings | |
variable "aws_instance_size" { | |
default = { | |
consul = "t2.micro" | |
mesos = "t2.micro" | |
dockerhost = "t2.micro" | |
kafka = "t2.micro" | |
mongot1 = "t2.micro" | |
mongot2 = "t2.micro" | |
redis = "t2.micro" | |
helix = "t2.micro" | |
description = "AWS instance size" | |
} | |
} | |
# AWS Region settings | |
variable "aws_region" { | |
default = "eu-west-1" | |
description = "The Regions to use" | |
} | |
# AWS Security groups | |
variable "aws_sg" { | |
default = "sg_Test1" | |
description = "The Security groups to use" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment