O'Reilly logo

Getting Started with Terraform - Second Edition by Kirill Shirinkin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Returning data with outputs

We've already talked very briefly about outputs in previous chapters. By this time, you should already know what they are. However, let's recap their usage anyway.

Outputs allow the returning of data from the Terraform template after it was applied using the terraform output command. For example, to return the IP address of an EC2 instance, we could define an output as follows:

output "public_ip" { 
   value = "${aws_instance.web-server.public_ip}" 
} 

That allows us to easily pass this data to other scripts and tools. For example, with this approach, we could run tests against our servers. Enter Inspec.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required