2014-07-23 23:26:47 +02:00
---
layout: "aws"
page_title: "AWS: aws_launch_configuration"
2015-05-30 16:46:42 +02:00
sidebar_current: "docs-aws-resource-launch-configuration"
2014-10-22 05:21:56 +02:00
description: |-
Provides a resource to create a new launch configuration, used for autoscaling groups.
2014-07-23 23:26:47 +02:00
---
# aws\_launch\_configuration
Provides a resource to create a new launch configuration, used for autoscaling groups.
## Example Usage
```
2016-07-09 12:09:10 +02:00
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/ebs/ubuntu-trusty-14.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["paravirtual"]
}
owners = ["099720109477"] # Canonical
}
2014-07-23 23:26:47 +02:00
resource "aws_launch_configuration" "as_conf" {
name = "web_config"
2016-07-09 12:09:10 +02:00
image_id = "${data.aws_ami.ubuntu.id}"
2015-12-21 17:00:34 +01:00
instance_type = "t1.micro"
2014-07-23 23:26:47 +02:00
}
```
2015-08-12 18:00:05 +02:00
## Using with AutoScaling Groups
Launch Configurations cannot be updated after creation with the Amazon
2015-09-03 17:33:59 +02:00
Web Service API. In order to update a Launch Configuration, Terraform will
2015-09-16 20:50:19 +02:00
destroy the existing resource and create a replacement. In order to effectively
use a Launch Configuration resource with an [AutoScaling Group resource][1],
2015-11-07 08:25:07 +01:00
it's recommended to specify `create_before_destroy` in a [lifecycle][2] block.
Either omit the Launch Configuration `name` attribute, or specify a partial name
with `name_prefix` . Example:
2015-08-12 18:00:05 +02:00
```
2016-07-09 12:09:10 +02:00
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/ebs/ubuntu-trusty-14.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["paravirtual"]
}
owners = ["099720109477"] # Canonical
}
2015-08-12 18:00:05 +02:00
resource "aws_launch_configuration" "as_conf" {
2015-11-07 08:25:07 +01:00
name_prefix = "terraform-lc-example-"
2016-07-09 12:09:10 +02:00
image_id = "${data.aws_ami.ubuntu.id}"
2015-12-21 17:00:34 +01:00
instance_type = "t1.micro"
2015-08-12 18:00:05 +02:00
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "bar" {
name = "terraform-asg-example"
launch_configuration = "${aws_launch_configuration.as_conf.name}"
lifecycle {
create_before_destroy = true
}
}
```
With this setup Terraform generates a unique name for your Launch
Configuration and can then update the AutoScaling Group without conflict before
destroying the previous Launch Configuration.
2015-09-16 20:50:19 +02:00
## Using with Spot Instances
Launch configurations can set the spot instance pricing to be used for the
Auto Scaling Group to reserve instances. Simply specifying the `spot_price`
parameter will set the price on the Launch Configuration which will attempt to
reserve your instances at this price. See the [AWS Spot Instance
documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances.html)
for more information or how to launch [Spot Instances][3] with Terraform.
```
2016-07-09 12:09:10 +02:00
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/ebs/ubuntu-trusty-14.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["paravirtual"]
}
owners = ["099720109477"] # Canonical
}
2015-09-16 20:50:19 +02:00
resource "aws_launch_configuration" "as_conf" {
2016-07-09 12:09:10 +02:00
image_id = "${data.aws_ami.ubuntu.id}"
2015-12-21 17:00:34 +01:00
instance_type = "t1.micro"
2015-09-16 20:50:19 +02:00
spot_price = "0.001"
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "bar" {
name = "terraform-asg-example"
launch_configuration = "${aws_launch_configuration.as_conf.name}"
}
```
2014-07-23 23:26:47 +02:00
## Argument Reference
The following arguments are supported:
2015-04-14 01:00:29 +02:00
* `name` - (Optional) The name of the launch configuration. If you leave
2015-11-07 08:25:07 +01:00
this blank, Terraform will auto-generate a unique name.
* `name_prefix` - (Optional) Creates a unique name beginning with the specified
prefix. Conflicts with `name` .
2014-07-23 23:26:47 +02:00
* `image_id` - (Required) The EC2 image ID to launch.
* `instance_type` - (Required) The size of instance to launch.
2014-10-08 19:54:34 +02:00
* `iam_instance_profile` - (Optional) The IAM instance profile to associate
with launched instances.
2014-07-23 23:26:47 +02:00
* `key_name` - (Optional) The key name that should be used for the instance.
2015-01-14 18:28:25 +01:00
* `security_groups` - (Optional) A list of associated security group IDS.
2015-02-05 18:05:14 +01:00
* `associate_public_ip_address` - (Optional) Associate a public ip address with an instance in a VPC.
2016-07-16 16:13:29 +02:00
* `vpc_classic_link_id` - (Optional) The ID of a ClassicLink-enabled VPC. Only applies to EC2-Classic instances. (eg. `vpc-2730681a` )
* `vpc_classic_link_security_groups` - (Optional) The IDs of one or more security groups for the specified ClassicLink-enabled VPC (eg. `sg-46ae3d11` ).
2014-07-29 23:31:21 +02:00
* `user_data` - (Optional) The user data to provide when launching the instance.
2015-06-21 00:24:28 +02:00
* `enable_monitoring` - (Optional) Enables/disables detailed monitoring. This is enabled by default.
2015-07-02 02:09:04 +02:00
* `ebs_optimized` - (Optional) If true, the launched EC2 instance will be EBS-optimized.
2015-09-03 17:33:59 +02:00
* `root_block_device` - (Optional) Customize details about the root block
device of the instance. See [Block Devices ](#block-devices ) below for details.
* `ebs_block_device` - (Optional) Additional EBS block devices to attach to the
instance. See [Block Devices ](#block-devices ) below for details.
* `ephemeral_block_device` - (Optional) Customize Ephemeral (also known as
"Instance Store") volumes on the instance. See [Block Devices ](#block-devices ) below for details.
2015-09-16 20:50:19 +02:00
* `spot_price` - (Optional) The price to use for reserving spot instances.
2016-02-03 18:00:16 +01:00
* `placement_tenancy` - (Optional) The tenancy of the instance. Valid values are
`"default"` or `"dedicated"` , see [AWS's Create Launch Configuration ](http://docs.aws.amazon.com/AutoScaling/latest/APIReference/API_CreateLaunchConfiguration.html )
for more details
2015-04-02 17:47:37 +02:00
## Block devices
Each of the `*_block_device` attributes controls a portion of the AWS
Launch Configuration's "Block Device Mapping". It's a good idea to familiarize yourself with [AWS's Block Device
2016-01-14 21:55:39 +01:00
Mapping docs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html)
2015-04-02 17:47:37 +02:00
to understand the implications of using these attributes.
The `root_block_device` mapping supports the following:
* `volume_type` - (Optional) The type of volume. Can be `"standard"` , `"gp2"` ,
or `"io1"` . (Default: `"standard"` ).
* `volume_size` - (Optional) The size of the volume in gigabytes.
* `iops` - (Optional) The amount of provisioned
2016-01-14 21:55:39 +01:00
[IOPS ](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-io-characteristics.html ).
2015-04-02 17:47:37 +02:00
This must be set with a `volume_type` of `"io1"` .
* `delete_on_termination` - (Optional) Whether the volume should be destroyed
on instance termination (Default: `true` ).
Modifying any of the `root_block_device` settings requires resource
replacement.
Each `ebs_block_device` supports the following:
2015-07-07 00:32:18 +02:00
* `device_name` - (Required) The name of the device to mount.
2015-04-02 17:47:37 +02:00
* `snapshot_id` - (Optional) The Snapshot ID to mount.
* `volume_type` - (Optional) The type of volume. Can be `"standard"` , `"gp2"` ,
or `"io1"` . (Default: `"standard"` ).
* `volume_size` - (Optional) The size of the volume in gigabytes.
* `iops` - (Optional) The amount of provisioned
2016-01-14 21:55:39 +01:00
[IOPS ](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-io-characteristics.html ).
2015-04-02 17:47:37 +02:00
This must be set with a `volume_type` of `"io1"` .
* `delete_on_termination` - (Optional) Whether the volume should be destroyed
on instance termination (Default: `true` ).
2016-02-12 13:46:05 +01:00
* `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` ).
2015-04-02 17:47:37 +02:00
Modifying any `ebs_block_device` currently requires resource replacement.
Each `ephemeral_block_device` supports the following:
* `device_name` - The name of the block device to mount on the instance.
* `virtual_name` - The [Instance Store Device
2016-01-14 21:55:39 +01:00
Name](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#InstanceStoreDeviceNames)
2015-04-02 17:47:37 +02:00
(e.g. `"ephemeral0"` )
Each AWS Instance type has a different set of Instance Store block devices
available for attachment. AWS [publishes a
2016-01-14 21:55:39 +01:00
list](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#StorageOnInstanceTypes)
2015-04-02 17:47:37 +02:00
of which ephemeral devices are available on each type. The devices are always
identified by the `virtual_name` in the format `"ephemeral{0..N}"` .
2014-07-23 23:26:47 +02:00
2015-04-08 00:05:00 +02:00
~> **NOTE:** Changes to `*_block_device` configuration of _existing_ resources
cannot currently be detected by Terraform. After updating to block device
configuration, resource recreation can be manually triggered by using the
[`taint` command ](/docs/commands/taint.html ).
2014-07-23 23:26:47 +02:00
## Attributes Reference
The following attributes are exported:
* `id` - The ID of the launch configuration.
2015-08-12 18:00:05 +02:00
[1]: /docs/providers/aws/r/autoscaling_group.html
[2]: /docs/configuration/resources.html#lifecycle
2015-09-16 20:50:19 +02:00
[3]: /docs/providers/aws/r/spot_instance_request.html
2016-07-21 00:28:59 +02:00
## Import
Launch configurations can be imported using the `name` , e.g.
```
$ terraform import aws_launch_configuration.as_conf terraform-lg-123456
```