Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b637021

Browse files
Added support for placement group and volume tags (terraform-aws-modules#96)
1 parent b7b8b4a commit b637021

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ data "aws_ami" "ubuntu-xenial" {
135135
| credit\_specification | List of credit specification of instances |
136136
| id | List of IDs of instances |
137137
| key\_name | List of key names of instances |
138+
| placement\_group | List of placement groups of instances |
138139
| primary\_network\_interface\_id | List of IDs of the primary network interface of instances |
139140
| 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 |
140141
| private\_ip | List of private IP addresses assigned to the instances |
@@ -143,6 +144,7 @@ data "aws_ami" "ubuntu-xenial" {
143144
| security\_groups | List of associated security groups of instances |
144145
| subnet\_id | List of IDs of VPC subnets of instances |
145146
| tags | List of tags of instances |
147+
| volume\_tags | List of tags of volumes of instances |
146148
| vpc\_security\_group\_ids | List of associated security groups of instances, if running in non-default VPC |
147149

148150
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

‎examples/basic/main.tf‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ resource "aws_eip" "this" {
5353
instance = module.ec2.id[0]
5454
}
5555

56+
resource "aws_placement_group" "web" {
57+
name = "hunky-dory-pg"
58+
strategy = "cluster"
59+
}
60+
5661
module "ec2" {
5762
source = "../../"
5863

@@ -64,6 +69,7 @@ module "ec2" {
6469
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
6570
vpc_security_group_ids = [module.security_group.this_security_group_id]
6671
associate_public_ip_address = true
72+
placement_group = aws_placement_group.web.id
6773

6874
root_block_device = [
6975
{

‎examples/basic/outputs.tf‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ output "tags" {
2323
value = module.ec2.tags
2424
}
2525

26+
output "placement_group" {
27+
description = "List of placement group"
28+
value = module.ec2.placement_group
29+
}
30+
2631
output "instance_id" {
2732
description = "EC2 instance ID"
2833
value = module.ec2.id[0]

‎main.tf‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ resource "aws_instance" "this" {
2929
ipv6_addresses = var.ipv6_addresses
3030

3131
ebs_optimized = var.ebs_optimized
32-
volume_tags = var.volume_tags
3332

3433
dynamic "root_block_device" {
3534
for_each = var.root_block_device
@@ -76,6 +75,13 @@ resource "aws_instance" "this" {
7675
var.tags,
7776
)
7877

78+
volume_tags = merge(
79+
{
80+
"Name" = var.instance_count > 1 || var.use_num_suffix ? format("%s-%d", var.name, count.index + 1) : var.name
81+
},
82+
var.volume_tags,
83+
)
84+
7985
lifecycle {
8086
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
8187
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
@@ -109,7 +115,6 @@ resource "aws_instance" "this_t2" {
109115
ipv6_addresses = var.ipv6_addresses
110116

111117
ebs_optimized = var.ebs_optimized
112-
volume_tags = var.volume_tags
113118

114119
dynamic "root_block_device" {
115120
for_each = var.root_block_device
@@ -160,6 +165,13 @@ resource "aws_instance" "this_t2" {
160165
var.tags,
161166
)
162167

168+
volume_tags = merge(
169+
{
170+
"Name" = var.instance_count > 1 || var.use_num_suffix ? format("%s-%d", var.name, count.index + 1) : var.name
171+
},
172+
var.volume_tags,
173+
)
174+
163175
lifecycle {
164176
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
165177
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)

‎outputs.tf‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ locals {
77
this_primary_network_interface_id = compact(coalescelist(aws_instance.this.*.primary_network_interface_id, aws_instance.this_t2.*.primary_network_interface_id, [""]))
88
this_private_dns = compact(coalescelist(aws_instance.this.*.private_dns, aws_instance.this_t2.*.private_dns, [""]))
99
this_private_ip = compact(coalescelist(aws_instance.this.*.private_ip, aws_instance.this_t2.*.private_ip, [""]))
10+
this_placement_group = compact(concat(coalescelist(aws_instance.this.*.placement_group, aws_instance.this_t2.*.placement_group), [""]))
1011
this_security_groups = coalescelist(aws_instance.this.*.security_groups, aws_instance.this_t2.*.security_groups, [""])
1112
this_vpc_security_group_ids = coalescelist(flatten(aws_instance.this.*.vpc_security_group_ids), flatten(aws_instance.this_t2.*.vpc_security_group_ids), [""])
1213
this_subnet_id = compact(coalescelist(aws_instance.this.*.subnet_id, aws_instance.this_t2.*.subnet_id, [""]))
13-
this_credit_specification = aws_instance.this_t2.*.credit_specification
14+
this_credit_specification = flatten(aws_instance.this_t2.*.credit_specification)
1415
this_tags = coalescelist(aws_instance.this.*.tags, aws_instance.this_t2.*.tags, [""])
16+
this_volume_tags = coalescelist(aws_instance.this.*.volume_tags, aws_instance.this_t2.*.volume_tags, [""])
1517
}
1618

1719
output "id" {
@@ -24,11 +26,10 @@ output "availability_zone" {
2426
value = local.this_availability_zone
2527
}
2628

27-
// GH issue: https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/issues/8
28-
//output "placement_group" {
29-
// description = "List of placement groups of instances"
30-
// value = ["${element(concat(aws_instance.this.*.placement_group, list("")), 0)}"]
31-
//}
29+
output "placement_group" {
30+
description = "List of placement groups of instances"
31+
value = local.this_placement_group
32+
}
3233

3334
output "key_name" {
3435
description = "List of key names of instances"
@@ -85,3 +86,7 @@ output "tags" {
8586
value = local.this_tags
8687
}
8788

89+
output "volume_tags" {
90+
description = "List of tags of volumes of instances"
91+
value = local.this_volume_tags
92+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /