negabaro
negabaro

Reputation: 3965

How to display public ip of ec2_instance after terraform creation

I would like to display the public_ip of aws_instance created by terraform after terraform execution.

However, only the global IP of the first server appears.

My source code is as follows.

resource "aws_instance" "main" {
  count         = "3"
  ...
}


output "ec2_global_ips" {
  value = "${aws_instance.main.*.public_ip}"
}

Is something wrong grammar? Let me know if you have to know how to display array values as output in terraform.

Upvotes: 7

Views: 10841

Answers (2)

Akilan
Akilan

Reputation: 23

I hope this helps.

output "ec2_global_ips" {
  value = [for instance in aws_instance.main : instance.public_ip]
}

Upvotes: 1

Sai Prasad
Sai Prasad

Reputation: 735

I believe this will work:

output "ec2_global_ips" {
  value = ["${aws_instance.main.*.public_ip}"]
}

Upvotes: 13

Related Questions