0
0
Terraformcloud~30 mins

Output declaration syntax in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Output declaration syntax
📖 Scenario: You are managing cloud infrastructure using Terraform. You want to share important information about your resources after deployment, such as IP addresses or resource IDs, so other team members or tools can use them easily.
🎯 Goal: Create a Terraform configuration that defines a resource and then declares an output to show a specific attribute of that resource after deployment.
📋 What You'll Learn
Create a Terraform resource block for an AWS EC2 instance named example_instance with the AMI ID ami-12345678 and instance type t2.micro.
Declare an output named instance_id that outputs the ID of the example_instance.
Use the correct Terraform output declaration syntax.
💡 Why This Matters
🌍 Real World
Outputs in Terraform are used to share important information about deployed resources with other team members, automation tools, or subsequent Terraform configurations.
💼 Career
Knowing how to declare and manage outputs is essential for cloud engineers and DevOps professionals to create reusable and maintainable infrastructure code.
Progress0 / 4 steps
1
Create the AWS EC2 instance resource
Create a Terraform resource block named example_instance of type aws_instance with ami set to "ami-12345678" and instance_type set to "t2.micro".
Terraform
Need a hint?

Use the resource block with the resource type aws_instance and name example_instance. Set the ami and instance_type attributes exactly as specified.

2
Add an output block declaration
Add a Terraform output block named instance_id with a value set to the ID of the example_instance resource using aws_instance.example_instance.id.
Terraform
Need a hint?

Use the output block with the name instance_id. Set the value attribute to aws_instance.example_instance.id to output the instance ID.

3
Add a description to the output
Inside the instance_id output block, add a description attribute with the text "The ID of the example instance".
Terraform
Need a hint?

Add the description attribute inside the output block to explain what the output represents.

4
Add a sensitive flag to the output
In the instance_id output block, add the attribute sensitive = true to mark the output as sensitive.
Terraform
Need a hint?

Add sensitive = true inside the output block to hide the output value from normal display.