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