Skip to content

Commit 19e0584

Browse files
jjardonantonbabenko
authored andcommitted
main.tf: Make number of instances created configurable, defaulting to 1 (#64)
1 parent 8c30ae4 commit 19e0584

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

examples/volume-attachment/main.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module "security_group" {
4949
module "ec2" {
5050
source = "../../"
5151

52-
instance_count = 1
52+
instance_count = "${var.instances_number}"
5353

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

6262
resource "aws_volume_attachment" "this_ec2" {
63+
count = "${var.instances_number}"
64+
6365
device_name = "/dev/sdh"
64-
volume_id = "${aws_ebs_volume.this.id}"
65-
instance_id = "${module.ec2.id[0]}"
66+
volume_id = "${aws_ebs_volume.this.*.id[count.index]}"
67+
instance_id = "${module.ec2.id[count.index]}"
6668
}
6769

6870
resource "aws_ebs_volume" "this" {
69-
availability_zone = "${module.ec2.availability_zone[0]}"
71+
count = "${var.instances_number}"
72+
73+
availability_zone = "${module.ec2.availability_zone[count.index]}"
7074
size = 1
7175
}

examples/volume-attachment/outputs.tf

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
output "instance_id" {
2-
description = "EC2 instance ID"
3-
value = "${module.ec2.id[0]}"
4-
}
5-
6-
output "instance_public_dns" {
7-
description = "Public DNS name assigned to the EC2 instance"
8-
value = "${module.ec2.public_dns[0]}"
1+
output "instances_public_ips" {
2+
description = "Public IPs assigned to the EC2 instance"
3+
value = "${module.ec2.public_ip}"
94
}
105

116
output "ebs_volume_attachment_id" {
127
description = "The volume ID"
13-
value = "${aws_volume_attachment.this_ec2.volume_id}"
8+
value = "${aws_volume_attachment.this_ec2.*.volume_id}"
149
}
1510

1611
output "ebs_volume_attachment_instance_id" {
1712
description = "The instance ID"
18-
value = "${aws_volume_attachment.this_ec2.instance_id}"
13+
value = "${aws_volume_attachment.this_ec2.*.instance_id}"
1914
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variable "instances_number" {
2+
default = 1
3+
}

0 commit comments

Comments
 (0)