How to format an object in the Terraform output?

Asked

Viewed 26 times

0

I’m using the Terraform to climb my below in the Linode, everything goes very well, however, I am not able to format the output the way you would like it. My Output Variables is like this:

output "info" {
  value = {
    for vm in linode_instance.vm:
    vm.label => vm.ip_address
  }
}

The above code gives me an output as can be observed below:

info = {
  "jenkins-master" = "74.272.12.15"
  "jenkins-slave" = "50.163.31.24"
}

But I’d like something close to that:

info = [{
  "label" = "jenkins-master"
  "ip"    = "74.272.12.15"
},{
 "label" = "jenkins-slave"
  "ip"   = "50.163.31.24"
}]

Terraform offers features that allow you to format the output in this way? How to do this?

1 answer

0

I was able to solve it by making it create as many objects as needed within the list/array. Code:

output "info" {
  value = [for vm in linode_instance.vm : {
    label = vm.label
    ip    = vm.ip_address
  }]
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.