Istvan
Istvan

Reputation: 8562

Is it possible to output all of the EC2 instances that are created in a loop with Terraform?

I am creating many nodes with Terraform loops like the following:

resource "aws_instance" "dev-cluster" {
  ami                  = "${lookup(var.amis, var.region)}"
  instance_type        = "${var.instance_type}"
  count                = 13
  subnet_id            = "${var.global-private-subnet-1a-id}"
}

Is there a way to output all of these instance ids somehow in the outputs.tf?

I was trying but the output is empty

output "aws_ec2_instance_ids" {
  value = "${aws_instance.dev-cluster.*.id}"
}

Upvotes: 0

Views: 711

Answers (1)

Ignacio Millán
Ignacio Millán

Reputation: 8026

As aws_instance.dev-cluster.*.id returns multiple values, the output is an array and it must be inside brackets:

output "aws_ec2_instance_ids" {
  value = ["${aws_instance.dev-cluster.*.id}"]
}

Upvotes: 3

Related Questions