github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/website/source/docs/providers/aws/r/launch_configuration.html.markdown (about) 1 --- 2 layout: "aws" 3 page_title: "AWS: aws_launch_configuration" 4 sidebar_current: "docs-aws-resource-launch-configuration" 5 description: |- 6 Provides a resource to create a new launch configuration, used for autoscaling groups. 7 --- 8 9 # aws\_launch\_configuration 10 11 Provides a resource to create a new launch configuration, used for autoscaling groups. 12 13 ## Example Usage 14 15 ```hcl 16 data "aws_ami" "ubuntu" { 17 most_recent = true 18 19 filter { 20 name = "name" 21 values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"] 22 } 23 24 filter { 25 name = "virtualization-type" 26 values = ["hvm"] 27 } 28 29 owners = ["099720109477"] # Canonical 30 } 31 32 resource "aws_launch_configuration" "as_conf" { 33 name = "web_config" 34 image_id = "${data.aws_ami.ubuntu.id}" 35 instance_type = "t2.micro" 36 } 37 ``` 38 39 ## Using with AutoScaling Groups 40 41 Launch Configurations cannot be updated after creation with the Amazon 42 Web Service API. In order to update a Launch Configuration, Terraform will 43 destroy the existing resource and create a replacement. In order to effectively 44 use a Launch Configuration resource with an [AutoScaling Group resource][1], 45 it's recommended to specify `create_before_destroy` in a [lifecycle][2] block. 46 Either omit the Launch Configuration `name` attribute, or specify a partial name 47 with `name_prefix`. Example: 48 49 ```hcl 50 data "aws_ami" "ubuntu" { 51 most_recent = true 52 53 filter { 54 name = "name" 55 values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"] 56 } 57 58 filter { 59 name = "virtualization-type" 60 values = ["hvm"] 61 } 62 63 owners = ["099720109477"] # Canonical 64 } 65 66 resource "aws_launch_configuration" "as_conf" { 67 name_prefix = "terraform-lc-example-" 68 image_id = "${data.aws_ami.ubuntu.id}" 69 instance_type = "t2.micro" 70 71 lifecycle { 72 create_before_destroy = true 73 } 74 } 75 76 resource "aws_autoscaling_group" "bar" { 77 name = "terraform-asg-example" 78 launch_configuration = "${aws_launch_configuration.as_conf.name}" 79 min_size = 1 80 max_size = 2 81 82 lifecycle { 83 create_before_destroy = true 84 } 85 } 86 ``` 87 88 With this setup Terraform generates a unique name for your Launch 89 Configuration and can then update the AutoScaling Group without conflict before 90 destroying the previous Launch Configuration. 91 92 ## Using with Spot Instances 93 94 Launch configurations can set the spot instance pricing to be used for the 95 Auto Scaling Group to reserve instances. Simply specifying the `spot_price` 96 parameter will set the price on the Launch Configuration which will attempt to 97 reserve your instances at this price. See the [AWS Spot Instance 98 documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances.html) 99 for more information or how to launch [Spot Instances][3] with Terraform. 100 101 ```hcl 102 data "aws_ami" "ubuntu" { 103 most_recent = true 104 105 filter { 106 name = "name" 107 values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"] 108 } 109 110 filter { 111 name = "virtualization-type" 112 values = ["hvm"] 113 } 114 115 owners = ["099720109477"] # Canonical 116 } 117 118 resource "aws_launch_configuration" "as_conf" { 119 image_id = "${data.aws_ami.ubuntu.id}" 120 instance_type = "m4.large" 121 spot_price = "0.001" 122 123 lifecycle { 124 create_before_destroy = true 125 } 126 } 127 128 resource "aws_autoscaling_group" "bar" { 129 name = "terraform-asg-example" 130 launch_configuration = "${aws_launch_configuration.as_conf.name}" 131 } 132 ``` 133 134 ## Argument Reference 135 136 The following arguments are supported: 137 138 * `name` - (Optional) The name of the launch configuration. If you leave 139 this blank, Terraform will auto-generate a unique name. 140 * `name_prefix` - (Optional) Creates a unique name beginning with the specified 141 prefix. Conflicts with `name`. 142 * `image_id` - (Required) The EC2 image ID to launch. 143 * `instance_type` - (Required) The size of instance to launch. 144 * `iam_instance_profile` - (Optional) The IAM instance profile to associate 145 with launched instances. 146 * `key_name` - (Optional) The key name that should be used for the instance. 147 * `security_groups` - (Optional) A list of associated security group IDS. 148 * `associate_public_ip_address` - (Optional) Associate a public ip address with an instance in a VPC. 149 * `vpc_classic_link_id` - (Optional) The ID of a ClassicLink-enabled VPC. Only applies to EC2-Classic instances. (eg. `vpc-2730681a`) 150 * `vpc_classic_link_security_groups` - (Optional) The IDs of one or more security groups for the specified ClassicLink-enabled VPC (eg. `sg-46ae3d11`). 151 * `user_data` - (Optional) The user data to provide when launching the instance. 152 * `enable_monitoring` - (Optional) Enables/disables detailed monitoring. This is enabled by default. 153 * `ebs_optimized` - (Optional) If true, the launched EC2 instance will be EBS-optimized. 154 * `root_block_device` - (Optional) Customize details about the root block 155 device of the instance. See [Block Devices](#block-devices) below for details. 156 * `ebs_block_device` - (Optional) Additional EBS block devices to attach to the 157 instance. See [Block Devices](#block-devices) below for details. 158 * `ephemeral_block_device` - (Optional) Customize Ephemeral (also known as 159 "Instance Store") volumes on the instance. See [Block Devices](#block-devices) below for details. 160 * `spot_price` - (Optional) The price to use for reserving spot instances. 161 * `placement_tenancy` - (Optional) The tenancy of the instance. Valid values are 162 `"default"` or `"dedicated"`, see [AWS's Create Launch Configuration](http://docs.aws.amazon.com/AutoScaling/latest/APIReference/API_CreateLaunchConfiguration.html) 163 for more details 164 165 ## Block devices 166 167 Each of the `*_block_device` attributes controls a portion of the AWS 168 Launch Configuration's "Block Device Mapping". It's a good idea to familiarize yourself with [AWS's Block Device 169 Mapping docs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html) 170 to understand the implications of using these attributes. 171 172 The `root_block_device` mapping supports the following: 173 174 * `volume_type` - (Optional) The type of volume. Can be `"standard"`, `"gp2"`, 175 or `"io1"`. (Default: `"standard"`). 176 * `volume_size` - (Optional) The size of the volume in gigabytes. 177 * `iops` - (Optional) The amount of provisioned 178 [IOPS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-io-characteristics.html). 179 This must be set with a `volume_type` of `"io1"`. 180 * `delete_on_termination` - (Optional) Whether the volume should be destroyed 181 on instance termination (Default: `true`). 182 183 Modifying any of the `root_block_device` settings requires resource 184 replacement. 185 186 Each `ebs_block_device` supports the following: 187 188 * `device_name` - (Required) The name of the device to mount. 189 * `snapshot_id` - (Optional) The Snapshot ID to mount. 190 * `volume_type` - (Optional) The type of volume. Can be `"standard"`, `"gp2"`, 191 or `"io1"`. (Default: `"standard"`). 192 * `volume_size` - (Optional) The size of the volume in gigabytes. 193 * `iops` - (Optional) The amount of provisioned 194 [IOPS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-io-characteristics.html). 195 This must be set with a `volume_type` of `"io1"`. 196 * `delete_on_termination` - (Optional) Whether the volume should be destroyed 197 on instance termination (Default: `true`). 198 * `encrypted` - (Optional) Whether the volume should be encrypted or not. Do not use this option if you are using `snapshot_id` as the encrypted flag will be determined by the snapshot. (Default: `false`). 199 200 Modifying any `ebs_block_device` currently requires resource replacement. 201 202 Each `ephemeral_block_device` supports the following: 203 204 * `device_name` - The name of the block device to mount on the instance. 205 * `virtual_name` - The [Instance Store Device 206 Name](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#InstanceStoreDeviceNames) 207 (e.g. `"ephemeral0"`) 208 209 Each AWS Instance type has a different set of Instance Store block devices 210 available for attachment. AWS [publishes a 211 list](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#StorageOnInstanceTypes) 212 of which ephemeral devices are available on each type. The devices are always 213 identified by the `virtual_name` in the format `"ephemeral{0..N}"`. 214 215 ~> **NOTE:** Changes to `*_block_device` configuration of _existing_ resources 216 cannot currently be detected by Terraform. After updating to block device 217 configuration, resource recreation can be manually triggered by using the 218 [`taint` command](/docs/commands/taint.html). 219 220 ## Attributes Reference 221 222 The following attributes are exported: 223 224 * `id` - The ID of the launch configuration. 225 * `name` - The name of the launch configuration. 226 227 [1]: /docs/providers/aws/r/autoscaling_group.html 228 [2]: /docs/configuration/resources.html#lifecycle 229 [3]: /docs/providers/aws/r/spot_instance_request.html 230 231 ## Import 232 233 Launch configurations can be imported using the `name`, e.g. 234 235 ``` 236 $ terraform import aws_launch_configuration.as_conf terraform-lg-123456 237 ```