github.com/fluxrad/terraform@v0.6.4-0.20150906191316-06627ccf39fa/examples/aws-asg/main.tf (about)

     1  # Specify the provider and access details
     2  provider "aws" {
     3    region = "${var.aws_region}"
     4  }
     5  
     6  resource "aws_elb" "web-elb" {
     7    name = "terraform-example-elb"
     8  
     9    # The same availability zone as our instances
    10    availability_zones = ["${split(",", var.availability_zones)}"]
    11    listener {
    12      instance_port = 80
    13      instance_protocol = "http"
    14      lb_port = 80
    15      lb_protocol = "http"
    16    }
    17  
    18    health_check {
    19      healthy_threshold = 2
    20      unhealthy_threshold = 2
    21      timeout = 3
    22      target = "HTTP:80/"
    23      interval = 30
    24    }
    25  
    26  }
    27  
    28  resource "aws_autoscaling_group" "web-asg" {
    29    availability_zones = ["${split(",", var.availability_zones)}"]
    30    name = "terraform-example-asg"
    31    max_size = "${var.asg_max}"
    32    min_size = "${var.asg_min}"
    33    desired_capacity = "${var.asg_desired}"
    34    force_delete = true
    35    launch_configuration = "${aws_launch_configuration.web-lc.name}"
    36    load_balancers = ["${aws_elb.web-elb.name}"]
    37    #vpc_zone_identifier = ["${split(",", var.availability_zones)}"]
    38    tag {
    39      key = "Name"
    40      value = "web-asg"
    41      propagate_at_launch = "true"
    42    }
    43  }
    44  
    45  resource "aws_launch_configuration" "web-lc" {
    46    name = "terraform-example-lc"
    47    image_id = "${lookup(var.aws_amis, var.aws_region)}"
    48    instance_type = "${var.instance_type}"
    49    # Security group
    50    security_groups = ["${aws_security_group.default.name}"]
    51    user_data = "${file("userdata.sh")}"
    52    key_name = "${var.key_name}"
    53  }
    54  
    55  # Our default security group to access
    56  # the instances over SSH and HTTP
    57  resource "aws_security_group" "default" {
    58    name = "terraform_example_sg"
    59    description = "Used in the terraform"
    60  
    61    # SSH access from anywhere
    62    ingress {
    63      from_port = 22
    64      to_port = 22
    65      protocol = "tcp"
    66      cidr_blocks = ["0.0.0.0/0"]
    67    }
    68  
    69    # HTTP access from anywhere
    70    ingress {
    71      from_port = 80
    72      to_port = 80
    73      protocol = "tcp"
    74      cidr_blocks = ["0.0.0.0/0"]
    75    }
    76  
    77    # outbound internet access
    78    egress {
    79      from_port = 0
    80      to_port = 0
    81      protocol = "-1"
    82      cidr_blocks = ["0.0.0.0/0"]
    83    }
    84  }