Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Terraform Resource Types and Names
📖 Scenario: You are setting up a simple cloud infrastructure using Terraform. You need to define resources with correct types and names to create a virtual machine and a storage bucket.
🎯 Goal: Build a Terraform configuration that defines an aws_instance resource named web_server and an aws_s3_bucket resource named app_bucket.
📋 What You'll Learn
Create an aws_instance resource with the name web_server.
Create an aws_s3_bucket resource with the name app_bucket.
Use valid Terraform syntax for resource blocks.
Use the exact resource types and names as specified.
💡 Why This Matters
🌍 Real World
Terraform is widely used to automate cloud infrastructure setup. Defining resources with correct types and names is the first step to managing cloud services like virtual machines and storage.
💼 Career
Cloud engineers and DevOps professionals use Terraform daily to create and maintain infrastructure as code, ensuring consistent and repeatable deployments.
Progress0 / 4 steps
1
Create an AWS instance resource
Create a Terraform resource block for an AWS instance with the resource type aws_instance and the resource name web_server. Set the ami attribute to "ami-12345678" and the instance_type attribute to "t2.micro".
Terraform
Hint
Use the resource keyword, then the resource type aws_instance, followed by the resource name web_server in quotes.
2
Create an S3 bucket resource
Add a Terraform resource block for an AWS S3 bucket with the resource type aws_s3_bucket and the resource name app_bucket. Set the bucket attribute to "my-app-bucket".
Terraform
Hint
Use the resource keyword with type aws_s3_bucket and name app_bucket. Set the bucket attribute inside.
3
Add tags to the AWS instance
Inside the aws_instance resource named web_server, add a tags block with a tag Name set to "WebServerInstance".
Terraform
Hint
Use a tags block with key-value pairs inside the aws_instance resource.
4
Add versioning to the S3 bucket
Inside the aws_s3_bucket resource named app_bucket, add a versioning block with enabled set to true.
Terraform
Hint
Use a versioning block inside the aws_s3_bucket resource with enabled = true.
Practice
(1/5)
1. What does the resource block in Terraform define?
Terraform requires both resource type and name to be quoted strings.
Step 2: Identify the error
The resource name my_bucket is not quoted, causing a syntax error.
Final Answer:
Resource name is not quoted -> Option A
Quick Check:
Resource names must be quoted strings [OK]
Hint: Always quote resource names to avoid syntax errors [OK]
Common Mistakes:
Forgetting quotes around resource names
Assuming attributes cause errors
Thinking provider block is mandatory here
5. You want to create two AWS EC2 instances with different names but the same type in Terraform. Which is the best way to name the resources?
hard
A. resource "aws_instance" "aws_instance" {} and resource "aws_instance" "aws_instance" {}
B. resource "aws_instance" "app1" {} and resource "aws_instance" "app2" {}
C. resource "aws_instance" "1" {} and resource "aws_instance" "2" {}
D. resource "aws_instance" "instance" {} and resource "aws_instance" "instance" {}
Solution
Step 1: Understand resource naming rules
Resource names must be unique within the same type to avoid conflicts.
Step 2: Evaluate naming options
resource "aws_instance" "app1" {} and resource "aws_instance" "app2" {} uses unique, descriptive names app1 and app2. Choices that reuse the same name cause errors. The choice using numeric names is valid but less descriptive.
Final Answer:
resource "aws_instance" "app1" {} and resource "aws_instance" "app2" {} -> Option B
Quick Check:
Unique descriptive names prevent conflicts [OK]
Hint: Use unique, clear names for each resource [OK]