github.com/leowmjw/otto@v0.2.1-0.20160126165905-6400716cf085/builtin/app/docker-external/data/aws-simple/deploy/main.tf.tpl (about) 1 # Generated by Otto, do not edit manually 2 3 variable "infra_id" {} 4 variable "aws_access_key" {} 5 variable "aws_secret_key" {} 6 variable "aws_region" {} 7 variable "key_name" {} 8 9 variable "ami" { default = "ami-21630d44" } 10 variable "instance_type" { default = "t2.micro" } 11 variable "subnet_public" {} 12 variable "vpc_cidr" {} 13 variable "vpc_id" {} 14 15 provider "aws" { 16 access_key = "${var.aws_access_key}" 17 secret_key = "${var.aws_secret_key}" 18 region = "${var.aws_region}" 19 } 20 21 resource "aws_security_group" "app" { 22 name = "{{ name }}-${var.infra_id}" 23 vpc_id = "${var.vpc_id}" 24 25 ingress { 26 protocol = -1 27 from_port = 0 28 to_port = 0 29 cidr_blocks = ["${var.vpc_cidr}"] 30 } 31 32 ingress { 33 protocol = "tcp" 34 from_port = 22 35 to_port = 22 36 cidr_blocks = ["0.0.0.0/0"] 37 } 38 39 egress { 40 protocol = -1 41 from_port = 0 42 to_port = 0 43 cidr_blocks = ["0.0.0.0/0"] 44 } 45 } 46 47 # Deploy a set of instances 48 resource "aws_instance" "app" { 49 ami = "${var.ami}" 50 instance_type = "${var.instance_type}" 51 subnet_id = "${var.subnet_public}" 52 key_name = "${var.key_name}" 53 user_data = "${file("${path.module}/cloud-init.sh")}" 54 55 vpc_security_group_ids = ["${aws_security_group.app.id}"] 56 57 tags { 58 Name = "{{ name }}" 59 } 60 61 connection { 62 user = "ubuntu" 63 host = "${self.public_ip}" 64 } 65 66 # Wait for cloud-init (ensures instance is fully booted before moving on) 67 provisioner "remote-exec" { 68 inline = ["while sudo pkill -0 cloud-init 2>/dev/null; do sleep 2; done"] 69 } 70 71 {% for dir in foundation_dirs.build %} 72 # Foundation {{ forloop.Counter }} (build) 73 provisioner "remote-exec" { 74 inline = ["mkdir -p /tmp/otto/foundation-{{ forloop.Counter }}"] 75 } 76 77 provisioner "file" { 78 source = "{{ dir }}/" 79 destination = "/tmp/otto/foundation-{{ forloop.Counter }}" 80 } 81 82 provisioner "remote-exec" { 83 inline = ["cd /tmp/otto/foundation-{{ forloop.Counter}} && bash ./main.sh"] 84 } 85 {% endfor %} 86 87 {% for dir in foundation_dirs.deploy %} 88 # Foundation {{ forloop.Counter }} (deploy) 89 provisioner "remote-exec" { 90 inline = ["mkdir -p /tmp/otto/foundation-deploy-{{ forloop.Counter }}"] 91 } 92 93 provisioner "file" { 94 source = "{{ dir }}/" 95 destination = "/tmp/otto/foundation-deploy-{{ forloop.Counter }}" 96 } 97 98 provisioner "remote-exec" { 99 inline = ["cd /tmp/otto/foundation-deploy-{{ forloop.Counter}} && bash ./main.sh"] 100 } 101 {% endfor %} 102 103 # Remove any temporary directories we made from foundations (if any) 104 provisioner "remote-exec" { 105 inline = ["rm -rf /tmp/otto"] 106 } 107 } 108 109 output "ip" { 110 value = "${aws_instance.app.public_ip}" 111 }