0
0
Terraformcloud~30 mins

Resource arguments and attributes in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform Resource Arguments and Attributes
📖 Scenario: You are setting up a simple cloud infrastructure using Terraform. You want to create a virtual machine instance with specific settings and then access its attributes to use elsewhere in your configuration.
🎯 Goal: Build a Terraform configuration that defines a virtual machine resource with given arguments and then outputs one of its attributes.
📋 What You'll Learn
Create a resource block for an AWS EC2 instance named example.
Set the ami argument to "ami-0c55b159cbfafe1f0".
Set the instance_type argument to "t2.micro".
Create an output named instance_id that outputs the instance's ID attribute.
💡 Why This Matters
🌍 Real World
Terraform is widely used to automate cloud infrastructure setup. Defining resources with arguments and accessing their attributes is fundamental to managing cloud environments.
💼 Career
Cloud engineers and DevOps professionals use Terraform to create and manage infrastructure efficiently and reproducibly.
Progress0 / 4 steps
1
Create the AWS EC2 instance resource
Create a Terraform resource block named aws_instance with the resource name example. Set the ami argument to "ami-0c55b159cbfafe1f0" and the instance_type argument to "t2.micro".
Terraform
Need a hint?

Use the resource keyword followed by the resource type aws_instance and the name example. Inside the block, set the ami and instance_type arguments exactly as specified.

2
Add a tag argument to the instance
Inside the aws_instance.example resource block, add a tags argument with a map containing Name = "ExampleInstance".
Terraform
Need a hint?

Use the tags argument with curly braces to define a map. Inside, set the key Name to the value "ExampleInstance".

3
Create an output for the instance ID
Create an output block named instance_id that outputs the attribute id of the resource aws_instance.example.
Terraform
Need a hint?

Use the output keyword with the name instance_id. Inside, set value to aws_instance.example.id to get the instance's ID.

4
Add a provider block for AWS
Add a provider block for aws with the region set to "us-east-1".
Terraform
Need a hint?

Use the provider block with the name aws. Inside, set the region argument to "us-east-1".