0
0
Terraformcloud~5 mins

Querying existing resources in Terraform - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the data block in Terraform?
The data block is used to query and read information about existing resources that are not managed by the current Terraform configuration.
Click to reveal answer
beginner
How do you reference an existing AWS VPC by its ID in Terraform?
You use a data block like this:<br>
data "aws_vpc" "example" {
  id = "vpc-12345678"
}
<br>This lets you access its attributes in your configuration.
Click to reveal answer
intermediate
Why should you use data sources instead of hardcoding resource attributes?
Using data sources keeps your configuration flexible and up-to-date by dynamically fetching current resource details instead of relying on fixed values that may change.
Click to reveal answer
intermediate
What happens if the queried resource does not exist when using a Terraform data source?
Terraform will return an error during plan or apply because it cannot find the resource to read its attributes.
Click to reveal answer
beginner
Can you modify existing resources using Terraform data sources?
No, data sources only read information. To modify resources, you must use resource blocks managed by Terraform.
Click to reveal answer
What Terraform block is used to query existing resources?
Aoutput
Bresource
Cdata
Dvariable
Which of the following is TRUE about Terraform data sources?
AThey read information from existing resources.
BThey store variables.
CThey delete resources.
DThey can create new resources.
If a data source references a non-existent resource, what will happen?
ATerraform will create the resource automatically.
BTerraform will ignore the missing resource.
CTerraform will skip the data source silently.
DTerraform will return an error during plan or apply.
How do you access an attribute from a data source in Terraform?
AUsing <code>data.<resource_type>.<name>.<attribute></code>
BUsing <code>resource.<name>.<attribute></code>
CUsing <code>var.<attribute></code>
DUsing <code>output.<attribute></code>
Why is it better to use data sources instead of hardcoding resource IDs?
AData sources are faster to deploy.
BData sources keep configurations flexible and accurate.
CData sources automatically update resource attributes.
DData sources create new resources.
Explain how Terraform data sources help you work with existing cloud resources.
Think about how you can read info without managing the resource.
You got /4 concepts.
    Describe the difference between Terraform resource blocks and data blocks.
    One manages, the other queries.
    You got /4 concepts.