In Terraform, the correct way to reference a resource attribute is:
pgsql
CopyEdit
resource_type.resource_name.attribute
For example, if the resource block is:
hcl
CopyEdit
resource " kubernetes_namespace " " example " {
metadata {
name = " my-namespace "
}
}
To reference the name attribute, use:
pgsql
CopyEdit
kubernetes_namespace.example.name
Explanation of incorrect answers:
A (resource.kubernetes_namespace.example.name)– Incorrect. Terraform does not use the resource. prefix when referencing resources.
C (data.kubernetes.namespace.name)– Incorrect. This syntax is used fordata sources, not resources.
D (kubernetes_namespace.test.name)– Incorrect. The resource name is " example " , not " test " .
Official Terraform Documentation Reference:
Terraform Resource References