Reputation: 3965
I would like to add different messages to the output results of the server I made first and the server I made the second and later, and display it.
What I want to do is as follows finally.
output
ec2global_ips [
manager_ip is : xxx,
node ip is: [xxx,xxx]
]
currently my output.tf code is as follows.
output "ec2_global_ips" {
value = ["${aws_instance.main.*.public_ip}"]
}
For that, I think that it is necessary to judge somewhere aws_instance.main.0.public_ip
or aws_instance.main.1.public_ip
and put another value
Is there a way to make such a thing with terraform? The var.count function could not be used in output.tf etc.
Upvotes: 0
Views: 213
Reputation: 521
You can use the slice and element interpolations (code untested):
output "ec2_global_ips" {
value = "${
map(
"manager_ip", "${element(aws_instance.main.*.public_ip, 0)}"
"node_ips", "${slice(aws_instance.main.*.public_ip, 1, length(aws_instance.main.*.public_ip))}"
)
}"
}
Judging by your desired output it looks like you're looking for manager_ip to be a string (hence the element and not a slice for it) and node_ips to be a list. This should give you what you're looking for.
Upvotes: 1