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
Recall & Review
beginner
What is a resource in Terraform?
A resource in Terraform is a block that describes one piece of infrastructure, like a server, database, or network. It tells Terraform what to create or manage.
Click to reveal answer
beginner
Why are resources considered the core of Terraform?
Resources are the core because they define the actual infrastructure components Terraform manages. Without resources, Terraform has nothing to create or change.
Click to reveal answer
intermediate
How does Terraform use resources to manage infrastructure?
Terraform reads resource blocks to understand what infrastructure to build or update. It compares the current state with the desired state defined by resources and makes changes accordingly.
Click to reveal answer
beginner
Can Terraform work without resources? Why or why not?
No, Terraform cannot work without resources because resources are what describe the infrastructure to manage. They are the instructions Terraform follows to create or update infrastructure.
Resources describe infrastructure components like servers or databases that Terraform manages.
Why are resources essential in Terraform?
AThey run Terraform commands
BThey store user credentials
CThey define the infrastructure Terraform manages
DThey provide cloud billing info
✗ Incorrect
Resources tell Terraform what infrastructure to create or update, making them essential.
What happens if you remove all resource blocks from a Terraform configuration?
ATerraform updates the cloud provider
BTerraform has no infrastructure to manage
CTerraform runs faster
DTerraform creates default resources
✗ Incorrect
Without resources, Terraform has no instructions to create or manage infrastructure.
Which of these is a valid Terraform resource type?
Aaws_instance
Bterraform_function
Ccloud_user
Dnetwork_protocol
✗ Incorrect
aws_instance is a common resource type representing a virtual server in AWS.
How does Terraform know what changes to make to infrastructure?
ABy checking cloud billing reports
BBy reading user emails
CBy scanning network traffic
DBy comparing resource definitions with current state
✗ Incorrect
Terraform compares the desired state from resources with the current state to decide changes.
Explain why resources are the core of Terraform and how they relate to infrastructure management.
Think about what Terraform needs to know to create or update infrastructure.
You got /3 concepts.
Describe what happens during a Terraform apply when resource blocks are present.
Focus on the process Terraform follows to manage resources.
You got /3 concepts.
Practice
(1/5)
1. What is the main role of a resource in Terraform?
easy
A. It defines what cloud or system object Terraform will create or manage.
B. It stores variables for Terraform configurations.
C. It runs scripts during deployment.
D. It controls user access permissions.
Solution
Step 1: Understand Terraform's purpose
Terraform manages infrastructure by creating or updating real-world objects like servers or databases.
Step 2: Identify the role of resources
Resources tell Terraform exactly which objects to create or manage in the cloud or system.
Final Answer:
It defines what cloud or system object Terraform will create or manage. -> Option A
Quick Check:
Resources = Define infrastructure objects [OK]
Hint: Resources = real cloud objects Terraform manages [OK]
Common Mistakes:
Confusing resources with variables
Thinking resources run scripts
Assuming resources control permissions
2. Which of the following is the correct syntax to declare an AWS EC2 instance resource in Terraform?
easy
A. resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" }
B. resource aws_instance example { ami = "ami-123456" instance_type = "t2.micro" }
C. resource "aws_instance" example { ami = "ami-123456" instance_type = "t2.micro" }
D. resource "aws_instance" "example" ( ami = "ami-123456", instance_type = "t2.micro" )
Solution
Step 1: Recall Terraform resource syntax
Terraform resource blocks require the keyword resource, followed by the resource type and name in quotes, then a block with settings.
Step 2: Check each option
resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" } correctly uses quotes around type and name, and curly braces for settings. Others miss quotes or use wrong brackets.
Final Answer:
resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" } -> Option A
Quick Check:
Correct resource syntax uses quotes and braces [OK]
Hint: Resource type and name must be in quotes with braces [OK]
What will Terraform do when applying this configuration?
medium
A. Create a new S3 bucket named 'mybucket' with public access.
B. Delete any existing S3 bucket named 'mybucket'.
C. Update the ACL of all S3 buckets to 'private'.
D. Create a new S3 bucket named 'my-unique-bucket-123' with private access.
Solution
Step 1: Read the resource block details
The resource is an AWS S3 bucket named 'mybucket' in Terraform, with bucket name 'my-unique-bucket-123' and ACL set to 'private'.
Step 2: Understand Terraform behavior
Terraform will create or manage the bucket named 'my-unique-bucket-123' with the specified ACL. It does not delete unrelated buckets or change all buckets.
Final Answer:
Create a new S3 bucket named 'my-unique-bucket-123' with private access. -> Option D
Quick Check:
Resource defines exact object and settings [OK]
Hint: Resource name is internal; bucket attribute is actual bucket name [OK]
C. The resource name "web" should not be in quotes.
D. The resource type aws_instance is invalid.
Solution
Step 1: Check the instance_type attribute
The value t2.micro is a string and must be enclosed in quotes in Terraform.
Step 2: Verify other parts
The resource type and name are correctly quoted. The AMI ID is present as "ami-abc123".
Final Answer:
The instance_type value should be in quotes. -> Option B
Quick Check:
String values need quotes in Terraform [OK]
Hint: String values always need quotes in resource blocks [OK]
Common Mistakes:
Forgetting quotes around string values
Misquoting resource names or types
Assuming AMI ID is optional
5. You want to create two AWS EC2 instances with different names but the same AMI and instance type using Terraform resources. Which approach correctly uses resources to achieve this?
hard
A. Use a variable to store the AMI and instance_type, but only one resource block with one name.
B. Define one resource block and try to assign two names separated by a comma.
C. Define two separate resource blocks with different names but same AMI and instance_type values.
D. Create one resource block and duplicate it manually in the same file with the same name.
Solution
Step 1: Understand resource uniqueness
Each resource block must have a unique name to represent a distinct object Terraform manages.
Step 2: Check options for creating multiple instances
Define two separate resource blocks with different names but same AMI and instance_type values correctly defines two resource blocks with different names but same settings. Others either reuse names or misuse syntax.
Final Answer:
Define two separate resource blocks with different names but same AMI and instance_type values. -> Option C
Quick Check:
Unique resource names needed for multiple objects [OK]
Hint: Use unique resource names for each object [OK]