0
0
Terraformcloud~30 mins

Why outputs expose useful information in Terraform - See It in Action

Choose your learning style9 modes available
Why outputs expose useful information
📖 Scenario: You are setting up a simple cloud infrastructure using Terraform. You want to create a virtual machine and then expose its IP address as an output. This output will help you easily find the IP address after deployment without searching through the cloud console.
🎯 Goal: Create a Terraform configuration that defines a virtual machine resource and exposes its public IP address using an output variable.
📋 What You'll Learn
Create a resource block for a virtual machine named example_vm.
Define an output variable named vm_ip that exposes the public IP address of example_vm.
💡 Why This Matters
🌍 Real World
Outputs help you quickly find important details like IP addresses after deploying cloud resources, saving time and effort.
💼 Career
Knowing how to expose useful information with outputs is essential for cloud engineers to manage and share infrastructure details effectively.
Progress0 / 4 steps
1
Create a virtual machine resource
Create a resource block named example_vm of type aws_instance with the ami set to "ami-0c55b159cbfafe1f0" and instance_type set to "t2.micro".
Terraform
Need a hint?

Use the resource keyword to define the virtual machine with the exact name and properties.

2
Add a configuration variable for the output
Create an output block named vm_ip but leave the value empty for now.
Terraform
Need a hint?

Use the output keyword and give it the name vm_ip. Set value to an empty string for now.

3
Set the output value to the VM's public IP
Set the value of the output vm_ip to the public IP address of the example_vm resource using aws_instance.example_vm.public_ip.
Terraform
Need a hint?

Use the resource reference aws_instance.example_vm.public_ip to get the public IP address.

4
Add a description to the output
Add a description to the output vm_ip with the text "The public IP address of the example VM".
Terraform
Need a hint?

Add the description attribute inside the output block with the exact text.