awscc_ec2_launch_template (Resource)

Specifies the properties for creating a launch template. The minimum required properties for specifying a launch template are as follows:

A launch template can contain some or all of the configuration information to launch an instance. When you launch an instance using a launch template, instance properties that are not specified in the launch template use default values, except the ImageId property, which has no default value. If you do not specify an AMI ID for the launch template ImageId property, you must specify an AMI ID for the instance ImageId property. For more information, see Launch an instance from a launch template in the Amazon EC2 User Guide.

Example Usage

Launch template from latest Amazon Linux AMI

To use awscc_ec2_launch_template to launch the latest Amazon Linux AMI

resource "awscc_ec2_launch_template" "amazon_linux" {
  launch_template_data = {
    image_id      = data.aws_ami.amazon_linux.id
    instance_type = "t2.micro"
  }
  launch_template_name = "latest_amazon_linux"
}

data "aws_ami" "amazon_linux" {
  most_recent = true
  owners      = ["amazon"]
  filter {
    name   = "name"
    values = ["amzn2-ami-hvm-*-gp2"]
  }

  filter {
    name   = "root-device-type"
    values = ["ebs"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  filter {
    name   = "architecture"
    values = ["x86_64"]
  }
}

Launch template with defined block device mapping

The following awscc_ec2_launch_template with block device mapping and detailed monitoring enabled

resource "awscc_ec2_launch_template" "block_device" {
  launch_template_data = {
    image_id = data.aws_ami.amazon_linux.id
    block_device_mappings = [
      {
        ebs = {
          volume_size         = 30
          volume_type         = "gp3"
          delete_on_terminate = true
          encrypted           = true
        }
        device_name = "/dev/xvdcz"
      }
    ]
    monitoring = {
      enabled = true
    }
    instance_type = "t2.micro"
  }
  launch_template_name = "with_block_device"
}

Launch template with public IP assigned

The following awscc_ec2_launch_template with public IP assigned for EC2 Auto Scaling Group. Note that when you specify a network interface for Amazon EC2 Auto Scaling, specify the VPC subnets as properties of the Auto Scaling group, and not in the launch template (because they will be ignored).

resource "awscc_ec2_launch_template" "with eip" {
  launch_template_data = {
    image_id = data.aws_ami.amazon_linux.id
    network_interfaces = [
      {
        device_index                = 0
        associate_public_ip_address = true
        delete_on_termination       = true
        groups = [
          "sg-example1",
          "sg-example2"
        ]
      }
    ]
    monitoring = {
      enabled = true
    }
    instance_type = "t2.micro"
  }
  launch_template_name = "with_eip"
}

Schema

Required

Optional

Read-Only

Nested Schema for launch_template_data

Optional:

Nested Schema for launch_template_data.block_device_mappings

Optional: md5-eed5e538204e98babb37817004c06889

Nested Schema for launch_template_data.block_device_mappings.ebs

Optional: md5-7b7767e26449fd97dc2227207e340cc4

For io2 volumes, you can achieve up to 256,000 IOPS on instances built on the Nitro System. On other instances, you can achieve performance up to 32,000 IOPS. This parameter is supported for io1, io2, and gp3 volumes only.

  • kms_key_id (String) The ARN of the symmetric KMSlong (KMS) CMK used for encryption.
  • snapshot_id (String) The ID of the snapshot.
  • throughput (Number) The throughput to provision for a gp3 volume, with a maximum of 1,000 MiB/s. Valid Range: Minimum value of 125. Maximum value of 1000.
  • volume_size (Number) The size of the volume, in GiBs. You must specify either a snapshot ID or a volume size. The following are the supported volumes sizes for each volume type: md5-7a5a0db446dd5621a08c29fa481dcfdc

    Nested Schema for launch_template_data.capacity_reservation_specification

    Optional: md5-75a448a74883493014e4c3527a1bb44c

    Nested Schema for launch_template_data.capacity_reservation_specification.capacity_reservation_target

    Optional: md5-99275e71f870c9c83626c155635f2973

    Nested Schema for launch_template_data.cpu_options

    Optional: md5-b062592c62e50a335e6196fedbb1811c

    Nested Schema for launch_template_data.credit_specification

    Optional: md5-940288df61e553b7a78321b0bf980dd9

    Nested Schema for launch_template_data.elastic_gpu_specifications

    Optional: md5-71b6ec9d81bfeb559bb192441b5641a0

    Nested Schema for launch_template_data.elastic_inference_accelerators

    Optional: md5-784d49ccb833849be5593382ef6c21ac

    Nested Schema for launch_template_data.enclave_options

    Optional: md5-8311ead25fba4c8c209c33ce812e68ca

    Nested Schema for launch_template_data.hibernation_options

    Optional: md5-320379716a864f678f5eead56d4ba219

    Nested Schema for launch_template_data.iam_instance_profile

    Optional: md5-055fb33f5c78f4f960d7054f640c8295

    Nested Schema for launch_template_data.instance_market_options

    Optional: md5-579867a736272504f7734c3ab1a25b97

    Nested Schema for launch_template_data.instance_market_options.spot_options

    Optional: md5-01fe848e97213837b03376d2d1da5217

    Default: 7 days from the current date

  • Nested Schema for launch_template_data.instance_requirements

    Optional: md5-22c4e8f1e100dbbbc97b6b6f9549ee11

    Default: Any manufacturer

  • accelerator_names (List of String) The accelerators that must be on the instance type.

    Default: Any accelerator

  • accelerator_total_memory_mi_b (Attributes) The minimum and maximum amount of total accelerator memory, in MiB. Default: No minimum or maximum limits (see below for nested schema)
  • accelerator_types (List of String) The accelerator types that must be on the instance type.

    Default: Any accelerator type

  • allowed_instance_types (List of String) The instance types to apply your specified attributes against. All other instance types are ignored, even if they match your specified attributes. You can use strings with one or more wild cards, represented by an asterisk (*), to allow an instance type, size, or generation. The following are examples: m5.8xlarge, c5*.*, m5a.*, r*, *3*. For example, if you specify c5*,Amazon EC2 will allow the entire C5 instance family, which includes all C5a and C5n instance types. If you specify m5a.*, Amazon EC2 will allow all the M5a instance types, but not the M5n instance types. If you specify AllowedInstanceTypes, you can't specify ExcludedInstanceTypes. Default: All instance types
  • bare_metal (String) Indicates whether bare metal instance types must be included, excluded, or required.

    Default: excluded

  • baseline_ebs_bandwidth_mbps (Attributes) The minimum and maximum baseline bandwidth to Amazon EBS, in Mbps. For more information, see Amazon EBS–optimized instances in the Amazon EC2 User Guide. Default: No minimum or maximum limits (see below for nested schema)
  • burstable_performance (String) Indicates whether burstable performance T instance types are included, excluded, or required. For more information, see Burstable performance instances.

    Default: excluded

  • cpu_manufacturers (List of String) The CPU manufacturers to include.

    Don't confuse the CPU manufacturer with the CPU architecture. Instances will be launched with a compatible CPU architecture based on the Amazon Machine Image (AMI) that you specify in your launch template. Default: Any manufacturer

  • excluded_instance_types (List of String) The instance types to exclude. You can use strings with one or more wild cards, represented by an asterisk (*), to exclude an instance type, size, or generation. The following are examples: m5.8xlarge, c5*.*, m5a.*, r*, *3*. For example, if you specify c5*,Amazon EC2 will exclude the entire C5 instance family, which includes all C5a and C5n instance types. If you specify m5a.*, Amazon EC2 will exclude all the M5a instance types, but not the M5n instance types. If you specify ExcludedInstanceTypes, you can't specify AllowedInstanceTypes. Default: No excluded instance types
  • instance_generations (List of String) Indicates whether current or previous generation instance types are included. The current generation instance types are recommended for use. Current generation instance types are typically the latest two to three generations in each instance family. For more information, see Instance types in the Amazon EC2 User Guide. For current generation instance types, specify current. For previous generation instance types, specify previous. Default: Current and previous generation instance types
  • local_storage (String) Indicates whether instance types with instance store volumes are included, excluded, or required. For more information, Amazon EC2 instance store in the Amazon EC2 User Guide.

    Default: included

  • local_storage_types (List of String) The type of local storage that is required.

    Default: hdd and ssd

  • max_spot_price_as_percentage_of_optimal_on_demand_price (Number) [Price protection] The price protection threshold for Spot Instances, as a percentage of an identified On-Demand price. The identified On-Demand price is the price of the lowest priced current generation C, M, or R instance type with your specified attributes. If no current generation C, M, or R instance type matches your attributes, then the identified price is from the lowest priced current generation instance types, and failing that, from the lowest priced previous generation instance types that match your attributes. When Amazon EC2 selects instance types with your attributes, it will exclude instance types whose price exceeds your specified threshold. The parameter accepts an integer, which Amazon EC2 interprets as a percentage. If you set DesiredCapacityType to vcpu or memory-mib, the price protection threshold is based on the per vCPU or per memory price instead of the per instance price. Only one of SpotMaxPricePercentageOverLowestPrice or MaxSpotPriceAsPercentageOfOptimalOnDemandPrice can be specified. If you don't specify either, Amazon EC2 will automatically apply optimal price protection to consistently select from a wide range of instance types. To indicate no price protection threshold for Spot Instances, meaning you want to consider all instance types that match your attributes, include one of these parameters and specify a high value, such as 999999.
  • memory_gi_b_per_v_cpu (Attributes) The minimum and maximum amount of memory per vCPU, in GiB. Default: No minimum or maximum limits (see below for nested schema)
  • memory_mi_b (Attributes) The minimum and maximum amount of memory, in MiB. (see below for nested schema)
  • network_bandwidth_gbps (Attributes) The minimum and maximum amount of network bandwidth, in gigabits per second (Gbps). Default: No minimum or maximum limits (see below for nested schema)
  • network_interface_count (Attributes) The minimum and maximum number of network interfaces. Default: No minimum or maximum limits (see below for nested schema)
  • on_demand_max_price_percentage_over_lowest_price (Number) [Price protection] The price protection threshold for On-Demand Instances, as a percentage higher than an identified On-Demand price. The identified On-Demand price is the price of the lowest priced current generation C, M, or R instance type with your specified attributes. When Amazon EC2 selects instance types with your attributes, it will exclude instance types whose price exceeds your specified threshold. The parameter accepts an integer, which Amazon EC2 interprets as a percentage. To turn off price protection, specify a high value, such as 999999. This parameter is not supported for GetSpotPlacementScores and GetInstanceTypesFromInstanceRequirements. If you set TargetCapacityUnitType to vcpu or memory-mib, the price protection threshold is applied based on the per-vCPU or per-memory price instead of the per-instance price. Default: 20
  • require_hibernate_support (Boolean) Indicates whether instance types must support hibernation for On-Demand Instances. This parameter is not supported for GetSpotPlacementScores. Default: false
  • spot_max_price_percentage_over_lowest_price (Number) [Price protection] The price protection threshold for Spot Instances, as a percentage higher than an identified Spot price. The identified Spot price is the Spot price of the lowest priced current generation C, M, or R instance type with your specified attributes. If no current generation C, M, or R instance type matches your attributes, then the identified Spot price is from the lowest priced current generation instance types, and failing that, from the lowest priced previous generation instance types that match your attributes. When Amazon EC2 selects instance types with your attributes, it will exclude instance types whose Spot price exceeds your specified threshold. The parameter accepts an integer, which Amazon EC2 interprets as a percentage. If you set TargetCapacityUnitType to vcpu or memory-mib, the price protection threshold is applied based on the per-vCPU or per-memory price instead of the per-instance price. This parameter is not supported for GetSpotPlacementScores and GetInstanceTypesFromInstanceRequirements. Only one of SpotMaxPricePercentageOverLowestPrice or MaxSpotPriceAsPercentageOfOptimalOnDemandPrice can be specified. If you don't specify either, Amazon EC2 will automatically apply optimal price protection to consistently select from a wide range of instance types. To indicate no price protection threshold for Spot Instances, meaning you want to consider all instance types that match your attributes, include one of these parameters and specify a high value, such as 999999. Default: 100
  • total_local_storage_gb (Attributes) The minimum and maximum amount of total local storage, in GB. Default: No minimum or maximum limits (see below for nested schema)
  • v_cpu_count (Attributes) The minimum and maximum number of vCPUs. (see below for nested schema)
  • Nested Schema for launch_template_data.instance_requirements.accelerator_count

    Optional:

    Nested Schema for launch_template_data.instance_requirements.accelerator_total_memory_mi_b

    Optional:

    Nested Schema for launch_template_data.instance_requirements.baseline_ebs_bandwidth_mbps

    Optional:

    Nested Schema for launch_template_data.instance_requirements.memory_gi_b_per_v_cpu

    Optional:

    Nested Schema for launch_template_data.instance_requirements.memory_mi_b

    Optional:

    Nested Schema for launch_template_data.instance_requirements.network_bandwidth_gbps

    Optional:

    Nested Schema for launch_template_data.instance_requirements.network_interface_count

    Optional:

    Nested Schema for launch_template_data.instance_requirements.total_local_storage_gb

    Optional:

    Nested Schema for launch_template_data.instance_requirements.v_cpu_count

    Optional:

    Nested Schema for launch_template_data.license_specifications

    Optional:

    Nested Schema for launch_template_data.maintenance_options

    Optional:

    Nested Schema for launch_template_data.metadata_options

    Optional:

    Nested Schema for launch_template_data.monitoring

    Optional:

    Nested Schema for launch_template_data.network_interfaces

    Optional:

    Nested Schema for launch_template_data.network_interfaces.connection_tracking_specification

    Optional:

    Nested Schema for launch_template_data.network_interfaces.ena_srd_specification

    Optional:

    Nested Schema for launch_template_data.network_interfaces.ena_srd_specification.ena_srd_udp_specification

    Optional:

    Nested Schema for launch_template_data.network_interfaces.ipv_4_prefixes

    Optional:

    Nested Schema for launch_template_data.network_interfaces.ipv_6_addresses

    Optional:

    Nested Schema for launch_template_data.network_interfaces.ipv_6_prefixes

    Optional:

    Nested Schema for launch_template_data.network_interfaces.private_ip_addresses

    Optional:

    Nested Schema for launch_template_data.placement

    Optional:

    Nested Schema for launch_template_data.private_dns_name_options

    Optional:

    Nested Schema for launch_template_data.tag_specifications

    Optional:

    Nested Schema for launch_template_data.tag_specifications.tags

    Required:

    Nested Schema for tag_specifications

    Optional:

    Nested Schema for tag_specifications.tags

    Required:

    Import

    Import is supported using the following syntax:

    $ terraform import awscc_ec2_launch_template.example <resource ID>