Skip to content

Instantly share code, notes, and snippets.

@sizovs
Last active April 12, 2016 21:41
Show Gist options
  • Save sizovs/13d7d2f0a7a75467d9d7903d016e0629 to your computer and use it in GitHub Desktop.
Save sizovs/13d7d2f0a7a75467d9d7903d016e0629 to your computer and use it in GitHub Desktop.
variable "public_key_path" {
default = "~/.ssh/terraform.pub"
}
resource "aws_key_pair" "auth" {
key_name = "terraform-key"
public_key = "${file(var.public_key_path)}"
}
resource "aws_security_group" "default" {
name = "uber-securiy"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
variable "webappAvailabilityZones" {
default = {
"0" = "us-east-1a"
"1" = "us-east-1b"
"2" = "us-east-1b"
}
}
resource "aws_instance" "webapp" {
ami = "ami-2c657646"
instance_type = "t1.micro"
key_name = "${aws_key_pair.auth.id}"
vpc_security_group_ids = ["${aws_security_group.default.id}"]
provisioner "local-exec" {
command = "echo ${self.public_ip} > publicIp.txt"
}
count = 3
availability_zone = "${lookup(var.webappAvailabilityZones, count.index)}"
}
resource "aws_elb" "web" {
instances = ["${aws_instance.webapp.*.id}"]
availability_zones = ["${values(var.webappAvailabilityZones)}"]
listener {
instance_port = 8080
instance_protocol = "http"
lb_port = 8080
lb_protocol = "http"
}
}
output "webAppDns" {
value = "${aws_elb.web.dns_name}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment