Terraform Module for AWS Launch Template
This is a stable example. It should successfully build out of the box
This examples does is built on Construct Libraries marked "Stable" and does not have any infrastructure prerequisites to build.
This module may be used to create Launch Template resources in AWS cloud provider......
This module needs Terraform 0.12.19 or newer. You can download the latest Terraform version from here.
This module deploys aws services details are in respective feature branches.
Below we are able to check the resources that are being created as part of this module call:
- Launch Template
To use this module, add the following call to your code:
module "launch_template" {
source = "git::https://github.com/nitinda/terraform-module-aws-launch-template.git?ref=master"
providers = {
aws = aws.services
}
name_prefix = "lt-"
description = "EC2 Launch Template"
ebs_optimized = true
image_id = var.image_id
monitoring = { enabled = false }
tags = var.tags
vpc_security_group_ids = [ var.vpc_security_group_ids ]
user_data = base64encode("${data.template_file.template_data.rendered}")
iam_instance_profile = { name = module.iam_instance_profile_ec2.name }
block_device_mappings = []
tag_specifications = [
{
resource_type = "instance"
tags = merge(var.common_tags, map("Name", "demo-ec2-instance",))
},
{
resource_type = "volume"
tags = merge(var.common_tags, map("Name", "demo-ec2-instance-volume",))
}
]
}
module "launch_template" {
source = "git::https://github.com/nitinda/terraform-module-aws-launch-template.git?ref=master"
providers = {
aws = aws.services
}
name_prefix = "lt-"
description = "RabbitMQ EC2 Launch Template"
ebs_optimized = true
image_id = data.aws_ami.ami_ubuntu.id
vpc_security_group_ids = [ module.security_group_ec2.id ]
user_data = base64encode("${data.template_file.template_data.rendered}")
iam_instance_profile = [
{
name = module.iam_instance_profile_ec2.name
}
]
block_device_mappings = [
{
device_name = "/dev/sda1"
ebs = {
volume_size = 20
}
},
{
device_name = "/dev/sdf"
ebs = {
volume_size = 20
}
}
]
tag_specifications = [
{
resource_type = "instance"
tags = merge(var.common_tags, map("Name", "ec2-instance",))
},
{
resource_type = "volume"
tags = merge(var.common_tags, map("Name", "ec2-instance-volume",))
}
]
tags = merge(
var.common_tags,
{
Environment = "prod"
Name = "iam-role-ec2"
}
)
}
The variables required in order for the module to be successfully called from the deployment repository are the following:
Variable | Description | Type | Argument Status | Default Value |
---|---|---|---|---|
name | The name of the launch template | string | Optional | null |
name_prefix | Creates a unique name beginning with the specified prefix | string | Optional | null |
description | Description of the launch template | string | Optional | null |
block_device_mappings | Specify volumes to attach to the instance besides the volumes specified by the AMI | any | Optional | [] |
capacity_reservation_specification | Targeting for EC2 capacity reservations | any | Optional | {} |
cpu_options | _The CPU options for the instance | any | Optional | {} |
credit_specification | Customize the credit specification of the instance | map(string) | Optional | {} |
disable_api_termination | If true, enables EC2 Instance Termination Protection | boolean | Optional | false |
ebs_optimized | If true, the launched instance will be EBS Optimized | boolean | Optional | [] |
elastic_gpu_specifications | The elastic GPU to attach to the instance | any | Optional | {} |
elastic_inference_accelerator | Configuration block containing an Elastic Inference Accelerator to attach to the instance |
any | Optional | {} |
iam_instance_profile | The IAM Instance Profile to launch the instance with | map(string) | Optional | {} |
image_id | The AMI id | string | Required | |
instance_initiated_shutdown_behavior | Shutdown behavior for the instance | string | Optional | stop |
instance_market_options | The market (purchasing) option for the instance | any | Optional | {} |
instance_type | The type of the instance | string | Optional | null |
kernel_id | The kernel ID | string | Optional | null |
key_name | The key name to use for the instance | string | Optional | null |
license_specification | A list of license specifications to associate with | map(string) | Optional | {} |
metadata_options | Customize the metadata options for the instance | any | Optional | {} |
monitoring | The monitoring option for the instance. See Monitoring below for more details | map(string) | Optional | {} |
network_interfaces | Customize network interfaces to be attached at instance boot time | any | Optional | {} |
placement | The placement of the instance | any | Optional | {} |
ram_disk_id | The ID of the RAM disk | string | Optional | null |
security_group_names | A list of security group names to associate with | any | Optional | [] |
vpc_security_group_ids | A list of security group IDs to associate with | list(string) | Optional | [] |
tag_specifications | The tags to apply to the resources during launch | any | Optional | [] |
tags | A mapping of tags to assign to the launch template | map(string) | Optional | {} |
user_data | The Base64-encoded user data to provide when launching the instance | string | Optional | null |
hibernation_options | The hibernation options for the instance | any | Optional | {} |
This module has the following outputs:
- latest_version
- id
- arn
In order for the variables to be accessed on module level please use the syntax below:
module.<module_name>.<output_variable_name>
The output variable is able to be accessed through terraform state file using the syntax below:
data.terraform_remote_state.<module_name>.<output_variable_name>
Module maintained by Module maintained by the - Nitin Das