How to ouput two values from tuples? Server name and IP


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-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    = "${}-server-${count.index}"
  tags = {
    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:


And this is the error when I run plan:

│ Error: Invalid template interpolation value
│   on 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

Found it :grin:

output "Name_IP" {
  value = (formatlist(
    "%s: %s",