nerdexam
HashiCorp

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.

Read, generate, and modify configuration

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)
  • B
    3% (1)
  • C
    91% (29)
  • D
    3% (1)
  • E
    3% (1)

Why each option

In HCL, a resource's attribute is referenced using the format `resource_type.resource_local_name.attribute_name`.

Aresource.kubrnetes_namespace>example.name

The `resource.` prefix and `>` separator are not standard HCL syntax for referencing resource attributes.

Bkubernetes_namespace.test.name

The local name `test` is incorrect if the resource's local name is `example`.

Ckubernetes_namespace.example,nameCorrect

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`.

Ddata kubernetes_namespace.name

`data kubernetes_namespace.name` refers to a data source, not a resource, and the syntax for attributes is still `data.type.name.attribute`.

ENone of the above

Concept tested: HCL resource attribute referencing syntax

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

Topics

#HCL syntax#Resource referencing#Attributes

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice