github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/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 ## Interpolated tags 64 65 ``` 66 variable extra_tags { 67 default = [ 68 { 69 key = "Foo" 70 value = "Bar" 71 propagate_at_launch = true 72 }, 73 { 74 key = "Baz" 75 value = "Bam" 76 propagate_at_launch = true 77 }, 78 ] 79 } 80 81 resource "aws_autoscaling_group" "bar" { 82 availability_zones = ["us-east-1a"] 83 name = "foobar3-terraform-test" 84 max_size = 5 85 min_size = 2 86 launch_configuration = "${aws_launch_configuration.foobar.name}" 87 88 tags = [ 89 { 90 key = "explicit1" 91 value = "value1" 92 propagate_at_launch = true 93 }, 94 { 95 key = "explicit2" 96 value = "value2" 97 propagate_at_launch = true 98 }, 99 ] 100 101 tags = ["${concat( 102 list( 103 map("key", "interpolation1", "value", "value3", "propagate_at_launch", true), 104 map("key", "interpolation2", "value", "value4", "propagate_at_launch", true) 105 ), 106 var.extra_tags) 107 }"] 108 } 109 ``` 110 111 ## Argument Reference 112 113 The following arguments are supported: 114 115 * `name` - (Optional) The name of the auto scaling group. By default generated by Terraform. 116 * `name_prefix` - (Optional) Creates a unique name beginning with the specified 117 prefix. Conflicts with `name`. 118 * `max_size` - (Required) The maximum size of the auto scale group. 119 * `min_size` - (Required) The minimum size of the auto scale group. 120 (See also [Waiting for Capacity](#waiting-for-capacity) below.) 121 * `availability_zones` - (Optional) A list of AZs to launch resources in. 122 Required only if you do not specify any `vpc_zone_identifier` 123 * `default_cooldown` - (Optional) The amount of time, in seconds, after a scaling activity completes before another scaling activity can start. 124 * `launch_configuration` - (Required) The name of the launch configuration to use. 125 * `initial_lifecycle_hook` - (Optional) One or more 126 [Lifecycle Hooks](http://docs.aws.amazon.com/autoscaling/latest/userguide/lifecycle-hooks.html) 127 to attach to the autoscaling group **before** instances are launched. The 128 syntax is exactly the same as the separate 129 [`aws_autoscaling_lifecycle_hook`](/docs/providers/aws/r/autoscaling_lifecycle_hooks.html) 130 resource, without the `autoscaling_group_name` attribute. Please note that this will only work when creating 131 a new autoscaling group. For all other use-cases, please use `aws_autoscaling_lifecycle_hook` resource. 132 * `health_check_grace_period` - (Optional, Default: 300) Time (in seconds) after instance comes into service before checking health. 133 * `health_check_type` - (Optional) "EC2" or "ELB". Controls how health checking is done. 134 * `desired_capacity` - (Optional) The number of Amazon EC2 instances that 135 should be running in the group. (See also [Waiting for 136 Capacity](#waiting-for-capacity) below.) 137 * `force_delete` - (Optional) Allows deleting the autoscaling group without waiting 138 for all instances in the pool to terminate. You can force an autoscaling group to delete 139 even if it's in the process of scaling a resource. Normally, Terraform 140 drains all the instances before deleting the group. This bypasses that 141 behavior and potentially leaves resources dangling. 142 * `load_balancers` (Optional) A list of elastic load balancer names to add to the autoscaling 143 group names. 144 * `vpc_zone_identifier` (Optional) A list of subnet IDs to launch resources in. 145 * `target_group_arns` (Optional) A list of `aws_alb_target_group` ARNs, for use with 146 Application Load Balancing 147 * `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`. 148 * `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`. 149 Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your autoscaling group from functioning properly. 150 * `tag` (Optional) A list of tag blocks. Tags documented below. 151 * `tags` (Optional) A list of tag blocks (maps). Tags documented below. 152 * `placement_group` (Optional) The name of the placement group into which you'll launch your instances, if any. 153 * `metrics_granularity` - (Optional) The granularity to associate with the metrics to collect. The only valid value is `1Minute`. Default is `1Minute`. 154 * `enabled_metrics` - (Optional) A list of metrics to collect. The allowed values are `GroupMinSize`, `GroupMaxSize`, `GroupDesiredCapacity`, `GroupInServiceInstances`, `GroupPendingInstances`, `GroupStandbyInstances`, `GroupTerminatingInstances`, `GroupTotalInstances`. 155 * `wait_for_capacity_timeout` (Default: "10m") A maximum 156 [duration](https://golang.org/pkg/time/#ParseDuration) that Terraform should 157 wait for ASG instances to be healthy before timing out. (See also [Waiting 158 for Capacity](#waiting-for-capacity) below.) Setting this to "0" causes 159 Terraform to skip all Capacity Waiting behavior. 160 * `min_elb_capacity` - (Optional) Setting this causes Terraform to wait for 161 this number of instances to show up healthy in the ELB only on creation. 162 Updates will not wait on ELB instance number changes. 163 (See also [Waiting for Capacity](#waiting-for-capacity) below.) 164 * `wait_for_elb_capacity` - (Optional) Setting this will cause Terraform to wait 165 for exactly this number of healthy instances in all attached load balancers 166 on both create and update operations. (Takes precedence over 167 `min_elb_capacity` behavior.) 168 (See also [Waiting for Capacity](#waiting-for-capacity) below.) 169 * `protect_from_scale_in` (Optional) Allows setting instance protection. The 170 autoscaling group will not select instances with this setting for terminination 171 during scale in events. 172 173 Tags support the following: 174 175 The `tag` attribute accepts exactly one tag declaration with the following fields: 176 177 * `key` - (Required) Key 178 * `value` - (Required) Value 179 * `propagate_at_launch` - (Required) Enables propagation of the tag to 180 Amazon EC2 instances launched via this ASG 181 182 To declare multiple tags additional `tag` blocks can be specified. 183 Alternatively the `tags` attributes can be used, which accepts a list of maps containing the above field names as keys and their respective values. 184 This allows the construction of dynamic lists of tags which is not possible using the single `tag` attribute. 185 `tag` and `tags` are mutually exclusive, only one of them can be specified. 186 187 ## Attributes Reference 188 189 The following attributes are exported: 190 191 * `id` - The autoscaling group id. 192 * `arn` - The ARN for this AutoScaling Group 193 * `availability_zones` - The availability zones of the autoscale group. 194 * `min_size` - The minimum size of the autoscale group 195 * `max_size` - The maximum size of the autoscale group 196 * `default_cooldown` - Time between a scaling activity and the succeeding scaling activity. 197 * `name` - The name of the autoscale group 198 * `health_check_grace_period` - Time after instance comes into service before checking health. 199 * `health_check_type` - "EC2" or "ELB". Controls how health checking is done. 200 * `desired_capacity` -The number of Amazon EC2 instances that should be running in the group. 201 * `launch_configuration` - The launch configuration of the autoscale group 202 * `vpc_zone_identifier` (Optional) - The VPC zone identifier 203 * `load_balancers` (Optional) The load balancer names associated with the 204 autoscaling group. 205 * `target_group_arns` (Optional) list of Target Group ARNs that apply to this 206 AutoScaling Group 207 208 ~> **NOTE:** When using `ELB` as the `health_check_type`, `health_check_grace_period` is required. 209 210 ~> **NOTE:** Terraform has two types of ways you can add lifecycle hooks - via 211 the `initial_lifecycle_hook` attribute from this resource, or via the separate 212 [`aws_autoscaling_lifecycle_hook`](/docs/providers/aws/r/autoscaling_lifecycle_hooks.html) 213 resource. `initial_lifecycle_hook` exists here because any lifecycle hooks 214 added with `aws_autoscaling_lifecycle_hook` will not be added until the 215 autoscaling group has been created, and depending on your 216 [capacity](#waiting-for-capacity) settings, after the initial instances have 217 been launched, creating unintended behavior. If you need hooks to run on all 218 instances, add them with `initial_lifecycle_hook` here, but take 219 care to not duplicate these hooks in `aws_autoscaling_lifecycle_hook`. 220 221 ## Waiting for Capacity 222 223 A newly-created ASG is initially empty and begins to scale to `min_size` (or 224 `desired_capacity`, if specified) by launching instances using the provided 225 Launch Configuration. These instances take time to launch and boot. 226 227 On ASG Update, changes to these values also take time to result in the target 228 number of instances providing service. 229 230 Terraform provides two mechanisms to help consistently manage ASG scale up 231 time across dependent resources. 232 233 #### Waiting for ASG Capacity 234 235 The first is default behavior. Terraform waits after ASG creation for 236 `min_size` (or `desired_capacity`, if specified) healthy instances to show up 237 in the ASG before continuing. 238 239 If `min_size` or `desired_capacity` are changed in a subsequent update, 240 Terraform will also wait for the correct number of healthy instances before 241 continuing. 242 243 Terraform considers an instance "healthy" when the ASG reports `HealthStatus: 244 "Healthy"` and `LifecycleState: "InService"`. See the [AWS AutoScaling 245 Docs](https://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/AutoScalingGroupLifecycle.html) 246 for more information on an ASG's lifecycle. 247 248 Terraform will wait for healthy instances for up to 249 `wait_for_capacity_timeout`. If ASG creation is taking more than a few minutes, 250 it's worth investigating for scaling activity errors, which can be caused by 251 problems with the selected Launch Configuration. 252 253 Setting `wait_for_capacity_timeout` to `"0"` disables ASG Capacity waiting. 254 255 #### Waiting for ELB Capacity 256 257 The second mechanism is optional, and affects ASGs with attached ELBs specified 258 via the `load_balancers` attribute. 259 260 The `min_elb_capacity` parameter causes Terraform to wait for at least the 261 requested number of instances to show up `"InService"` in all attached ELBs 262 during ASG creation. It has no effect on ASG updates. 263 264 If `wait_for_elb_capacity` is set, Terraform will wait for exactly that number 265 of Instances to be `"InService"` in all attached ELBs on both creation and 266 updates. 267 268 These parameters can be used to ensure that service is being provided before 269 Terraform moves on. If new instances don't pass the ELB's health checks for any 270 reason, the Terraform apply will time out, and the ASG will be marked as 271 tainted (i.e. marked to be destroyed in a follow up run). 272 273 As with ASG Capacity, Terraform will wait for up to `wait_for_capacity_timeout` 274 for the proper number of instances to be healthy. 275 276 #### Troubleshooting Capacity Waiting Timeouts 277 278 If ASG creation takes more than a few minutes, this could indicate one of a 279 number of configuration problems. See the [AWS Docs on Load Balancer 280 Troubleshooting](https://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-troubleshooting.html) 281 for more information. 282 283 284 ## Import 285 286 AutoScaling Groups can be imported using the `name`, e.g. 287 288 ``` 289 $ terraform import aws_autoscaling_group.web web-asg 290 ```