TA-002-P · Question #358
How would you reference the attribute "name* of this fictitious resource in HCL?
The correct answer is C. kubernetes_namespace.example,name. In HCL, a resource's attribute is referenced using the format resource_type.resource_local_name.attribute_name.
Question
How would you reference the attribute "name* of this fictitious resource in HCL?
Options
- Aresource.kubrnetes_namespace>example.name
- Bkubernetes_namespace.test.name
- Ckubernetes_namespace.example,name
- Ddata kubernetes_namespace.name
- ENone of the above
How the community answered
(32 responses)- B3% (1)
- C91% (29)
- D3% (1)
- E3% (1)
Why each option
In HCL, a resource's attribute is referenced using the format `resource_type.resource_local_name.attribute_name`.
The `resource.` prefix and `>` separator are not standard HCL syntax for referencing resource attributes.
The local name `test` is incorrect if the resource's local name is `example`.
In Terraform's HashiCorp Configuration Language (HCL), attributes of a resource are referenced using the syntax `resource_type.local_name.attribute_name`. Assuming the fictitious resource has a `resource_type` of `kubernetes_namespace` and a `local_name` of `example`, its `name` attribute would be `kubernetes_namespace.example.name`.
`data kubernetes_namespace.name` refers to a data source, not a resource, and the syntax for attributes is still `data.type.name.attribute`.
Concept tested: HCL resource attribute referencing syntax
Source: https://developer.hashicorp.com/terraform/language/expressions/references
Topics
Community Discussion
No community discussion yet for this question.