Which feature allows you to reuse a computed value across multiple resources by defining it once?

Prepare for the HashiCorp Terraform Associate Exam. Utilize flashcards and multiple-choice questions with detailed hints and explanations. Boost your confidence and be ready for success!

Multiple Choice

Which feature allows you to reuse a computed value across multiple resources by defining it once?

Explanation:
Local values let you define a computed value once and reuse it across multiple resources within the same module. By placing a derived value in a locals block, you compute it a single time and then reference local.some_name wherever you need it. This keeps your configuration DRY and ensures consistency; if the underlying inputs change, you only update the value in one place. Other features don’t fit this exact use case. A data source brings in information from the provider about existing infrastructure, rather than defining and reusing a single computed value within your configuration. Modules help structure and reuse groups of resources, but they don’t inherently provide a single internal value to be shared across resources in the same module. Outputs expose values to the outer configuration, not for internal reuse across multiple resources.

Local values let you define a computed value once and reuse it across multiple resources within the same module. By placing a derived value in a locals block, you compute it a single time and then reference local.some_name wherever you need it. This keeps your configuration DRY and ensures consistency; if the underlying inputs change, you only update the value in one place.

Other features don’t fit this exact use case. A data source brings in information from the provider about existing infrastructure, rather than defining and reusing a single computed value within your configuration. Modules help structure and reuse groups of resources, but they don’t inherently provide a single internal value to be shared across resources in the same module. Outputs expose values to the outer configuration, not for internal reuse across multiple resources.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy