github.com/ns1/terraform@v0.7.10-0.20161109153551-8949419bef40/website/source/docs/providers/aws/r/autoscaling_group.html.markdown (about)

     1  ---
     2  layout: "aws"
     3  page_title: "AWS: aws_autoscaling_group"
     4  sidebar_current: "docs-aws-resource-autoscaling-group"
     5  description: |-
     6    Provides an AutoScaling Group resource.
     7  ---
     8  
     9  # aws\_autoscaling\_group
    10  
    11  Provides an AutoScaling Group resource.
    12  
    13  ## Example Usage
    14  
    15  ```
    16  resource "aws_placement_group" "test" {
    17    name = "test"
    18    strategy = "cluster"
    19  }
    20  
    21  resource "aws_autoscaling_group" "bar" {
    22    availability_zones = ["us-east-1a"]
    23    name = "foobar3-terraform-test"
    24    max_size = 5
    25    min_size = 2
    26    health_check_grace_period = 300
    27    health_check_type = "ELB"
    28    desired_capacity = 4
    29    force_delete = true
    30    placement_group = "${aws_placement_group.test.id}"
    31    launch_configuration = "${aws_launch_configuration.foobar.name}"
    32  
    33    tag {
    34      key = "foo"
    35      value = "bar"
    36      propagate_at_launch = true
    37    }
    38    tag {
    39      key = "lorem"
    40      value = "ipsum"
    41      propagate_at_launch = false
    42    }
    43  }
    44  ```
    45  
    46  ## Argument Reference
    47  
    48  The following arguments are supported:
    49  
    50  * `name` - (Optional) The name of the auto scale group. By default generated by terraform.
    51  * `max_size` - (Required) The maximum size of the auto scale group.
    52  * `min_size` - (Required) The minimum size of the auto scale group.
    53      (See also [Waiting for Capacity](#waiting-for-capacity) below.)
    54  * `availability_zones` - (Optional) A list of AZs to launch resources in.
    55     Required only if you do not specify any `vpc_zone_identifier`
    56  * `launch_configuration` - (Required) The name of the launch configuration to use.
    57  * `health_check_grace_period` - (Optional, Default: 300) Time (in seconds) after instance comes into service before checking health.
    58  * `health_check_type` - (Optional) "EC2" or "ELB". Controls how health checking is done.
    59  * `desired_capacity` - (Optional) The number of Amazon EC2 instances that
    60      should be running in the group. (See also [Waiting for
    61      Capacity](#waiting-for-capacity) below.)
    62  * `force_delete` - (Optional) Allows deleting the autoscaling group without waiting
    63     for all instances in the pool to terminate.  You can force an autoscaling group to delete
    64     even if it's in the process of scaling a resource. Normally, Terraform
    65     drains all the instances before deleting the group.  This bypasses that
    66     behavior and potentially leaves resources dangling.
    67  * `load_balancers` (Optional) A list of load balancer names to add to the autoscaling
    68     group names.
    69  * `vpc_zone_identifier` (Optional) A list of subnet IDs to launch resources in.
    70  * `target_group_arns` (Optional) A list of `aws_alb_target_group` ARNs, for use with
    71  Application Load Balancing
    72  * `termination_policies` (Optional) A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `Default`.
    73  * `tag` (Optional) A list of tag blocks. Tags documented below.
    74  * `placement_group` (Optional) The name of the placement group into which you'll launch your instances, if any.
    75  * `metrics_granularity` - (Optional) The granularity to associate with the metrics to collect. The only valid value is `1Minute`. Default is `1Minute`.
    76  * `enabled_metrics` - (Optional) A list of metrics to collect. The allowed values are `GroupMinSize`, `GroupMaxSize`, `GroupDesiredCapacity`, `GroupInServiceInstances`, `GroupPendingInstances`, `GroupStandbyInstances`, `GroupTerminatingInstances`, `GroupTotalInstances`.
    77  * `wait_for_capacity_timeout` (Default: "10m") A maximum
    78    [duration](https://golang.org/pkg/time/#ParseDuration) that Terraform should
    79    wait for ASG instances to be healthy before timing out.  (See also [Waiting
    80    for Capacity](#waiting-for-capacity) below.) Setting this to "0" causes
    81    Terraform to skip all Capacity Waiting behavior.
    82  * `min_elb_capacity` - (Optional) Setting this causes Terraform to wait for
    83    this number of instances to show up healthy in the ELB only on creation.
    84    Updates will not wait on ELB instance number changes.
    85    (See also [Waiting for Capacity](#waiting-for-capacity) below.)
    86  * `wait_for_elb_capacity` - (Optional) Setting this will cause Terraform to wait
    87    for exactly this number of healthy instances in all attached load balancers
    88    on both create and update operations. (Takes precedence over
    89    `min_elb_capacity` behavior.)
    90    (See also [Waiting for Capacity](#waiting-for-capacity) below.)
    91  * `protect_from_scale_in` (Optional) Allows setting instance protection. The
    92     autoscaling group will not select instances with this setting for terminination
    93     during scale in events.
    94  
    95  Tags support the following:
    96  
    97  * `key` - (Required) Key
    98  * `value` - (Required) Value
    99  * `propagate_at_launch` - (Required) Enables propagation of the tag to
   100     Amazon EC2 instances launched via this ASG
   101  
   102  ## Attributes Reference
   103  
   104  The following attributes are exported:
   105  
   106  * `id` - The autoscaling group id.
   107  * `arn` - The ARN for this AutoScaling Group
   108  * `availability_zones` - The availability zones of the autoscale group.
   109  * `min_size` - The minimum size of the autoscale group
   110  * `max_size` - The maximum size of the autoscale group
   111  * `default_cooldown` - Time between a scaling activity and the succeeding scaling activity.
   112  * `name` - The name of the autoscale group
   113  * `health_check_grace_period` - Time after instance comes into service before checking health.
   114  * `health_check_type` - "EC2" or "ELB". Controls how health checking is done.
   115  * `desired_capacity` -The number of Amazon EC2 instances that should be running in the group.
   116  * `launch_configuration` - The launch configuration of the autoscale group
   117  * `vpc_zone_identifier` (Optional) - The VPC zone identifier
   118  * `load_balancers` (Optional) The load balancer names associated with the
   119     autoscaling group.
   120  * `target_group_arns` (Optional) list of Target Group ARNs that apply to this
   121  AutoScaling Group
   122  
   123  ~> **NOTE:** When using `ELB` as the health_check_type, `health_check_grace_period` is required.
   124  
   125  ## Waiting for Capacity
   126  
   127  A newly-created ASG is initially empty and begins to scale to `min_size` (or
   128  `desired_capacity`, if specified) by launching instances using the provided
   129  Launch Configuration. These instances take time to launch and boot.
   130  
   131  On ASG Update, changes to these values also take time to result in the target
   132  number of instances providing service.
   133  
   134  Terraform provides two mechanisms to help consistently manage ASG scale up
   135  time across dependent resources.
   136  
   137  #### Waiting for ASG Capacity
   138  
   139  The first is default behavior. Terraform waits after ASG creation for
   140  `min_size` (or `desired_capacity`, if specified) healthy instances to show up
   141  in the ASG before continuing.
   142  
   143  If `min_size` or `desired_capacity` are changed in a subsequent update,
   144  Terraform will also wait for the correct number of healthy instances before
   145  continuing.
   146  
   147  Terraform considers an instance "healthy" when the ASG reports `HealthStatus:
   148  "Healthy"` and `LifecycleState: "InService"`. See the [AWS AutoScaling
   149  Docs](https://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/AutoScalingGroupLifecycle.html)
   150  for more information on an ASG's lifecycle.
   151  
   152  Terraform will wait for healthy instances for up to
   153  `wait_for_capacity_timeout`. If ASG creation is taking more than a few minutes,
   154  it's worth investigating for scaling activity errors, which can be caused by
   155  problems with the selected Launch Configuration.
   156  
   157  Setting `wait_for_capacity_timeout` to `"0"` disables ASG Capacity waiting.
   158  
   159  #### Waiting for ELB Capacity
   160  
   161  The second mechanism is optional, and affects ASGs with attached ELBs specified
   162  via the `load_balancers` attribute.
   163  
   164  The `min_elb_capacity` parameter causes Terraform to wait for at least the
   165  requested number of instances to show up `"InService"` in all attached ELBs
   166  during ASG creation.  It has no effect on ASG updates.
   167  
   168  If `wait_for_elb_capacity` is set, Terraform will wait for exactly that number
   169  of Instances to be `"InService"` in all attached ELBs on both creation and
   170  updates.
   171  
   172  These parameters can be used to ensure that service is being provided before
   173  Terraform moves on. If new instances don't pass the ELB's health checks for any
   174  reason, the Terraform apply will time out, and the ASG will be marked as
   175  tainted (i.e. marked to be destroyed in a follow up run).
   176  
   177  As with ASG Capacity, Terraform will wait for up to `wait_for_capacity_timeout`
   178  for the proper number of instances to be healthy.
   179  
   180  #### Troubleshooting Capacity Waiting Timeouts
   181  
   182  If ASG creation takes more than a few minutes, this could indicate one of a
   183  number of configuration problems. See the [AWS Docs on Load Balancer
   184  Troubleshooting](https://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-troubleshooting.html)
   185  for more information.
   186  
   187  
   188  ## Import
   189  
   190  AutoScaling Groups can be imported using the `name`, e.g. 
   191  
   192  ```
   193  $ terraform import aws_autoscaling_group.web web-asg
   194  ```