Terraform output

449 views
Skip to first unread message

Harish Kalyanaraman

unread,
Jan 3, 2017, 4:13:37 AM1/3/17
to Terraform
I have launched multiple instances and I am getting outputs in a comma separated manner using the following output module .

output "instance_ips" {
 value = ["${aws_instance.docker.*.public_ip}"]
}

I would need to assign these IP's in a variable array and reference it elsewhere . How do I approach this as looping is not available in terraform asaik .

Lowe Schmidt

unread,
Jan 3, 2017, 5:09:49 AM1/3/17
to terrafo...@googlegroups.com
It's easier to help you if you can show where and how you want to use it.

In general you would use it like "${module.mymodule.instance_ips}" to get the values somewhere else. 

--
Lowe Schmidt | +46 723 867 157

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/cac98258-814e-43e4-ac2d-6125f9cfae81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harish Kalyanaraman

unread,
Jan 3, 2017, 5:49:50 AM1/3/17
to Terraform
Let me elaborate it a little more . I am writing a  bash script to store the ips in a particular way . Something of this format given below .

for((i=1;i<=$count;i++))
do
 echo "http://$(/home/ec2-user/terraform output instance_ips)" >> output.txt
done

Now terraform output instance_ips gives multiple values stored in the list . So for me to complete the loop correctly i need to reference the individual values stored in the list and I am not sure how to reference it in terraform .

On Tuesday, January 3, 2017 at 3:39:49 PM UTC+5:30, Lowe Schmidt wrote:
It's easier to help you if you can show where and how you want to use it.

In general you would use it like "${module.mymodule.instance_ips}" to get the values somewhere else. 

--
Lowe Schmidt | +46 723 867 157

On 3 January 2017 at 10:13, Harish Kalyanaraman <harish.ka...@gmail.com> wrote:
I have launched multiple instances and I am getting outputs in a comma separated manner using the following output module .

output "instance_ips" {
 value = ["${aws_instance.docker.*.public_ip}"]
}

I would need to assign these IP's in a variable array and reference it elsewhere . How do I approach this as looping is not available in terraform asaik .

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.

Lowe Schmidt

unread,
Jan 3, 2017, 6:31:12 AM1/3/17
to terrafo...@googlegroups.com
Is you're problem with the bash script or with terraform? 

For storing all the IP's in a text file, 

terraform output instance_ips >> outputs.txt 

will suffice, you may want to strip commas with sed or something like that.

--
Lowe Schmidt | +46 723 867 157

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/4f8ef40c-2c04-41ab-931a-1046bf59e49e%40googlegroups.com.

Harish Kalyanaraman

unread,
Jan 3, 2017, 6:40:31 AM1/3/17
to Terraform
I want to reference the individual ip's out of this which would be called in the bash script as I have mentioned . I want my output like this



Lowe Schmidt

unread,
Jan 3, 2017, 6:48:31 AM1/3/17
to terrafo...@googlegroups.com
Something like this ? 

for i in $(tf output "Private IPs"); do echo http://${i//,}; done 


--
Lowe Schmidt | +46 723 867 157

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/684adde6-61f3-4edc-aed1-4b65ea780641%40googlegroups.com.

Harish Kalyanaraman

unread,
Jan 3, 2017, 7:25:01 AM1/3/17
to Terraform
It is working . I didn't think of using this approach .Thanks a lot for your help Lowe :) . 

Lowe Schmidt

unread,
Jan 4, 2017, 6:36:33 AM1/4/17
to terrafo...@googlegroups.com

--
Lowe Schmidt | +46 723 867 157

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/27585264-c212-49a1-ac64-51b5a94ba977%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages