Terraform-Associate-004 practice question 13 of 35

A resource block is shown in the Exhibit section of this page. How would you reference the attribute name of this resource in HCL?

Full set: 360 questions
Answer options
A: resource.kubernetes_namespace.example.name
B: kubernetes_namespace.example.name Correct answer
C: data.kubernetes.namespace.name
D: kubernetes_namespace.test.name
Correct Answer:
B. kubernetes_namespace.example.name
Explanation

In HashiCorp Configuration Language (HCL), the standard syntax to reference an attribute of a managed resource is ... For a resource block of type kubernetesnamespace with the local name example, the name attribute is correctly referenced as kubernetesnamespace.example.name. This expression allows other parts of the configuration, such as another resource or an output value, to use the value of this specific attribute.

Why Incorrect

A. resource.kubernetesnamespace.example.name: The resource. prefix is not part of the standard syntax for referencing resource attributes in general HCL expressions.
C. data.kubernetes.namespace.name: The data. prefix is used to reference attributes from a data source, not a managed resource block as specified in the question.
D. kubernetesnamespace.test.name: This uses the incorrect local name (test). The reference must match the local name defined in the resource block, which is example.

References

1. HashiCorp Terraform Documentation, "Expressions - References to Resource Attributes": This document explicitly states the syntax for referring to resource attributes is RESOURCETYPE.LOCALNAME.ATTRIBUTE. It provides examples like awsinstance.web.id, which directly supports the structure of the correct answer.

2. HashiCorp Terraform Documentation, "Expressions - Reference Types": This page clarifies the different prefixes for references. It shows that resource references start directly with the resource type (e.g., awsinstance.example), while data source references start with data. (e.g., data.awsami.example). This confirms that options A and C use incorrect prefixes for this scenario.

Scroll to Top