github.com/ewbankkit/terraform@v0.7.7/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  
    12    listener {
    13      instance_port     = 80
    14      instance_protocol = "http"
    15      lb_port           = 80
    16      lb_protocol       = "http"
    17    }
    18  
    19    health_check {
    20      healthy_threshold   = 2
    21      unhealthy_threshold = 2
    22      timeout             = 3
    23      target              = "HTTP:80/"
    24      interval            = 30
    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  
    38    #vpc_zone_identifier = ["${split(",", var.availability_zones)}"]
    39    tag {
    40      key                 = "Name"
    41      value               = "web-asg"
    42      propagate_at_launch = "true"
    43    }
    44  }
    45  
    46  resource "aws_launch_configuration" "web-lc" {
    47    name          = "terraform-example-lc"
    48    image_id      = "${lookup(var.aws_amis, var.aws_region)}"
    49    instance_type = "${var.instance_type}"
    50  
    51    # Security group
    52    security_groups = ["${aws_security_group.default.id}"]
    53    user_data       = "${file("userdata.sh")}"
    54    key_name        = "${var.key_name}"
    55  }
    56  
    57  # Our default security group to access
    58  # the instances over SSH and HTTP
    59  resource "aws_security_group" "default" {
    60    name        = "terraform_example_sg"
    61    description = "Used in the terraform"
    62  
    63    # SSH access from anywhere
    64    ingress {
    65      from_port   = 22
    66      to_port     = 22
    67      protocol    = "tcp"
    68      cidr_blocks = ["0.0.0.0/0"]
    69    }
    70  
    71    # HTTP access from anywhere
    72    ingress {
    73      from_port   = 80
    74      to_port     = 80
    75      protocol    = "tcp"
    76      cidr_blocks = ["0.0.0.0/0"]
    77    }
    78  
    79    # outbound internet access
    80    egress {
    81      from_port   = 0
    82      to_port     = 0
    83      protocol    = "-1"
    84      cidr_blocks = ["0.0.0.0/0"]
    85    }
    86  }