0
0
Terraformcloud~20 mins

Terraform output command - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the Terraform Output Command
📖 Scenario: You are managing cloud infrastructure using Terraform. After creating resources, you want to see important information like IP addresses or resource IDs easily. Terraform's output command helps you display this information after deployment.
🎯 Goal: Build a Terraform configuration that creates a simple resource and defines an output to show a specific attribute of that resource. Learn how to declare outputs and how Terraform outputs work.
📋 What You'll Learn
Create a Terraform resource block for an AWS EC2 instance with a fixed AMI and instance type
Define an output block named instance_id that outputs the EC2 instance's ID
Use the exact resource name aws_instance.example
Use the exact output name instance_id
💡 Why This Matters
🌍 Real World
Cloud engineers often need to see key information about deployed resources quickly. Terraform outputs provide a simple way to access this information after deployment.
💼 Career
Knowing how to use Terraform outputs is essential for infrastructure as code roles, enabling automation and integration with other tools.
Progress0 / 4 steps
1
Create the AWS EC2 instance resource
Create a Terraform resource block named aws_instance with the name example. Set the ami to "ami-0c55b159cbfafe1f0" and the instance_type to "t2.micro".
Terraform
Need a hint?

Use the resource keyword, then the resource type aws_instance, then the resource name example. Inside the block, set ami and instance_type exactly as shown.

2
Add an output block for the instance ID
Add a Terraform output block named instance_id. Inside it, set the value to the ID of the EC2 instance resource you created, using aws_instance.example.id.
Terraform
Need a hint?

Use the output keyword, then the output name instance_id. Set value to aws_instance.example.id to show the instance ID.

3
Initialize Terraform and apply the configuration
Add the Terraform commands as comments to initialize the working directory and apply the configuration. Write # terraform init and # terraform apply -auto-approve as comments.
Terraform
Need a hint?

Write the commands terraform init and terraform apply -auto-approve as comments to show the steps to deploy.

4
Add an output block to show the public IP address
Add another Terraform output block named public_ip. Set its value to the public IP address of the EC2 instance using aws_instance.example.public_ip.
Terraform
Need a hint?

Use another output block named public_ip and set value to aws_instance.example.public_ip to show the instance's public IP.