What is the purpose of a data source in Terraform?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

What is the purpose of a data source in Terraform?

Explanation:
Data sources in Terraform fetch information from outside Terraform to use in your configurations. They are read-only and don’t create or manage infrastructure themselves, but pull data from a provider or external source so you can reference it elsewhere in your config. This is useful for discovering existing resources or external data—like finding the latest AMI in AWS or reading outputs from another Terraform state—and then using those values to shape your resource definitions. For example, you can reference data.aws_ami.example.id in a resource to ensure you launch with the correct image. Providers, resources, and state are handled separately, but data sources give you access to external information within the same configuration.

Data sources in Terraform fetch information from outside Terraform to use in your configurations. They are read-only and don’t create or manage infrastructure themselves, but pull data from a provider or external source so you can reference it elsewhere in your config. This is useful for discovering existing resources or external data—like finding the latest AMI in AWS or reading outputs from another Terraform state—and then using those values to shape your resource definitions. For example, you can reference data.aws_ami.example.id in a resource to ensure you launch with the correct image. Providers, resources, and state are handled separately, but data sources give you access to external information within the same configuration.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy