Question 1 · choose 1
A configuration hard-codes a machine image ID, and the image team publishes a new image every month with a known name pattern. The configuration should always use the newest matching image without managing the image itself. What should it use?
- AA resource block for the image, so Terraform creates a fresh image every month
- BA variable that the image team updates in the configuration's default value every month
- CA data block that looks up the newest image matching the name pattern
- DAn output that exports the image ID from the image team's console session
Show the answer and why
AA resource block for the image, so Terraform creates a fresh image every month
Incorrect
A resource would make Terraform create and own an image, which the image team already publishes.
BA variable that the image team updates in the configuration's default value every month
Incorrect
That still hard-codes the ID, only in a different place, and needs a person each month.
CA data block that looks up the newest image matching the name pattern
Correct
Data sources read information about existing infrastructure for use in the configuration without managing it.
DAn output that exports the image ID from the image team's console session
Incorrect
Outputs expose values from a configuration; they cannot read another system's console.
Resources are what Terraform manages; data sources are what it only reads.
HashiCorp documentation
- Resources overview (resource behavior: create, update in place, destroy and re-create) (opens in a new tab)
- Data sources (read-only lookups, when they are read) (opens in a new tab)
- variable block reference (arguments) (opens in a new tab)
- Query data sources (tutorial) (opens in a new tab)
- Output values (opens in a new tab)