Output Order in specific order

Hi Team,

I have terraform config file (version 0.12.20)which creates ec2 instance. In the last I am displaying its IP’s. I want to display order in a certain order.

For example

Outputs:

Bart_SERVER_IP = “172.22.16.219”

Master-IP = “172.22.16.218”

PEM-IP = “172.22.16.222”

SSH-USER = “demo”

Slave1-IP = “172.22.14.189”

Slave2-IP = “172.22.16.217”

To

Outputs:

Bart_SERVER_IP = “172.22.16.219”

Master-IP = “172.22.16.218”

Slave1-IP = “172.22.14.189”

Slave2-IP = “172.22.16.217”

PEM-IP = “172.22.16.222”

SSH-USER = “root”

============

Terraform alphabetically sorts outputs by resource address, and there is not a way to change that behavior.

Hi there, yes the output is ordered, but you can use the heredoc output to order your outputs.

# main.tf

locals {
  lowest_number = min(10, 24, 4)
  ceil_number   = ceil(6.4)
  pow_number    = pow(2, 4)
  length        = 7
  pet_prefix    = upper("pet")
}

resource "random_pet" "server_name" {
  length = local.lowest_number
}

resource "random_pet" "server_name_two" {
  length = local.ceil_number
}

resource "random_pet" "server_name_three" {
  length = local.pow_number
}

resource "random_pet" "server_name_four" {
  prefix = local.pet_prefix
  length = local.length
}

output "random_pet" {
  value = random_pet.server_name.id
}

output "random_pet_two" {
  value = random_pet.server_name_two.id
}

output "random_pet_three" {
  value = random_pet.server_name_three.id
}

output "random_pet_four" {
  value = random_pet.server_name_four.id
}

output "ordered" {
  value = <<ORDERED
${random_pet.server_name.id}
${random_pet.server_name_two.id}
${random_pet.server_name_three.id}
${random_pet.server_name_four.id}
ORDERED
}