Created
October 5, 2015 13:43
-
-
Save ryane/cc4b400df6a269c1868e 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
variable aws_access_key {} | |
variable aws_secret_key {} | |
variable ssh_key { default = "~/.ssh/id_rsa.pub" } | |
variable ssl_cert_file { default = "./cert.pem" } | |
variable ssl_key_file { default = "./key.pem" } | |
provider "aws" { | |
access_key = "${var.aws_access_key}" | |
secret_key = "${var.aws_secret_key}" | |
region = "us-west-1" | |
} | |
resource "aws_key_pair" "keypair" { | |
key_name = "test-key" | |
public_key = "${file(var.ssh_key)}" | |
} | |
resource "aws_vpc" "main" { | |
cidr_block = "10.0.0.0/16" | |
enable_dns_hostnames = true | |
} | |
resource "aws_subnet" "main" { | |
vpc_id = "${aws_vpc.main.id}" | |
cidr_block = "10.0.0.0/16" | |
availability_zone = "us-west-1c" | |
} | |
resource "aws_internet_gateway" "main" { | |
vpc_id = "${aws_vpc.main.id}" | |
} | |
resource "aws_route_table" "main" { | |
vpc_id = "${aws_vpc.main.id}" | |
route { | |
cidr_block = "0.0.0.0/0" | |
gateway_id = "${aws_internet_gateway.main.id}" | |
} | |
} | |
resource "aws_main_route_table_association" "main" { | |
vpc_id = "${aws_vpc.main.id}" | |
route_table_id = "${aws_route_table.main.id}" | |
} | |
resource "aws_security_group" "ui" { | |
name = "test-ui" | |
description = "Allow inbound traffic for UI" | |
vpc_id="${aws_vpc.main.id}" | |
ingress { # HTTP | |
from_port = 80 | |
to_port = 80 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { # HTTPS | |
from_port = 443 | |
to_port = 443 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
} | |
resource "aws_instance" "test-instances" { | |
ami = "ami-6bcfc42e" | |
instance_type = "m3.xlarge" | |
count = 3 | |
vpc_security_group_ids = [ | |
"${aws_vpc.main.default_security_group_id}" | |
] | |
key_name = "${aws_key_pair.keypair.key_name}" | |
associate_public_ip_address=true | |
subnet_id = "${aws_subnet.main.id}" | |
root_block_device { | |
delete_on_termination = true | |
} | |
} | |
resource "aws_iam_server_certificate" "elb_cert" { | |
name = "test-elb-certificate" | |
certificate_body = "${file(var.ssl_cert_file)}" | |
private_key = "${file(var.ssl_key_file)}" | |
} | |
resource "aws_elb" "test-elb" { | |
name = "test-elb" | |
cross_zone_load_balancing = true | |
idle_timeout = 400 | |
connection_draining = true | |
connection_draining_timeout = 400 | |
subnets = ["${aws_subnet.main.id}"] | |
security_groups = [ | |
"${aws_security_group.ui.id}", | |
"${aws_vpc.main.default_security_group_id}" | |
] | |
instances = ["${aws_instance.test-instances.*.id}"] | |
listener { | |
instance_port = 80 | |
instance_protocol = "http" | |
lb_port = 80 | |
lb_protocol = "http" | |
} | |
listener { | |
instance_port = 443 | |
instance_protocol = "https" | |
lb_port = 443 | |
lb_protocol = "https" | |
ssl_certificate_id = "${aws_iam_server_certificate.elb_cert.arn}" | |
} | |
health_check { | |
healthy_threshold = 10 | |
unhealthy_threshold = 2 | |
timeout = 3 | |
target = "TCP:80" | |
interval = 30 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment