Recall & Review
beginner
What is a
data block in Terraform?A
data block lets you fetch information from existing resources outside your Terraform configuration. It helps you use data created elsewhere.Click to reveal answer
beginner
What are the main parts of a Terraform data source block?
A data source block has three parts: the keyword
data, the resource type (like aws_ami), and a name you choose to reference it later.Click to reveal answer
beginner
How do you reference a data source output in Terraform?
Use
data.<resource_type>.<name>.<attribute>. For example, data.aws_ami.example.id gets the AMI ID.Click to reveal answer
intermediate
Example: What does this data block do?<br>
data "aws_ami" "ubuntu" {
most_recent = true
owners = ["099720109477"]
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}
}It finds the most recent Ubuntu 20.04 AMI owned by the official Ubuntu account. This lets you use the latest Ubuntu image in your infrastructure.
Click to reveal answer
beginner
Why use data sources instead of hardcoding values?
Data sources keep your config flexible and up-to-date. They fetch live info, so you avoid errors from outdated or manual values.
Click to reveal answer
What keyword starts a data source block in Terraform?
✗ Incorrect
The
data keyword defines a data source block to fetch existing info.How do you name a data source block?
✗ Incorrect
You give a unique name after the resource type to reference the data source later.
Which of these is a valid way to reference a data source attribute?
✗ Incorrect
Data source attributes are referenced with
data.<type>.<name>.<attribute>.What does the
filter block inside a data source do?✗ Incorrect
Filters narrow down which existing resources the data source returns.
Why is using data sources considered a best practice?
✗ Incorrect
Data sources fetch live info, avoiding stale or manual values.
Explain the structure and purpose of a Terraform data source block.
Think about how you tell Terraform to look up info it doesn't create.
You got /5 concepts.
Describe how filters work inside a data source block and why they are useful.
Filters help you find exactly what you need from many options.
You got /4 concepts.