github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/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 ``` 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 ``` 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 80 lifecycle { 81 create_before_destroy = true 82 } 83 } 84 ``` 85 86 With this setup Terraform generates a unique name for your Launch 87 Configuration and can then update the AutoScaling Group without conflict before 88 destroying the previous Launch Configuration. 89 90 ## Using with Spot Instances 91 92 Launch configurations can set the spot instance pricing to be used for the 93 Auto Scaling Group to reserve instances. Simply specifying the `spot_price` 94 parameter will set the price on the Launch Configuration which will attempt to 95 reserve your instances at this price. See the [AWS Spot Instance 96 documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances.html) 97 for more information or how to launch [Spot Instances][3] with Terraform. 98 99 ``` 100 data "aws_ami" "ubuntu" { 101 most_recent = true 102 103 filter { 104 name = "name" 105 values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"] 106 } 107 108 filter { 109 name = "virtualization-type" 110 values = ["hvm"] 111 } 112 113 owners = ["099720109477"] # Canonical 114 } 115 116 resource "aws_launch_configuration" "as_conf" { 117 image_id = "${data.aws_ami.ubuntu.id}" 118 instance_type = "m4.large" 119 spot_price = "0.001" 120 121 lifecycle { 122 create_before_destroy = true 123 } 124 } 125 126 resource "aws_autoscaling_group" "bar" { 127 name = "terraform-asg-example" 128 launch_configuration = "${aws_launch_configuration.as_conf.name}" 129 } 130 ``` 131 132 ## Argument Reference 133 134 The following arguments are supported: 135 136 * `name` - (Optional) The name of the launch configuration. If you leave 137 this blank, Terraform will auto-generate a unique name. 138 * `name_prefix` - (Optional) Creates a unique name beginning with the specified 139 prefix. Conflicts with `name`. 140 * `image_id` - (Required) The EC2 image ID to launch. 141 * `instance_type` - (Required) The size of instance to launch. 142 * `iam_instance_profile` - (Optional) The IAM instance profile to associate 143 with launched instances. 144 * `key_name` - (Optional) The key name that should be used for the instance. 145 * `security_groups` - (Optional) A list of associated security group IDS. 146 * `associate_public_ip_address` - (Optional) Associate a public ip address with an instance in a VPC. 147 * `vpc_classic_link_id` - (Optional) The ID of a ClassicLink-enabled VPC. Only applies to EC2-Classic instances. (eg. `vpc-2730681a`) 148 * `vpc_classic_link_security_groups` - (Optional) The IDs of one or more security groups for the specified ClassicLink-enabled VPC (eg. `sg-46ae3d11`). 149 * `user_data` - (Optional) The user data to provide when launching the instance. 150 * `enable_monitoring` - (Optional) Enables/disables detailed monitoring. This is enabled by default. 151 * `ebs_optimized` - (Optional) If true, the launched EC2 instance will be EBS-optimized. 152 * `root_block_device` - (Optional) Customize details about the root block 153 device of the instance. See [Block Devices](#block-devices) below for details. 154 * `ebs_block_device` - (Optional) Additional EBS block devices to attach to the 155 instance. See [Block Devices](#block-devices) below for details. 156 * `ephemeral_block_device` - (Optional) Customize Ephemeral (also known as 157 "Instance Store") volumes on the instance. See [Block Devices](#block-devices) below for details. 158 * `spot_price` - (Optional) The price to use for reserving spot instances. 159 * `placement_tenancy` - (Optional) The tenancy of the instance. Valid values are 160 `"default"` or `"dedicated"`, see [AWS's Create Launch Configuration](http://docs.aws.amazon.com/AutoScaling/latest/APIReference/API_CreateLaunchConfiguration.html) 161 for more details 162 163 ## Block devices 164 165 Each of the `*_block_device` attributes controls a portion of the AWS 166 Launch Configuration's "Block Device Mapping". It's a good idea to familiarize yourself with [AWS's Block Device 167 Mapping docs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html) 168 to understand the implications of using these attributes. 169 170 The `root_block_device` mapping supports the following: 171 172 * `volume_type` - (Optional) The type of volume. Can be `"standard"`, `"gp2"`, 173 or `"io1"`. (Default: `"standard"`). 174 * `volume_size` - (Optional) The size of the volume in gigabytes. 175 * `iops` - (Optional) The amount of provisioned 176 [IOPS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-io-characteristics.html). 177 This must be set with a `volume_type` of `"io1"`. 178 * `delete_on_termination` - (Optional) Whether the volume should be destroyed 179 on instance termination (Default: `true`). 180 181 Modifying any of the `root_block_device` settings requires resource 182 replacement. 183 184 Each `ebs_block_device` supports the following: 185 186 * `device_name` - (Required) The name of the device to mount. 187 * `snapshot_id` - (Optional) The Snapshot ID to mount. 188 * `volume_type` - (Optional) The type of volume. Can be `"standard"`, `"gp2"`, 189 or `"io1"`. (Default: `"standard"`). 190 * `volume_size` - (Optional) The size of the volume in gigabytes. 191 * `iops` - (Optional) The amount of provisioned 192 [IOPS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-io-characteristics.html). 193 This must be set with a `volume_type` of `"io1"`. 194 * `delete_on_termination` - (Optional) Whether the volume should be destroyed 195 on instance termination (Default: `true`). 196 * `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`). 197 198 Modifying any `ebs_block_device` currently requires resource replacement. 199 200 Each `ephemeral_block_device` supports the following: 201 202 * `device_name` - The name of the block device to mount on the instance. 203 * `virtual_name` - The [Instance Store Device 204 Name](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#InstanceStoreDeviceNames) 205 (e.g. `"ephemeral0"`) 206 207 Each AWS Instance type has a different set of Instance Store block devices 208 available for attachment. AWS [publishes a 209 list](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#StorageOnInstanceTypes) 210 of which ephemeral devices are available on each type. The devices are always 211 identified by the `virtual_name` in the format `"ephemeral{0..N}"`. 212 213 ~> **NOTE:** Changes to `*_block_device` configuration of _existing_ resources 214 cannot currently be detected by Terraform. After updating to block device 215 configuration, resource recreation can be manually triggered by using the 216 [`taint` command](/docs/commands/taint.html). 217 218 ## Attributes Reference 219 220 The following attributes are exported: 221 222 * `id` - The ID of the launch configuration. 223 * `name` - The name of the launch configuration. 224 225 [1]: /docs/providers/aws/r/autoscaling_group.html 226 [2]: /docs/configuration/resources.html#lifecycle 227 [3]: /docs/providers/aws/r/spot_instance_request.html 228 229 ## Import 230 231 Launch configurations can be imported using the `name`, e.g. 232 233 ``` 234 $ terraform import aws_launch_configuration.as_conf terraform-lg-123456 235 ```