nerdexam
HashiCorpHashiCorp

TA-002-P · Question #365

TA-002-P Question #365: Real Exam Question with Answer & Explanation

The correct answer is D: data.vsphere_datacenter.dc.id. To reference an attribute from a Terraform data source, the syntax is data.data_source_type.data_source_local_name.attribute_name.

Read, generate, and modify configuration

Question

How would you be able to reference an attribute from the vsphere_datacenter data source for use with the argument within the vsprere_folder resource in the following configuration?

Options

  • Avsphere_datacenter.dc.id
  • Bdata.vsphere_datacenter.dc
  • Cdata.dc,id
  • Ddata.vsphere_datacenter.dc.id

Explanation

To reference an attribute from a Terraform data source, the syntax is data.data_source_type.data_source_local_name.attribute_name.

Common mistakes.

  • A. This syntax is used for resources, not data sources; data sources require the data. prefix.
  • B. This references the entire data source object, not a specific attribute like id.
  • C. This syntax is incorrect; it misses the data_source_type and uses a comma instead of a dot.

Concept tested. HCL data source attribute referencing syntax

Reference. https://developer.hashicorp.com/terraform/language/expressions/references

Topics

#Terraform syntax#Data sources#Attribute referencing

Community Discussion

No community discussion yet for this question.

Full TA-002-P PracticeBrowse All TA-002-P Questions