Which data source expression correctly references the id of a vsphere_datacenter data source named 'dc'?

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

Which data source expression correctly references the id of a vsphere_datacenter data source named 'dc'?

Explanation:
When you want a value from a data source in Terraform, you reference it using data.<provider>_<data_type>.<local_name>.<attribute>. For a vsphere_datacenter data source named 'dc', the datacenter’s unique identifier is obtained with data.vsphere_datacenter.dc.id. This reflects the data source being read from the provider and then exposing its attributes after the lookup is performed during plan/apply. The other forms aren’t correct because: - id_value would imply an attribute that doesn’t exist on this data source. - Referencing the data source without an attribute yields the whole object, not a single scalar value. - Omitting the data prefix would indicate a resource, not a data source, which is not how data sources are accessed.

When you want a value from a data source in Terraform, you reference it using data._... For a vsphere_datacenter data source named 'dc', the datacenter’s unique identifier is obtained with data.vsphere_datacenter.dc.id. This reflects the data source being read from the provider and then exposing its attributes after the lookup is performed during plan/apply.

The other forms aren’t correct because:

  • id_value would imply an attribute that doesn’t exist on this data source.

  • Referencing the data source without an attribute yields the whole object, not a single scalar value.

  • Omitting the data prefix would indicate a resource, not a data source, which is not how data sources are accessed.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy