Commit b637021c authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

Added support for placement group and volume tags (#96)

parent b7b8b4ac
...@@ -135,6 +135,7 @@ data "aws_ami" "ubuntu-xenial" { ...@@ -135,6 +135,7 @@ data "aws_ami" "ubuntu-xenial" {
| credit\_specification | List of credit specification of instances | | credit\_specification | List of credit specification of instances |
| id | List of IDs of instances | | id | List of IDs of instances |
| key\_name | List of key names of instances | | key\_name | List of key names of instances |
| placement\_group | List of placement groups of instances |
| primary\_network\_interface\_id | List of IDs of the primary network interface of instances | | primary\_network\_interface\_id | List of IDs of the primary network interface of instances |
| private\_dns | 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 | | private\_dns | 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 |
| private\_ip | List of private IP addresses assigned to the instances | | private\_ip | List of private IP addresses assigned to the instances |
...@@ -143,6 +144,7 @@ data "aws_ami" "ubuntu-xenial" { ...@@ -143,6 +144,7 @@ data "aws_ami" "ubuntu-xenial" {
| security\_groups | List of associated security groups of instances | | security\_groups | List of associated security groups of instances |
| subnet\_id | List of IDs of VPC subnets of instances | | subnet\_id | List of IDs of VPC subnets of instances |
| tags | List of tags of instances | | tags | List of tags of instances |
| volume\_tags | List of tags of volumes of instances |
| vpc\_security\_group\_ids | List of associated security groups of instances, if running in non-default VPC | | vpc\_security\_group\_ids | List of associated security groups of instances, if running in non-default VPC |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
......
...@@ -53,6 +53,11 @@ resource "aws_eip" "this" { ...@@ -53,6 +53,11 @@ resource "aws_eip" "this" {
instance = module.ec2.id[0] instance = module.ec2.id[0]
} }
resource "aws_placement_group" "web" {
name = "hunky-dory-pg"
strategy = "cluster"
}
module "ec2" { module "ec2" {
source = "../../" source = "../../"
...@@ -64,6 +69,7 @@ module "ec2" { ...@@ -64,6 +69,7 @@ module "ec2" {
subnet_id = tolist(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
placement_group = aws_placement_group.web.id
root_block_device = [ root_block_device = [
{ {
......
...@@ -23,6 +23,11 @@ output "tags" { ...@@ -23,6 +23,11 @@ output "tags" {
value = module.ec2.tags value = module.ec2.tags
} }
output "placement_group" {
description = "List of placement group"
value = module.ec2.placement_group
}
output "instance_id" { output "instance_id" {
description = "EC2 instance ID" description = "EC2 instance ID"
value = module.ec2.id[0] value = module.ec2.id[0]
......
...@@ -29,7 +29,6 @@ resource "aws_instance" "this" { ...@@ -29,7 +29,6 @@ resource "aws_instance" "this" {
ipv6_addresses = var.ipv6_addresses ipv6_addresses = var.ipv6_addresses
ebs_optimized = var.ebs_optimized ebs_optimized = var.ebs_optimized
volume_tags = var.volume_tags
dynamic "root_block_device" { dynamic "root_block_device" {
for_each = var.root_block_device for_each = var.root_block_device
...@@ -76,6 +75,13 @@ resource "aws_instance" "this" { ...@@ -76,6 +75,13 @@ resource "aws_instance" "this" {
var.tags, var.tags,
) )
volume_tags = merge(
{
"Name" = var.instance_count > 1 || var.use_num_suffix ? format("%s-%d", var.name, count.index + 1) : var.name
},
var.volume_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)
...@@ -109,7 +115,6 @@ resource "aws_instance" "this_t2" { ...@@ -109,7 +115,6 @@ resource "aws_instance" "this_t2" {
ipv6_addresses = var.ipv6_addresses ipv6_addresses = var.ipv6_addresses
ebs_optimized = var.ebs_optimized ebs_optimized = var.ebs_optimized
volume_tags = var.volume_tags
dynamic "root_block_device" { dynamic "root_block_device" {
for_each = var.root_block_device for_each = var.root_block_device
...@@ -160,6 +165,13 @@ resource "aws_instance" "this_t2" { ...@@ -160,6 +165,13 @@ resource "aws_instance" "this_t2" {
var.tags, var.tags,
) )
volume_tags = merge(
{
"Name" = var.instance_count > 1 || var.use_num_suffix ? format("%s-%d", var.name, count.index + 1) : var.name
},
var.volume_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)
......
...@@ -7,11 +7,13 @@ locals { ...@@ -7,11 +7,13 @@ locals {
this_primary_network_interface_id = compact(coalescelist(aws_instance.this.*.primary_network_interface_id, aws_instance.this_t2.*.primary_network_interface_id, [""])) 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(coalescelist(aws_instance.this.*.private_dns, aws_instance.this_t2.*.private_dns, [""])) this_private_dns = compact(coalescelist(aws_instance.this.*.private_dns, aws_instance.this_t2.*.private_dns, [""]))
this_private_ip = compact(coalescelist(aws_instance.this.*.private_ip, aws_instance.this_t2.*.private_ip, [""])) this_private_ip = compact(coalescelist(aws_instance.this.*.private_ip, aws_instance.this_t2.*.private_ip, [""]))
this_placement_group = compact(concat(coalescelist(aws_instance.this.*.placement_group, aws_instance.this_t2.*.placement_group), [""]))
this_security_groups = coalescelist(aws_instance.this.*.security_groups, aws_instance.this_t2.*.security_groups, [""]) this_security_groups = coalescelist(aws_instance.this.*.security_groups, aws_instance.this_t2.*.security_groups, [""])
this_vpc_security_group_ids = coalescelist(flatten(aws_instance.this.*.vpc_security_group_ids), flatten(aws_instance.this_t2.*.vpc_security_group_ids), [""]) 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(coalescelist(aws_instance.this.*.subnet_id, aws_instance.this_t2.*.subnet_id, [""])) 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 = flatten(aws_instance.this_t2.*.credit_specification)
this_tags = coalescelist(aws_instance.this.*.tags, aws_instance.this_t2.*.tags, [""]) this_tags = coalescelist(aws_instance.this.*.tags, aws_instance.this_t2.*.tags, [""])
this_volume_tags = coalescelist(aws_instance.this.*.volume_tags, aws_instance.this_t2.*.volume_tags, [""])
} }
output "id" { output "id" {
...@@ -24,11 +26,10 @@ output "availability_zone" { ...@@ -24,11 +26,10 @@ output "availability_zone" {
value = local.this_availability_zone value = local.this_availability_zone
} }
// GH issue: https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/8 output "placement_group" {
//output "placement_group" { description = "List of placement groups of instances"
// description = "List of placement groups of instances" value = local.this_placement_group
// value = ["${element(concat(aws_instance.this.*.placement_group, list("")), 0)}"] }
//}
output "key_name" { output "key_name" {
description = "List of key names of instances" description = "List of key names of instances"
...@@ -85,3 +86,7 @@ output "tags" { ...@@ -85,3 +86,7 @@ output "tags" {
value = local.this_tags value = local.this_tags
} }
output "volume_tags" {
description = "List of tags of volumes of instances"
value = local.this_volume_tags
}
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