Terraform-Associate-004 Exam Questions & Answers
HashiCorp Certified: Terraform Associate (004) • HashiCorp
100% money-back guarantee
Sample Terraform-Associate-004 Questions
Practice with real exam-style questions, each with the verified correct answer and explanation.
A resource block is shown in the Exhibit section of this page. How would you reference the attribute name of this resource in HCL?
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 Reference
What kind of configuration block will create an infrastructure object with settings specified within the block?
This is the kind of configuration block that will create an infrastructure object with settings specified within the block. The other options are not used for creating infrastructure objects, but for configuring providers, accessing state data, or querying data sources.
You have just developed a new Terraform configuration for two virtual machines with a cloud provider. You would like to create the infrastructure for the first time.
Which Terraform command should you runfirst?
B (terraform init)--Must be run firstto initialize the Terraform working directory, download providers, and configure the backend.
A (terraform apply)-- Requires initialization first, so itcannotbe run before terraform init.
C (terraform plan)-- Also requires terraform init first to generate a plan.
D (terraform show)-- Displays the state,not relevantfor first-time deployment.
Official Terraform Documentation Reference:
terraform init - HashiCorp Documentation
The terraform output command shows outputs from child modules.
Rationale for Correct Answer: terraform output shows the root module's outputs (the outputs defined in the current working directory's root module). Outputs from child modules are not directly listed unless the root module re-exports them via its own output blocks (e.g., output 'child_public_ip' { value = module.child.public_ip }).
Analysis of Incorrect Options (Distractors):
A (True): Incorrect because child module outputs are accessible via module.<name>.<output>, but terraform output displays only outputs defined in the root module.
Key Concept: Module outputs scope: child outputs must be exposed through root outputs to be shown by terraform output.
Exhibit:
provider "aws" { region = "us-east-1" }
provider "aws" { region = "us-west-2" }
You need to deploy resources into two different AWS regions in the same Terraform configuration using the provider blocks shown in the exhibit. What do you need to add to the provider configuration to deploy a resource to the us-west-2 AWS region?
Detailed
Rationale for Correct Answe r:Terraform requires provider aliases when you configure the same provider multiple times in one configuration. You must define the second AWS provider with an alias, then explicitly tell the resource to use it with the provider meta-argument:
provider 'aws' {
region = 'us-east-1'
}
provider 'aws' {
alias = 'west'
region = 'us-west-2'
}
resource 'aws_instance' 'example_us_west_2' {
provider = aws.west
ami = data.aws_ami.ubuntu.id
instance_type = 't3.micro'
}
This is a core Terraform objective: selecting the correct provider configuration for a resource when multiple instances exist.
Analysis of Incorrect Options (Distractors):
B: Incorrect. Provider blocks do not support the syntax provider 'aws' 'west' { ... }. Aliasing is done with alias = 'west'.
C: Incorrect. You cannot invent a new provider type name like aws_west. The provider remains aws; you differentiate configurations via alias.
D: Incorrect. Terraform will not automatically choose between multiple provider configurations for the same provider; you must disambiguate using aliases and provider = ....
Key Concept:Provider aliases and the provider meta-argument for multi-region (or multi-account) deployments.
Get access to all 359 verified questions with detailed answers.
Unlock All Terraform-Associate-004 Questions