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