Hello.
I’m trying to output two values at the same line, however I can’t manager to do ti. Can anyone give me a hand? Thank you
I did try to use locals, merge the values, but none worked as expected or give a different error.
What I’m trying to accomplish is to show the server name and the IP, something similar to this
linux-server-0: 123.123.123.123
linux-server-1: 234.234.234.234
...
linux-server-5: 888.888.888.888
AWS Resource code
resource "aws_instance" "server" {
ami = "ami-0fa19aa4b897d0a15"
instance_type = var.server_instance_type
key_name = aws_key_pair.generated_key.key_name
subnet_id = "subnet-123456"
vpc_security_group_ids = ["sg-1234567890123"] #
count = var.server_count
user_data = templatefile("./config.yaml", {
serv_name = "${var.name}-server-${count.index}"
})
tags = {
Name = "${var.name}-server-${count.index}"
Terraform = "true"
}
This is the output code
output "Servers" {
value = "${aws_instance.linux_server[*].tags.Name} ${aws_instance.linux_server[*].public_ip}"
}
The output result is displayed correctly (what I expect) if I change the asterisk (*) for the index number, for instance:
aws_instance.linux_server[0].tags.Name
And this is the error when I run plan:
╷
│ Error: Invalid template interpolation value
│
│ on main.tf line 121, in output "Servers":
│ 121: value = "${aws_instance.linux_server[*].tags.Name} ${aws_instance.linux_server[*].public_ip}"
│ ├────────────────
│ │ aws_instance.linux_server is tuple with 2 elements
│
│ Cannot include the given value in a string template: string required.
Terraform v1.4.6 on darwin_arm64