Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added placement groups #94

Merged
merged 2 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ data "aws_ami" "ubuntu-xenial" {
| credit\_specification | List of credit specification of instances |
| id | List of IDs 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 |
| 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 |
Expand Down
1 change: 1 addition & 0 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Note that this example may create resources which can cost money. Run `terraform
| ids\_t2 | List of IDs of t2-type instances |
| instance\_id | EC2 instance ID |
| instance\_public\_dns | Public DNS name assigned to the EC2 instance |
| placement\_group | List of placement group |
| public\_dns | List of public DNS names assigned to the instances |
| tags | List of tags |
| vpc\_security\_group\_ids | List of VPC security group ids assigned to the instances |
Expand Down
8 changes: 7 additions & 1 deletion examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data "aws_ami" "amazon_linux" {

module "security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "2.7.0"
version = "~> 2.0"

name = "example"
description = "Security group for example usage with EC2 instance"
Expand All @@ -53,6 +53,11 @@ resource "aws_eip" "this" {
instance = "${module.ec2.id[0]}"
}

resource "aws_placement_group" "web" {
name = "hunky-dory-pg"
strategy = "cluster"
}

module "ec2" {
source = "../../"

Expand All @@ -64,6 +69,7 @@ module "ec2" {
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
associate_public_ip_address = true
placement_group = "${aws_placement_group.web.id}"

root_block_device = [{
volume_type = "gp2"
Expand Down
5 changes: 5 additions & 0 deletions examples/basic/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ output "tags" {
value = "${module.ec2.tags}"
}

output "placement_group" {
description = "List of placement group"
value = "${module.ec2.placement_group}"
}

output "instance_id" {
description = "EC2 instance ID"
value = "${module.ec2.id[0]}"
Expand Down
10 changes: 5 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ locals {
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_private_dns = "${compact(concat(coalescelist(aws_instance.this.*.private_dns, aws_instance.this_t2.*.private_dns), list("")))}"
this_private_ip = "${compact(concat(coalescelist(aws_instance.this.*.private_ip, aws_instance.this_t2.*.private_ip), list("")))}"
this_placement_group = "${compact(concat(coalescelist(aws_instance.this.*.placement_group, aws_instance.this_t2.*.placement_group), list("")))}"
this_security_groups = "${compact(concat(coalescelist(flatten(aws_instance.this.*.security_groups), flatten(aws_instance.this_t2.*.security_groups)), list("")))}"
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_subnet_id = "${compact(concat(coalescelist(aws_instance.this.*.subnet_id, aws_instance.this_t2.*.subnet_id), list("")))}"
Expand All @@ -25,11 +26,10 @@ output "availability_zone" {
value = ["${local.this_availability_zone}"]
}

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

output "key_name" {
description = "List of key names of instances"
Expand Down