github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/builtin/app/ruby/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" {}
    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  provider "aws" {
    17    access_key = "${var.aws_access_key}"
    18    secret_key = "${var.aws_secret_key}"
    19    region     = "${var.aws_region}"
    20  }
    21  
    22  resource "aws_security_group" "elb" {
    23    name = "{{ name }}-elb-${var.infra_id}"
    24    vpc_id = "${var.vpc_id}"
    25  
    26    egress {
    27      protocol    = -1
    28      from_port   = 0
    29      to_port     = 0
    30      cidr_blocks = ["0.0.0.0/0"]
    31    }
    32  
    33    ingress {
    34      protocol    = "tcp"
    35      from_port   = 80
    36      to_port     = 80
    37      cidr_blocks = ["0.0.0.0/0"]
    38    }
    39  }
    40  
    41  resource "aws_security_group" "app" {
    42    name   = "{{ name }}-${var.infra_id}"
    43    vpc_id = "${var.vpc_id}"
    44  
    45    ingress {
    46      protocol    = -1
    47      from_port   = 0
    48      to_port     = 0
    49      cidr_blocks = ["${var.vpc_cidr}"]
    50    }
    51    egress {
    52      protocol    = -1
    53      from_port   = 0
    54      to_port     = 0
    55      cidr_blocks = ["0.0.0.0/0"]
    56    }
    57  }
    58  
    59  resource "aws_elb" "app" {
    60    name            = "{{ name }}-${var.infra_id}"
    61    subnets         = ["${var.public_subnet_id}"]
    62    security_groups = ["${aws_security_group.elb.id}"]
    63    instances       = ["${aws_instance.app.*.id}"]
    64  
    65    # TODO: make listening ports configurable
    66    listener {
    67      lb_port           = 80
    68      lb_protocol       = "tcp"
    69      instance_port     = 80
    70      instance_protocol = "tcp"
    71    }
    72  }
    73  
    74  # Deploy a set of instances
    75  resource "aws_instance" "app" {
    76    ami           = "${var.ami}"
    77    instance_type = "${var.instance_type}"
    78    subnet_id     = "${var.private_subnet_id}"
    79    key_name      = "${var.key_name}"
    80  
    81    vpc_security_group_ids = ["${aws_security_group.app.id}"]
    82  
    83    tags {
    84      Name = "{{ name }}"
    85    }
    86  }
    87  
    88  output "url" {
    89    value = "http://${aws_elb.app.dns_name}/"
    90  }