Practice Free Terraform Associate 004 Exam Online Questions
Your DevOps team is currently using the local backend for your Terraform configuration. You would like to move to a remote backend to store the state file in a central location.
Which of the following backends would not work?
- A . Artifactory
- B . Amazon S3
- C . Terraform Cloud
- D . Git
D
Explanation:
This is not a valid backend for Terraform, as it does not support locking or versioning of state files4.
The other options are valid backends that can store state files in a central location.
You want to use API tokens and other secrets within your team’s Terraform workspaces.
Where does HashiCorp recommend you store these sensitive values? (Pick 3 correct responses)
- A . In a plaintext document on a shared drive.
- B . In a terraform.tfvars file, checked into version control.
- C . In a terraform.tfvars file, securely managed and shared with your team.
- D . In an HCP Terraform/Terraform Cloud variable, with the sensitive option checked.
- E . In HashiCorp Vault.
C,D,E
Explanation:
Rationale for Correct Answer
C: Securely managed.tfvars files are acceptable if not committed to version control.
D: HCP Terraform provides secure storage for sensitive variables.
E: HashiCorp Vault is designed for secrets management and integrates with Terraform. Analysis of Incorrect Options (Distractors):
A: Plaintext storage is insecure.
B: Secrets should never be committed to version control.
Key Concept: Sensitive values must be stored using secure secret management solutions.
Reference: Terraform Exam Objective C Use Terraform to Manage Infrastructure
When using multiple configuration of the same Terraform provider, what meta-argument must you include in any non-default provider configurations?
- A . Alias
- B . Id
- C . Depends_on
- D . name
A
Explanation:
This is the meta-argument that you must include in any non-default provider configurations, as it allows you to give a friendly name to the configuration and reference it in other parts of your code. The other options are either invalid or irrelevant for this purpose.
You want to create a string that combines a generated random_id and a variable and reuse that string several times in your configuration.
What is the simplest correct way to implement this without repeating the random_id and variable?
- A . Use a module.
- B . Add an output value.
- C . Add a local value.
- D . Use a data source.
C
Explanation:
Rationale for Correct Answer
A local value (locals {… }) is the simplest way to
define a reusable expression once and reference it many times via local.<name>. This is exactly what locals are for: reducing repetition and improving readability when combining values like random_id results and variables.
Analysis of Incorrect Options (Distractors):
A (Module): Overkill―modules are for packaging reusable groups of resources, not simple string reuse inside the same configuration.
B (Output value): Outputs are for exposing values to the CLI or to parent modules, not for internal reuse within the same module.
D (Data source): Data sources read existing remote objects; they are not intended for composing local strings.
Key Concept: Using locals to avoid repeating expressions.
Reference: Terraform Objectives ― Read, Generate, and Modify Configurations (locals, expressions, and reuse patterns).
What is the name of the default file where Terraform stores the state?
Type your answer in the field provided. The text field is not case-sensitive and all variations of the correct answer are accepted.
Explanation:
The name of the default file where Terraform stores the state is terraform.tfstate. This file contains a JSON representation of the current state of the infrastructure managed by Terraform. Terraform uses this file to track the metadata and attributes of the resources, and to plan and apply changes. By default, Terraform stores the state file locally in the same directory as the configuration files, but it can also be configured to store the state remotely in a backend.
Reference = [Terraform State], [State File Format]
In a HCP Terraform/Terraform Cloud workspace linked to a version control repository, speculative plan runs start automatically when you merge or commit changes to version control.
- A . True
- B . False
A
Explanation:
Speculative Plans: Terraform Cloud’sspeculative planfeature runs automatically when changes are detected in a linked VCS repository, enabling users to review potential infrastructure changes without committing them.
Automatic Integration: This feature automates the planning process by triggering when changes are committed, aiding teams in previewing infrastructure changes seamlessly.
For further understanding, see theTerraform Cloud VCS Integrationdocumentation.
Exhibit:
Root module configuration:
output "vnet_id" {
value = module.my_network.vnet_id
}
Error:
Error: Reference to undeclared output value
on main.tf line 12, in output "vnet_id":
12: value = module.my_network.vnet_id
You are using a networking module in your Terraform configuration with the name my_network. Your
root module includes the configuration shown. When you run terraform validate, you get the error shown.
Which option would successfully retrieve this value from your networking module?
- A . Change the referenced value to module.my_network.outputs.vnet_id.
- B . Define the attribute vnet_id as a variable in the networking module.
- C . Change the referenced value to my_network.outputs.vnet_id.
- D . Define the attribute vnet_id as an output in the networking module.
D
Explanation:
Rationale for Correct Answer
A parent/root module can only read values from a child module if the child module exports them via an output block. The error indicates vnet_id is not an exported output from module.my_network. Defining output "vnet_id" { value =… } inside the networking (child) module makes module.my_network.vnet_id valid.
Analysis of Incorrect Options (Distractors):
A: Incorrect―Terraform does not use module.<name>.outputs.<output>; module outputs are referenced directly as module.<name>.<output>.
B: Incorrect―variables are inputs to a module, not values exported from it.
C: Incorrect―missing the module. prefix and still uses an invalid.outputs path.
Key Concept: Module outputs are the contract for exposing child module values to the root/parent.
Reference: Terraform Objectives ― Interact with Terraform Modules (module inputs/outputs and composition).
You can reference a resource created with for_each using a Splat ( *) expression.
- A . True
- B . False
B
Explanation:
You cannot reference a resource created with for_each using a splat (*) expression, as it will not work with resources that have non-numeric keys. You need to use a for expression instead to iterate over the resource instances.
_______backends support state locking.
- A . All
- B . No
- C . Some
- D . Only local
C
Explanation:
Some backends support state locking, which prevents other users from modifying the state file while a Terraform operation is in progress. This prevents conflicts and data loss. Not all backends support this feature, and you can check the documentation for each backend type to see if it does.
You have a simple Terraform configuration containing one VM (virtual machine) in a cloud provider. You run terraform apply and the VM is created successfully.
What will happen if you run terraform apply again immediately afterwards without changing any Terraform code?
- A . Terraform will terminate and recreate the VM.
- B . Terraform will create another duplicate VM.
- C . Terraform will apply the VM to the state file.
- D . Terraform will take no action.
D
Explanation:
Rationale for Correct Answer
Terraform is designed to be idempotent. If the configuration and real infrastructure match the state, a subsequent terraform apply will show no changes and perform no actions.
Analysis of Incorrect Options (Distractors):
A: Terraform does not recreate resources unless the plan requires it (configuration change, forced replacement, drift that requires replacement, etc.).
B: Terraform won’t create duplicates unless the configuration indicates multiple instances (e.g., count, for_each) or a new resource address.
C: The state was already written during the first successful apply; a second apply doesn’t “re-apply to the state file” as a distinct action.
Key Concept: Terraform idempotency and convergence to desired state.
Reference: Terraform Objectives ― Understand Terraform Basics and CLI (plan/apply behavior), Implement and Maintain State (state-driven operations).
