A resource is an infrastructure object that Terraform creates, updates, or deletes. It represents real cloud services like servers, databases, or networks.
Click to reveal answer
beginner
What is a data source in Terraform?
A data source lets Terraform read or fetch information from existing infrastructure or external sources without changing them.
Click to reveal answer
beginner
How does a resource differ from a data source in Terraform?
Resources create or manage infrastructure, while data sources only read existing information without making changes.
Click to reveal answer
intermediate
Why use a data source instead of a resource?
Use a data source to get details about existing infrastructure you did not create or want to keep unchanged.
Click to reveal answer
intermediate
Give an example of when to use a resource vs a data source.
Use a resource to create a new virtual machine. Use a data source to get the IP address of an existing database.
Click to reveal answer
What does a Terraform resource do?
ARuns Terraform commands
BOnly reads existing infrastructure
CCreates or manages infrastructure
DDeletes data sources
✗ Incorrect
Resources create, update, or delete infrastructure objects.
What is the main purpose of a Terraform data source?
ATo read existing infrastructure information
BTo create new cloud resources
CTo delete resources
DTo run scripts
✗ Incorrect
Data sources fetch information from existing infrastructure without changing it.
Which Terraform block would you use to get the IP of an existing server?
Aresource
Bdata
Cvariable
Doutput
✗ Incorrect
Data blocks read existing information like IP addresses.
If you want to create a new database, which Terraform block do you use?
Aresource
Bdata
Coutput
Dprovider
✗ Incorrect
Resources create new infrastructure components.
Can a data source modify infrastructure?
AYes, it can update resources
BYes, it can create resources
CYes, it can delete resources
DNo, it only reads data
✗ Incorrect
Data sources only read existing infrastructure; they do not modify it.
Explain the difference between a Terraform resource and a data source.
Think about who controls the infrastructure changes.
You got /4 concepts.
When would you choose to use a data source instead of a resource in Terraform?
Consider scenarios where infrastructure is already set up.
You got /4 concepts.
Practice
(1/5)
1. What is the main difference between a resource and a data source in Terraform?
easy
A. Resources and data sources both create infrastructure but in different clouds.
B. Resources create or manage infrastructure; data sources only read existing information.
C. Resources only read existing infrastructure; data sources create new infrastructure.
D. Resources are temporary; data sources are permanent.
Solution
Step 1: Understand resource role
Resources in Terraform are used to create or manage cloud infrastructure components.
Step 2: Understand data source role
Data sources are used to read information about existing infrastructure without changing it.
Final Answer:
Resources create or manage infrastructure; data sources only read existing information. -> Option B
Quick Check:
Resource = create/manage, Data source = read [OK]
Hint: Resources build; data sources just look up info [OK]
Common Mistakes:
Thinking data sources create resources
Confusing resource and data source roles
Assuming both modify infrastructure
Believing data sources are temporary
2. Which of the following is the correct syntax to declare a data source in Terraform?
easy
A. data "aws_ami" "example" {}
B. resource "aws_instance" "example" {}
C. source "aws_vpc" "example" {}
D. resource "data_aws_subnet" "example" {}
Solution
Step 1: Identify data source syntax
Data sources use the keyword data followed by the type and name.
Step 2: Check options
data "aws_ami" "example" {} uses data "aws_ami" "example" {}, which is correct syntax for a data source.