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