Skip to content

Commit

Permalink
main.tf: Make number of instances created configurable, defaulting to…
Browse files Browse the repository at this point in the history
  • Loading branch information
jjardon authored and antonbabenko committed Mar 22, 2019
1 parent 39ed89c commit e088fb8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
12 changes: 8 additions & 4 deletions examples/volume-attachment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module "security_group" {
module "ec2" {
source = "../../"

instance_count = 1
instance_count = "${var.instances_number}"

name = "example-with-ebs"
ami = "${data.aws_ami.amazon_linux.id}"
Expand All @@ -60,12 +60,16 @@ module "ec2" {
}

resource "aws_volume_attachment" "this_ec2" {
count = "${var.instances_number}"

device_name = "/dev/sdh"
volume_id = "${aws_ebs_volume.this.id}"
instance_id = "${module.ec2.id[0]}"
volume_id = "${aws_ebs_volume.this.*.id[count.index]}"
instance_id = "${module.ec2.id[count.index]}"
}

resource "aws_ebs_volume" "this" {
availability_zone = "${module.ec2.availability_zone[0]}"
count = "${var.instances_number}"

availability_zone = "${module.ec2.availability_zone[count.index]}"
size = 1
}
15 changes: 5 additions & 10 deletions examples/volume-attachment/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
output "instance_id" {
description = "EC2 instance ID"
value = "${module.ec2.id[0]}"
}

output "instance_public_dns" {
description = "Public DNS name assigned to the EC2 instance"
value = "${module.ec2.public_dns[0]}"
output "instances_public_ips" {
description = "Public IPs assigned to the EC2 instance"
value = "${module.ec2.public_ip}"
}

output "ebs_volume_attachment_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" {
description = "The instance ID"
value = "${aws_volume_attachment.this_ec2.instance_id}"
value = "${aws_volume_attachment.this_ec2.*.instance_id}"
}
3 changes: 3 additions & 0 deletions examples/volume-attachment/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "instances_number" {
default = 1
}

0 comments on commit e088fb8

Please sign in to comment.