Commit 4a082edb authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

Terraform 0.12 update (#93)

parent cab232de
repos: repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform - repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.7.3 rev: v1.12.0
hooks: hooks:
- id: terraform_fmt - id: terraform_fmt
- id: terraform_docs # - id: terraform_docs
- repo: git://github.com/pre-commit/pre-commit-hooks - repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0 rev: v2.2.3
hooks: hooks:
- id: check-merge-conflict - id: check-merge-conflict
...@@ -17,7 +17,7 @@ Terraform 0.11. Pin module version to `~> v1.0`. Submit pull-requests to `terraf ...@@ -17,7 +17,7 @@ Terraform 0.11. Pin module version to `~> v1.0`. Submit pull-requests to `terraf
```hcl ```hcl
module "ec2_cluster" { module "ec2_cluster" {
source = "terraform-aws-modules/ec2-instance/aws" source = "terraform-aws-modules/ec2-instance/aws"
version = "1.22.0" version = "~> 2.0"
name = "my-cluster" name = "my-cluster"
instance_count = 5 instance_count = 5
......
...@@ -10,7 +10,7 @@ data "aws_vpc" "default" { ...@@ -10,7 +10,7 @@ data "aws_vpc" "default" {
} }
data "aws_subnet_ids" "all" { data "aws_subnet_ids" "all" {
vpc_id = "${data.aws_vpc.default.id}" vpc_id = data.aws_vpc.default.id
} }
data "aws_ami" "amazon_linux" { data "aws_ami" "amazon_linux" {
...@@ -37,11 +37,11 @@ data "aws_ami" "amazon_linux" { ...@@ -37,11 +37,11 @@ data "aws_ami" "amazon_linux" {
module "security_group" { module "security_group" {
source = "terraform-aws-modules/security-group/aws" source = "terraform-aws-modules/security-group/aws"
version = "2.7.0" version = "~> 3.0"
name = "example" name = "example"
description = "Security group for example usage with EC2 instance" description = "Security group for example usage with EC2 instance"
vpc_id = "${data.aws_vpc.default.id}" vpc_id = data.aws_vpc.default.id
ingress_cidr_blocks = ["0.0.0.0/0"] ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["http-80-tcp", "all-icmp"] ingress_rules = ["http-80-tcp", "all-icmp"]
...@@ -50,7 +50,7 @@ module "security_group" { ...@@ -50,7 +50,7 @@ module "security_group" {
resource "aws_eip" "this" { resource "aws_eip" "this" {
vpc = true vpc = true
instance = "${module.ec2.id[0]}" instance = module.ec2.id[0]
} }
module "ec2" { module "ec2" {
...@@ -59,16 +59,23 @@ module "ec2" { ...@@ -59,16 +59,23 @@ module "ec2" {
instance_count = 2 instance_count = 2
name = "example-normal" name = "example-normal"
ami = "${data.aws_ami.amazon_linux.id}" ami = data.aws_ami.amazon_linux.id
instance_type = "m4.large" instance_type = "c5.large"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}" subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"] vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true associate_public_ip_address = true
root_block_device = [{ root_block_device = [
{
volume_type = "gp2" volume_type = "gp2"
volume_size = 10 volume_size = 10
}] },
]
tags = {
"Env" = "Private"
"Location" = "Secret"
}
} }
module "ec2_with_t2_unlimited" { module "ec2_with_t2_unlimited" {
...@@ -77,11 +84,11 @@ module "ec2_with_t2_unlimited" { ...@@ -77,11 +84,11 @@ module "ec2_with_t2_unlimited" {
instance_count = 1 instance_count = 1
name = "example-t2-unlimited" name = "example-t2-unlimited"
ami = "${data.aws_ami.amazon_linux.id}" ami = data.aws_ami.amazon_linux.id
instance_type = "t2.micro" instance_type = "t2.micro"
cpu_credits = "unlimited" cpu_credits = "unlimited"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}" subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"] vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true associate_public_ip_address = true
} }
...@@ -91,10 +98,11 @@ module "ec2_with_t3_unlimited" { ...@@ -91,10 +98,11 @@ module "ec2_with_t3_unlimited" {
instance_count = 1 instance_count = 1
name = "example-t3-unlimited" name = "example-t3-unlimited"
ami = "${data.aws_ami.amazon_linux.id}" ami = data.aws_ami.amazon_linux.id
instance_type = "t3.large" instance_type = "t3.large"
cpu_credits = "unlimited" cpu_credits = "unlimited"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}" subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"] vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true associate_public_ip_address = true
} }
output "ids" { output "ids" {
description = "List of IDs of instances" description = "List of IDs of instances"
value = "${module.ec2.id}" value = module.ec2.id
} }
output "ids_t2" { output "ids_t2" {
description = "List of IDs of t2-type instances" description = "List of IDs of t2-type instances"
value = "${module.ec2_with_t2_unlimited.id}" value = module.ec2_with_t2_unlimited.id
} }
output "public_dns" { output "public_dns" {
description = "List of public DNS names assigned to the instances" description = "List of public DNS names assigned to the instances"
value = "${module.ec2.public_dns}" value = module.ec2.public_dns
} }
output "vpc_security_group_ids" { output "vpc_security_group_ids" {
description = "List of VPC security group ids assigned to the instances" description = "List of VPC security group ids assigned to the instances"
value = "${module.ec2.vpc_security_group_ids}" value = module.ec2.vpc_security_group_ids
} }
output "tags" { output "tags" {
description = "List of tags" description = "List of tags"
value = "${module.ec2.tags}" value = module.ec2.tags
} }
output "instance_id" { output "instance_id" {
description = "EC2 instance ID" description = "EC2 instance ID"
value = "${module.ec2.id[0]}" value = module.ec2.id[0]
}
output "t2_instance_id" {
description = "EC2 instance ID"
value = module.ec2_with_t2_unlimited.id[0]
} }
output "instance_public_dns" { output "instance_public_dns" {
description = "Public DNS name assigned to the EC2 instance" description = "Public DNS name assigned to the EC2 instance"
value = "${module.ec2.public_dns[0]}" value = module.ec2.public_dns[0]
} }
output "credit_specification" { output "credit_specification" {
description = "Credit specification of EC2 instance (empty list for not t2 instance types)" description = "Credit specification of EC2 instance (empty list for not t2 instance types)"
value = "${module.ec2.credit_specification}" value = module.ec2.credit_specification
} }
output "credit_specification_t2_unlimited" { output "credit_specification_t2_unlimited" {
description = "Credit specification of t2-type EC2 instance" description = "Credit specification of t2-type EC2 instance"
value = "${module.ec2_with_t2_unlimited.credit_specification}" value = module.ec2_with_t2_unlimited.credit_specification
} }
...@@ -14,12 +14,14 @@ data "aws_vpc" "default" { ...@@ -14,12 +14,14 @@ data "aws_vpc" "default" {
} }
data "aws_subnet_ids" "all" { data "aws_subnet_ids" "all" {
vpc_id = "${data.aws_vpc.default.id}" vpc_id = data.aws_vpc.default.id
} }
data "aws_ami" "amazon_linux" { data "aws_ami" "amazon_linux" {
most_recent = true most_recent = true
owners = ["amazon"]
filter { filter {
name = "name" name = "name"
...@@ -39,11 +41,11 @@ data "aws_ami" "amazon_linux" { ...@@ -39,11 +41,11 @@ data "aws_ami" "amazon_linux" {
module "security_group" { module "security_group" {
source = "terraform-aws-modules/security-group/aws" source = "terraform-aws-modules/security-group/aws"
version = "2.7.0" version = "~> 3.0"
name = "example" name = "example"
description = "Security group for example usage with EC2 instance" description = "Security group for example usage with EC2 instance"
vpc_id = "${data.aws_vpc.default.id}" vpc_id = data.aws_vpc.default.id
ingress_cidr_blocks = ["0.0.0.0/0"] ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["http-80-tcp", "all-icmp"] ingress_rules = ["http-80-tcp", "all-icmp"]
...@@ -53,27 +55,27 @@ module "security_group" { ...@@ -53,27 +55,27 @@ module "security_group" {
module "ec2" { module "ec2" {
source = "../../" source = "../../"
instance_count = "${var.instances_number}" instance_count = var.instances_number
name = "example-with-ebs" name = "example-with-ebs"
ami = "${data.aws_ami.amazon_linux.id}" ami = data.aws_ami.amazon_linux.id
instance_type = "m4.large" instance_type = "c5.large"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}" subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"] vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true associate_public_ip_address = true
} }
resource "aws_volume_attachment" "this_ec2" { resource "aws_volume_attachment" "this_ec2" {
count = "${var.instances_number}" count = var.instances_number
device_name = "/dev/sdh" device_name = "/dev/sdh"
volume_id = "${aws_ebs_volume.this.*.id[count.index]}" volume_id = aws_ebs_volume.this[count.index].id
instance_id = "${module.ec2.id[count.index]}" instance_id = module.ec2.id[count.index]
} }
resource "aws_ebs_volume" "this" { resource "aws_ebs_volume" "this" {
count = "${var.instances_number}" count = var.instances_number
availability_zone = "${module.ec2.availability_zone[count.index]}" availability_zone = module.ec2.availability_zone[count.index]
size = 1 size = 1
} }
output "instances_public_ips" { output "instances_public_ips" {
description = "Public IPs assigned to the EC2 instance" description = "Public IPs assigned to the EC2 instance"
value = "${module.ec2.public_ip}" value = module.ec2.public_ip
} }
output "ebs_volume_attachment_id" { output "ebs_volume_attachment_id" {
description = "The volume ID" description = "The volume ID"
value = "${aws_volume_attachment.this_ec2.*.volume_id}" value = aws_volume_attachment.this_ec2.*.volume_id
} }
output "ebs_volume_attachment_instance_id" { output "ebs_volume_attachment_instance_id" {
description = "The instance ID" description = "The instance ID"
value = "${aws_volume_attachment.this_ec2.*.instance_id}" value = aws_volume_attachment.this_ec2.*.instance_id
} }
locals { locals {
is_t_instance_type = "${replace(var.instance_type, "/^t[23]{1}\\..*$/", "1") == "1" ? "1" : "0"}" is_t_instance_type = replace(var.instance_type, "/^t[23]{1}\\..*$/", "1") == "1" ? 1 : 0
instance_count = var.instance_count * (1 - local.is_t_instance_type)
t_instance_count = var.instance_count * local.is_t_instance_type
} }
###### ######
# Note: network_interface can't be specified together with associate_public_ip_address # Note: network_interface can't be specified together with associate_public_ip_address
###### ######
resource "aws_instance" "this" { resource "aws_instance" "this" {
count = "${var.instance_count * (1 - local.is_t_instance_type)}" count = local.instance_count > 0 ? local.instance_count : 0
ami = "${var.ami}" ami = var.ami
instance_type = "${var.instance_type}" instance_type = var.instance_type
user_data = "${var.user_data}" user_data = var.user_data
subnet_id = "${element(distinct(compact(concat(list(var.subnet_id), var.subnet_ids))),count.index)}" subnet_id = element(
key_name = "${var.key_name}" distinct(compact(concat([var.subnet_id], var.subnet_ids))),
monitoring = "${var.monitoring}" count.index,
vpc_security_group_ids = ["${var.vpc_security_group_ids}"] )
iam_instance_profile = "${var.iam_instance_profile}" key_name = var.key_name
monitoring = var.monitoring
associate_public_ip_address = "${var.associate_public_ip_address}" vpc_security_group_ids = var.vpc_security_group_ids
private_ip = "${var.private_ip}" iam_instance_profile = var.iam_instance_profile
ipv6_address_count = "${var.ipv6_address_count}"
ipv6_addresses = "${var.ipv6_addresses}" associate_public_ip_address = var.associate_public_ip_address
private_ip = var.private_ip
ebs_optimized = "${var.ebs_optimized}" ipv6_address_count = var.ipv6_address_count
volume_tags = "${var.volume_tags}" ipv6_addresses = var.ipv6_addresses
root_block_device = "${var.root_block_device}"
ebs_block_device = "${var.ebs_block_device}" ebs_optimized = var.ebs_optimized
ephemeral_block_device = "${var.ephemeral_block_device}" volume_tags = var.volume_tags
source_dest_check = "${var.source_dest_check}" dynamic "root_block_device" {
disable_api_termination = "${var.disable_api_termination}" for_each = var.root_block_device
instance_initiated_shutdown_behavior = "${var.instance_initiated_shutdown_behavior}" content {
placement_group = "${var.placement_group}" delete_on_termination = lookup(root_block_device.value, "delete_on_termination", null)
tenancy = "${var.tenancy}" iops = lookup(root_block_device.value, "iops", null)
volume_size = lookup(root_block_device.value, "volume_size", null)
tags = "${merge(map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}" volume_type = lookup(root_block_device.value, "volume_type", null)
}
}
dynamic "ebs_block_device" {
for_each = var.ebs_block_device
content {
delete_on_termination = lookup(ebs_block_device.value, "delete_on_termination", null)
device_name = ebs_block_device.value.device_name
encrypted = lookup(ebs_block_device.value, "encrypted", null)
iops = lookup(ebs_block_device.value, "iops", null)
snapshot_id = lookup(ebs_block_device.value, "snapshot_id", null)
volume_size = lookup(ebs_block_device.value, "volume_size", null)
volume_type = lookup(ebs_block_device.value, "volume_type", null)
}
}
dynamic "ephemeral_block_device" {
for_each = var.ephemeral_block_device
content {
device_name = ephemeral_block_device.value.device_name
no_device = lookup(ephemeral_block_device.value, "no_device", null)
virtual_name = lookup(ephemeral_block_device.value, "virtual_name", null)
}
}
source_dest_check = var.source_dest_check
disable_api_termination = var.disable_api_termination
instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
placement_group = var.placement_group
tenancy = var.tenancy
tags = merge(
{
"Name" = var.instance_count > 1 || var.use_num_suffix ? format("%s-%d", var.name, count.index + 1) : var.name
},
var.tags,
)
lifecycle { lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance: # Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036) # (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
# we have to ignore changes in the following arguments # we have to ignore changes in the following arguments
ignore_changes = ["private_ip", "root_block_device", "ebs_block_device"] ignore_changes = [
private_ip,
root_block_device,
ebs_block_device,
]
} }
} }
resource "aws_instance" "this_t2" { resource "aws_instance" "this_t2" {
count = "${var.instance_count * local.is_t_instance_type}" count = local.t_instance_count > 0 ? local.t_instance_count : 0
ami = "${var.ami}" ami = var.ami
instance_type = "${var.instance_type}" instance_type = var.instance_type
user_data = "${var.user_data}" user_data = var.user_data
subnet_id = "${element(distinct(compact(concat(list(var.subnet_id), var.subnet_ids))),count.index)}" subnet_id = element(
key_name = "${var.key_name}" distinct(compact(concat([var.subnet_id], var.subnet_ids))),
monitoring = "${var.monitoring}" count.index,
vpc_security_group_ids = ["${var.vpc_security_group_ids}"] )
iam_instance_profile = "${var.iam_instance_profile}" key_name = var.key_name
monitoring = var.monitoring
associate_public_ip_address = "${var.associate_public_ip_address}" vpc_security_group_ids = var.vpc_security_group_ids
private_ip = "${var.private_ip}" iam_instance_profile = var.iam_instance_profile
ipv6_address_count = "${var.ipv6_address_count}"
ipv6_addresses = "${var.ipv6_addresses}" associate_public_ip_address = var.associate_public_ip_address
private_ip = var.private_ip
ebs_optimized = "${var.ebs_optimized}" ipv6_address_count = var.ipv6_address_count
volume_tags = "${var.volume_tags}" ipv6_addresses = var.ipv6_addresses
root_block_device = "${var.root_block_device}"
ebs_block_device = "${var.ebs_block_device}" ebs_optimized = var.ebs_optimized
ephemeral_block_device = "${var.ephemeral_block_device}" volume_tags = var.volume_tags
source_dest_check = "${var.source_dest_check}" dynamic "root_block_device" {
disable_api_termination = "${var.disable_api_termination}" for_each = var.root_block_device
instance_initiated_shutdown_behavior = "${var.instance_initiated_shutdown_behavior}" content {
placement_group = "${var.placement_group}" delete_on_termination = lookup(root_block_device.value, "delete_on_termination", null)
tenancy = "${var.tenancy}" iops = lookup(root_block_device.value, "iops", null)
volume_size = lookup(root_block_device.value, "volume_size", null)
volume_type = lookup(root_block_device.value, "volume_type", null)
}
}
dynamic "ebs_block_device" {
for_each = var.ebs_block_device
content {
delete_on_termination = lookup(ebs_block_device.value, "delete_on_termination", null)
device_name = ebs_block_device.value.device_name
encrypted = lookup(ebs_block_device.value, "encrypted", null)
iops = lookup(ebs_block_device.value, "iops", null)
snapshot_id = lookup(ebs_block_device.value, "snapshot_id", null)
volume_size = lookup(ebs_block_device.value, "volume_size", null)
volume_type = lookup(ebs_block_device.value, "volume_type", null)
}
}
dynamic "ephemeral_block_device" {
for_each = var.ephemeral_block_device
content {
device_name = ephemeral_block_device.value.device_name
no_device = lookup(ephemeral_block_device.value, "no_device", null)
virtual_name = lookup(ephemeral_block_device.value, "virtual_name", null)
}
}
source_dest_check = var.source_dest_check
disable_api_termination = var.disable_api_termination
instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
placement_group = var.placement_group
tenancy = var.tenancy
credit_specification { credit_specification {
cpu_credits = "${var.cpu_credits}" cpu_credits = var.cpu_credits
} }
tags = "${merge(map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}" tags = merge(
{
"Name" = var.instance_count > 1 || var.use_num_suffix ? format("%s-%d", var.name, count.index + 1) : var.name
},
var.tags,
)
lifecycle { lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance: # Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036) # (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
# we have to ignore changes in the following arguments # we have to ignore changes in the following arguments
ignore_changes = ["private_ip", "root_block_device", "ebs_block_device"] ignore_changes = [
private_ip,
root_block_device,
ebs_block_device,
]
} }
} }
locals { locals {
this_id = "${compact(concat(coalescelist(aws_instance.this.*.id, aws_instance.this_t2.*.id), list("")))}" this_id = compact(coalescelist(aws_instance.this.*.id, aws_instance.this_t2.*.id, [""]))
this_availability_zone = "${compact(concat(coalescelist(aws_instance.this.*.availability_zone, aws_instance.this_t2.*.availability_zone), list("")))}" this_availability_zone = compact(coalescelist(aws_instance.this.*.availability_zone, aws_instance.this_t2.*.availability_zone, [""]))
this_key_name = "${compact(concat(coalescelist(aws_instance.this.*.key_name, aws_instance.this_t2.*.key_name), list("")))}" this_key_name = compact(coalescelist(aws_instance.this.*.key_name, aws_instance.this_t2.*.key_name, [""]))
this_public_dns = "${compact(concat(coalescelist(aws_instance.this.*.public_dns, aws_instance.this_t2.*.public_dns), list("")))}" this_public_dns = compact(coalescelist(aws_instance.this.*.public_dns, aws_instance.this_t2.*.public_dns, [""]))
this_public_ip = "${compact(concat(coalescelist(aws_instance.this.*.public_ip, aws_instance.this_t2.*.public_ip), list("")))}" this_public_ip = compact(coalescelist(aws_instance.this.*.public_ip, aws_instance.this_t2.*.public_ip, [""]))
this_primary_network_interface_id = "${compact(concat(coalescelist(aws_instance.this.*.primary_network_interface_id, aws_instance.this_t2.*.primary_network_interface_id), list("")))}" this_primary_network_interface_id = compact(coalescelist(aws_instance.this.*.primary_network_interface_id, aws_instance.this_t2.*.primary_network_interface_id, [""]))
this_private_dns = "${compact(concat(coalescelist(aws_instance.this.*.private_dns, aws_instance.this_t2.*.private_dns), list("")))}" this_private_dns = compact(coalescelist(aws_instance.this.*.private_dns, aws_instance.this_t2.*.private_dns, [""]))
this_private_ip = "${compact(concat(coalescelist(aws_instance.this.*.private_ip, aws_instance.this_t2.*.private_ip), list("")))}" this_private_ip = compact(coalescelist(aws_instance.this.*.private_ip, aws_instance.this_t2.*.private_ip, [""]))
this_security_groups = "${compact(concat(coalescelist(flatten(aws_instance.this.*.security_groups), flatten(aws_instance.this_t2.*.security_groups)), list("")))}" this_security_groups = coalescelist(aws_instance.this.*.security_groups, aws_instance.this_t2.*.security_groups, [""])
this_vpc_security_group_ids = "${compact(concat(coalescelist(flatten(aws_instance.this.*.vpc_security_group_ids), flatten(aws_instance.this_t2.*.vpc_security_group_ids)), list("")))}" this_vpc_security_group_ids = coalescelist(flatten(aws_instance.this.*.vpc_security_group_ids), flatten(aws_instance.this_t2.*.vpc_security_group_ids), [""])
this_subnet_id = "${compact(concat(coalescelist(aws_instance.this.*.subnet_id, aws_instance.this_t2.*.subnet_id), list("")))}" this_subnet_id = compact(coalescelist(aws_instance.this.*.subnet_id, aws_instance.this_t2.*.subnet_id, [""]))
this_credit_specification = "${aws_instance.this_t2.*.credit_specification}" this_credit_specification = aws_instance.this_t2.*.credit_specification
this_tags = "${coalescelist(flatten(aws_instance.this.*.tags), flatten(aws_instance.this_t2.*.tags))}" this_tags = coalescelist(aws_instance.this.*.tags, aws_instance.this_t2.*.tags, [""])
} }
output "id" { output "id" {
description = "List of IDs of instances" description = "List of IDs of instances"
value = ["${local.this_id}"] value = local.this_id
} }
output "availability_zone" { output "availability_zone" {
description = "List of availability zones of instances" description = "List of availability zones of instances"
value = ["${local.this_availability_zone}"] value = local.this_availability_zone
} }
// GH issue: https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/8 // GH issue: https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/8
...@@ -32,55 +32,56 @@ output "availability_zone" { ...@@ -32,55 +32,56 @@ output "availability_zone" {
output "key_name" { output "key_name" {
description = "List of key names of instances" description = "List of key names of instances"
value = ["${local.this_key_name}"] value = local.this_key_name
} }
output "public_dns" { output "public_dns" {
description = "List of public DNS names assigned to the instances. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC" description = "List of public DNS names assigned to the instances. For EC2-VPC, this is only available if you've enabled DNS hostnames for your VPC"
value = ["${local.this_public_dns}"] value = local.this_public_dns
} }
output "public_ip" { output "public_ip" {
description = "List of public IP addresses assigned to the instances, if applicable" description = "List of public IP addresses assigned to the instances, if applicable"
value = ["${local.this_public_ip}"] value = local.this_public_ip
} }
output "primary_network_interface_id" { output "primary_network_interface_id" {
description = "List of IDs of the primary network interface of instances" description = "List of IDs of the primary network interface of instances"
value = ["${local.this_primary_network_interface_id}"] value = local.this_primary_network_interface_id
} }
output "private_dns" { output "private_dns" {
description = "List of private DNS names assigned to the instances. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC" description = "List of private DNS names assigned to the instances. Can only be used inside the Amazon EC2, and only available if you've enabled DNS hostnames for your VPC"
value = ["${local.this_private_dns}"] value = local.this_private_dns
} }
output "private_ip" { output "private_ip" {
description = "List of private IP addresses assigned to the instances" description = "List of private IP addresses assigned to the instances"
value = ["${local.this_private_ip}"] value = local.this_private_ip
} }
output "security_groups" { output "security_groups" {
description = "List of associated security groups of instances" description = "List of associated security groups of instances"
value = ["${local.this_security_groups}"] value = local.this_security_groups
} }
output "vpc_security_group_ids" { output "vpc_security_group_ids" {
description = "List of associated security groups of instances, if running in non-default VPC" description = "List of associated security groups of instances, if running in non-default VPC"
value = ["${local.this_vpc_security_group_ids}"] value = local.this_vpc_security_group_ids
} }
output "subnet_id" { output "subnet_id" {
description = "List of IDs of VPC subnets of instances" description = "List of IDs of VPC subnets of instances"
value = ["${local.this_subnet_id}"] value = local.this_subnet_id
} }
output "credit_specification" { output "credit_specification" {
description = "List of credit specification of instances" description = "List of credit specification of instances"
value = ["${local.this_credit_specification}"] value = local.this_credit_specification
} }
output "tags" { output "tags" {
description = "List of tags of instances" description = "List of tags of instances"
value = ["${local.this_tags}"] value = local.this_tags
} }
variable "name" { variable "name" {
description = "Name to be used on all resources as prefix" description = "Name to be used on all resources as prefix"
type = string
} }
variable "instance_count" { variable "instance_count" {
description = "Number of instances to launch" description = "Number of instances to launch"
type = number
default = 1 default = 1
} }
variable "ami" { variable "ami" {
description = "ID of AMI to use for the instance" description = "ID of AMI to use for the instance"
type = string
} }
variable "placement_group" { variable "placement_group" {
description = "The Placement Group to start the instance in" description = "The Placement Group to start the instance in"
type = string
default = "" default = ""
} }
variable "tenancy" { variable "tenancy" {
description = "The tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host." description = "The tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host."
type = string
default = "default" default = "default"
} }
variable "ebs_optimized" { variable "ebs_optimized" {
description = "If true, the launched EC2 instance will be EBS-optimized" description = "If true, the launched EC2 instance will be EBS-optimized"
type = bool
default = false default = false
} }
variable "disable_api_termination" { variable "disable_api_termination" {
description = "If true, enables EC2 Instance Termination Protection" description = "If true, enables EC2 Instance Termination Protection"
type = bool
default = false default = false
} }
variable "instance_initiated_shutdown_behavior" { variable "instance_initiated_shutdown_behavior" {
description = "Shutdown behavior for the instance" # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingInstanceInitiatedShutdownBehavior description = "Shutdown behavior for the instance" # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingInstanceInitiatedShutdownBehavior
type = string
default = "" default = ""
} }
variable "instance_type" { variable "instance_type" {
description = "The type of instance to start" description = "The type of instance to start"
type = string
} }
variable "key_name" { variable "key_name" {
description = "The key name to use for the instance" description = "The key name to use for the instance"
type = string
default = "" default = ""
} }
variable "monitoring" { variable "monitoring" {
description = "If true, the launched EC2 instance will have detailed monitoring enabled" description = "If true, the launched EC2 instance will have detailed monitoring enabled"
type = bool
default = false default = false
} }
variable "vpc_security_group_ids" { variable "vpc_security_group_ids" {
description = "A list of security group IDs to associate with" description = "A list of security group IDs to associate with"
type = "list" type = list(string)
} }
variable "subnet_id" { variable "subnet_id" {
description = "The VPC Subnet ID to launch in" description = "The VPC Subnet ID to launch in"
type = string
default = "" default = ""
} }
variable "subnet_ids" { variable "subnet_ids" {
description = "A list of VPC Subnet IDs to launch in" description = "A list of VPC Subnet IDs to launch in"
type = list(string)
default = [] default = []
type = "list"
} }
variable "associate_public_ip_address" { variable "associate_public_ip_address" {
description = "If true, the EC2 instance will have associated public IP address" description = "If true, the EC2 instance will have associated public IP address"
type = bool
default = false default = false
} }
variable "private_ip" { variable "private_ip" {
description = "Private IP address to associate with the instance in a VPC" description = "Private IP address to associate with the instance in a VPC"
type = string
default = "" default = ""
} }
variable "source_dest_check" { variable "source_dest_check" {
description = "Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs." description = "Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs."
type = bool
default = true default = true
} }
variable "user_data" { variable "user_data" {
description = "The user data to provide when launching the instance" description = "The user data to provide when launching the instance"
type = string
default = "" default = ""
} }
variable "iam_instance_profile" { variable "iam_instance_profile" {
description = "The IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile." description = "The IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile."
type = string
default = "" default = ""
} }
variable "ipv6_address_count" { variable "ipv6_address_count" {
description = "A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet." description = "A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet."
type = number
default = 0 default = 0
} }
variable "ipv6_addresses" { variable "ipv6_addresses" {
description = "Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface" description = "Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface"
type = list(string)
default = [] default = []
} }
variable "tags" { variable "tags" {
description = "A mapping of tags to assign to the resource" description = "A mapping of tags to assign to the resource"
type = map(string)
default = {} default = {}
} }
variable "volume_tags" { variable "volume_tags" {
description = "A mapping of tags to assign to the devices created by the instance at launch time" description = "A mapping of tags to assign to the devices created by the instance at launch time"
type = map(string)
default = {} default = {}
} }
variable "root_block_device" { variable "root_block_device" {
description = "Customize details about the root block device of the instance. See Block Devices below for details" description = "Customize details about the root block device of the instance. See Block Devices below for details"
type = list(map(string))
default = [] default = []
} }
variable "ebs_block_device" { variable "ebs_block_device" {
description = "Additional EBS block devices to attach to the instance" description = "Additional EBS block devices to attach to the instance"
type = list(map(string))
default = [] default = []
} }
variable "ephemeral_block_device" { variable "ephemeral_block_device" {
description = "Customize Ephemeral (also known as Instance Store) volumes on the instance" description = "Customize Ephemeral (also known as Instance Store) volumes on the instance"
type = list(map(string))
default = [] default = []
} }
variable "network_interface" { variable "network_interface" {
description = "Customize network interfaces to be attached at instance boot time" description = "Customize network interfaces to be attached at instance boot time"
type = list(map(string))
default = [] default = []
} }
variable "cpu_credits" { variable "cpu_credits" {
description = "The credit option for CPU usage (unlimited or standard)" description = "The credit option for CPU usage (unlimited or standard)"
type = string
default = "standard" default = "standard"
} }
variable "use_num_suffix" { variable "use_num_suffix" {
description = "Always append numerical suffix to instance name, even if instance_count is 1" description = "Always append numerical suffix to instance name, even if instance_count is 1"
default = "false" type = bool
default = false
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment