0
0
Terraformcloud~5 mins

Data source vs resource difference in Terraform - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a resource in Terraform?
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
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
Which Terraform block would you use to get the IP of an existing server?
Aresource
Bdata
Cvariable
Doutput
If you want to create a new database, which Terraform block do you use?
Aresource
Bdata
Coutput
Dprovider
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
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.