github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/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 ```hcl 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 initial_lifecycle_hook { 34 name = "foobar" 35 default_result = "CONTINUE" 36 heartbeat_timeout = 2000 37 lifecycle_transition = "autoscaling:EC2_INSTANCE_LAUNCHING" 38 39 notification_metadata = <<EOF 40 { 41 "foo": "bar" 42 } 43 EOF 44 45 notification_target_arn = "arn:aws:sqs:us-east-1:444455556666:queue1*" 46 role_arn = "arn:aws:iam::123456789012:role/S3Access" 47 } 48 49 tag { 50 key = "foo" 51 value = "bar" 52 propagate_at_launch = true 53 } 54 55 tag { 56 key = "lorem" 57 value = "ipsum" 58 propagate_at_launch = false 59 } 60 } 61 ``` 62 63 ## Argument Reference 64 65 The following arguments are supported: 66 67 * `name` - (Optional) The name of the auto scaling group. By default generated by Terraform. 68 * `name_prefix` - (Optional) Creates a unique name beginning with the specified 69 prefix. Conflicts with `name`. 70 * `max_size` - (Required) The maximum size of the auto scale group. 71 * `min_size` - (Required) The minimum size of the auto scale group. 72 (See also [Waiting for Capacity](#waiting-for-capacity) below.) 73 * `availability_zones` - (Optional) A list of AZs to launch resources in. 74 Required only if you do not specify any `vpc_zone_identifier` 75 * `default_cooldown` - (Optional) The amount of time, in seconds, after a scaling activity completes before another scaling activity can start. 76 * `launch_configuration` - (Required) The name of the launch configuration to use. 77 * `initial_lifecycle_hook` - (Optional) One or more 78 [Lifecycle Hooks](http://docs.aws.amazon.com/autoscaling/latest/userguide/lifecycle-hooks.html) 79 to attach to the autoscaling group **before** instances are launched. The 80 syntax is exactly the same as the separate 81 [`aws_autoscaling_lifecycle_hook`](/docs/providers/aws/r/autoscaling_lifecycle_hooks.html) 82 resource, without the `autoscaling_group_name` attribute. Please note that this will only work when creating 83 a new autoscaling group. For all other use-cases, please use `aws_autoscaling_lifecycle_hook` resource. 84 * `health_check_grace_period` - (Optional, Default: 300) Time (in seconds) after instance comes into service before checking health. 85 * `health_check_type` - (Optional) "EC2" or "ELB". Controls how health checking is done. 86 * `desired_capacity` - (Optional) The number of Amazon EC2 instances that 87 should be running in the group. (See also [Waiting for 88 Capacity](#waiting-for-capacity) below.) 89 * `force_delete` - (Optional) Allows deleting the autoscaling group without waiting 90 for all instances in the pool to terminate. You can force an autoscaling group to delete 91 even if it's in the process of scaling a resource. Normally, Terraform 92 drains all the instances before deleting the group. This bypasses that 93 behavior and potentially leaves resources dangling. 94 * `load_balancers` (Optional) A list of elastic load balancer names to add to the autoscaling 95 group names. 96 * `vpc_zone_identifier` (Optional) A list of subnet IDs to launch resources in. 97 * `target_group_arns` (Optional) A list of `aws_alb_target_group` ARNs, for use with 98 Application Load Balancing 99 * `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`. 100 * `suspended_processes` - (Optional) A list of processes to suspend for the AutoScaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`. 101 Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your autoscaling group from functioning properly. 102 * `tag` (Optional) A list of tag blocks. Tags documented below. 103 * `placement_group` (Optional) The name of the placement group into which you'll launch your instances, if any. 104 * `metrics_granularity` - (Optional) The granularity to associate with the metrics to collect. The only valid value is `1Minute`. Default is `1Minute`. 105 * `enabled_metrics` - (Optional) A list of metrics to collect. The allowed values are `GroupMinSize`, `GroupMaxSize`, `GroupDesiredCapacity`, `GroupInServiceInstances`, `GroupPendingInstances`, `GroupStandbyInstances`, `GroupTerminatingInstances`, `GroupTotalInstances`. 106 * `wait_for_capacity_timeout` (Default: "10m") A maximum 107 [duration](https://golang.org/pkg/time/#ParseDuration) that Terraform should 108 wait for ASG instances to be healthy before timing out. (See also [Waiting 109 for Capacity](#waiting-for-capacity) below.) Setting this to "0" causes 110 Terraform to skip all Capacity Waiting behavior. 111 * `min_elb_capacity` - (Optional) Setting this causes Terraform to wait for 112 this number of instances to show up healthy in the ELB only on creation. 113 Updates will not wait on ELB instance number changes. 114 (See also [Waiting for Capacity](#waiting-for-capacity) below.) 115 * `wait_for_elb_capacity` - (Optional) Setting this will cause Terraform to wait 116 for exactly this number of healthy instances in all attached load balancers 117 on both create and update operations. (Takes precedence over 118 `min_elb_capacity` behavior.) 119 (See also [Waiting for Capacity](#waiting-for-capacity) below.) 120 * `protect_from_scale_in` (Optional) Allows setting instance protection. The 121 autoscaling group will not select instances with this setting for terminination 122 during scale in events. 123 124 Tags support the following: 125 126 * `key` - (Required) Key 127 * `value` - (Required) Value 128 * `propagate_at_launch` - (Required) Enables propagation of the tag to 129 Amazon EC2 instances launched via this ASG 130 131 ## Attributes Reference 132 133 The following attributes are exported: 134 135 * `id` - The autoscaling group id. 136 * `arn` - The ARN for this AutoScaling Group 137 * `availability_zones` - The availability zones of the autoscale group. 138 * `min_size` - The minimum size of the autoscale group 139 * `max_size` - The maximum size of the autoscale group 140 * `default_cooldown` - Time between a scaling activity and the succeeding scaling activity. 141 * `name` - The name of the autoscale group 142 * `health_check_grace_period` - Time after instance comes into service before checking health. 143 * `health_check_type` - "EC2" or "ELB". Controls how health checking is done. 144 * `desired_capacity` -The number of Amazon EC2 instances that should be running in the group. 145 * `launch_configuration` - The launch configuration of the autoscale group 146 * `vpc_zone_identifier` (Optional) - The VPC zone identifier 147 * `load_balancers` (Optional) The load balancer names associated with the 148 autoscaling group. 149 * `target_group_arns` (Optional) list of Target Group ARNs that apply to this 150 AutoScaling Group 151 152 ~> **NOTE:** When using `ELB` as the `health_check_type`, `health_check_grace_period` is required. 153 154 ~> **NOTE:** Terraform has two types of ways you can add lifecycle hooks - via 155 the `initial_lifecycle_hook` attribute from this resource, or via the separate 156 [`aws_autoscaling_lifecycle_hook`](/docs/providers/aws/r/autoscaling_lifecycle_hooks.html) 157 resource. `initial_lifecycle_hook` exists here because any lifecycle hooks 158 added with `aws_autoscaling_lifecycle_hook` will not be added until the 159 autoscaling group has been created, and depending on your 160 [capacity](#waiting-for-capacity) settings, after the initial instances have 161 been launched, creating unintended behavior. If you need hooks to run on all 162 instances, add them with `initial_lifecycle_hook` here, but take 163 care to not duplicate these hooks in `aws_autoscaling_lifecycle_hook`. 164 165 ## Waiting for Capacity 166 167 A newly-created ASG is initially empty and begins to scale to `min_size` (or 168 `desired_capacity`, if specified) by launching instances using the provided 169 Launch Configuration. These instances take time to launch and boot. 170 171 On ASG Update, changes to these values also take time to result in the target 172 number of instances providing service. 173 174 Terraform provides two mechanisms to help consistently manage ASG scale up 175 time across dependent resources. 176 177 #### Waiting for ASG Capacity 178 179 The first is default behavior. Terraform waits after ASG creation for 180 `min_size` (or `desired_capacity`, if specified) healthy instances to show up 181 in the ASG before continuing. 182 183 If `min_size` or `desired_capacity` are changed in a subsequent update, 184 Terraform will also wait for the correct number of healthy instances before 185 continuing. 186 187 Terraform considers an instance "healthy" when the ASG reports `HealthStatus: 188 "Healthy"` and `LifecycleState: "InService"`. See the [AWS AutoScaling 189 Docs](https://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/AutoScalingGroupLifecycle.html) 190 for more information on an ASG's lifecycle. 191 192 Terraform will wait for healthy instances for up to 193 `wait_for_capacity_timeout`. If ASG creation is taking more than a few minutes, 194 it's worth investigating for scaling activity errors, which can be caused by 195 problems with the selected Launch Configuration. 196 197 Setting `wait_for_capacity_timeout` to `"0"` disables ASG Capacity waiting. 198 199 #### Waiting for ELB Capacity 200 201 The second mechanism is optional, and affects ASGs with attached ELBs specified 202 via the `load_balancers` attribute. 203 204 The `min_elb_capacity` parameter causes Terraform to wait for at least the 205 requested number of instances to show up `"InService"` in all attached ELBs 206 during ASG creation. It has no effect on ASG updates. 207 208 If `wait_for_elb_capacity` is set, Terraform will wait for exactly that number 209 of Instances to be `"InService"` in all attached ELBs on both creation and 210 updates. 211 212 These parameters can be used to ensure that service is being provided before 213 Terraform moves on. If new instances don't pass the ELB's health checks for any 214 reason, the Terraform apply will time out, and the ASG will be marked as 215 tainted (i.e. marked to be destroyed in a follow up run). 216 217 As with ASG Capacity, Terraform will wait for up to `wait_for_capacity_timeout` 218 for the proper number of instances to be healthy. 219 220 #### Troubleshooting Capacity Waiting Timeouts 221 222 If ASG creation takes more than a few minutes, this could indicate one of a 223 number of configuration problems. See the [AWS Docs on Load Balancer 224 Troubleshooting](https://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-troubleshooting.html) 225 for more information. 226 227 228 ## Import 229 230 AutoScaling Groups can be imported using the `name`, e.g. 231 232 ``` 233 $ terraform import aws_autoscaling_group.web web-asg 234 ```