How would you reference the id attribute of a data source named 'dc' of type vsphere_datacenter when supplying the datacenter_id argument to a resource?

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

How would you reference the id attribute of a data source named 'dc' of type vsphere_datacenter when supplying the datacenter_id argument to a resource?

Explanation:
In Terraform, you pull a specific value from a data source by using data.<TYPE>.<NAME>.<ATTRIBUTE>. For a vsphere_datacenter data source named dc, the datacenter_id argument needs the actual datacenter’s ID, which is exposed by the id attribute. So the correct reference is data.vsphere_datacenter.dc.id, which provides the concrete ID to pass to the resource. Using just data.vsphere_datacenter.dc would give the whole data source object, not a string, and data.vsphere_datacenter.dc.id_value isn’t a valid attribute for this data source. Also, vsphere_datacenter.dc.id would reference a resource, not a data source, which isn’t appropriate here.

In Terraform, you pull a specific value from a data source by using data.... For a vsphere_datacenter data source named dc, the datacenter_id argument needs the actual datacenter’s ID, which is exposed by the id attribute. So the correct reference is data.vsphere_datacenter.dc.id, which provides the concrete ID to pass to the resource. Using just data.vsphere_datacenter.dc would give the whole data source object, not a string, and data.vsphere_datacenter.dc.id_value isn’t a valid attribute for this data source. Also, vsphere_datacenter.dc.id would reference a resource, not a data source, which isn’t appropriate here.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy