Limited-Time Offer: Enjoy 50% Savings! Coupon code: 50OFF Use it at checkout
Skip to content

Free HashiCorp Certified: Terraform Associate (004) Terraform-Associate-004 Exam Questions

Last updated: · 11 practice questions with answers and explanations

Page: 1 / 26 Total 385 questions

Want more questions? Get Premium Access.

Question 1

New Single answer

Topic: Infrastructure as Code (IaC) with Terraform

Skill tested: Select service-agnostic Terraform patterns for consistent multi-cloud infrastructure.

A media company operates workloads in two public clouds and a private virtualization environment. Teams want to standardize configuration and review workflows, but they accept that provider-specific resource details will remain different. They also want to reuse policy and deployment logic without building a custom abstraction layer that hides cloud capabilities. Which approach best meets these requirements?

Correct Answer: B. Use provider-specific resources where needed, while sharing modules, input conventions, and workflow practices for common patterns.
Explanation:

Terraform uses provider-specific resource types to interact with each platform; it does not translate one provider's resources into another's. Teams can still share service-agnostic practices such as module interfaces, variable conventions, and workflow automation while using appropriate provider resources for each environment. Separate configurations may be sensible in some cases but need not prevent shared modules or processes. Provisioners are not a substitute for provider-managed resources and generally provide less reliable lifecycle management.

Question 2

New Multiple answers

Topic: Terraform fundamentals

Skill tested: Configure multiple provider instances and assign resources to the intended provider alias.

A platform team manages DNS zones in two accounts using the same provider. The default credentials target the production account, while a second set of credentials targets a restricted staging account. The configuration must create one zone in each account and must not accidentally send staging changes to production. Which TWO actions provide the required provider selection? Select TWO.

Correct Answer: A. Declare two configurations of the provider, giving the staging configuration an alias and its staging credentials.; C. Associate the staging resource with the aliased configuration using its `provider` meta-argument.
Explanation:

A provider can have multiple configurations of the same type. The non-default configuration is declared with an alias, and a resource selects it with the `provider` meta-argument, such as `provider = dns.staging`. The `alias` is not a resource argument. Initialization installs providers and records selected provider versions in the dependency lock file; it does not bind account credentials to a particular state or switch accounts. A data source reads information and does not reconfigure a provider.

Question 3

New Single answer

Topic: Terraform fundamentals

Skill tested: Explain provider installation and dependency selection during Terraform initialization.

A developer clones a Terraform repository onto a new workstation. Its configuration declares a provider requirement with a version constraint, and the repository includes `.terraform.lock.hcl`, but the working directory has no `.terraform` directory. Before reviewing a plan, the developer runs `terraform init`. Which outcome should the developer expect?

Correct Answer: A. Terraform installs or retrieves the required provider package, initializes the working directory, and uses the lock file's selected version when it satisfies the constraint.
Explanation:

`terraform init` prepares a working directory, including installing provider plugins required by the configuration and initializing the configured backend. The dependency lock file records selected provider versions and checksums, so initialization normally reuses those selections when compatible with the declared constraints. Initialization neither applies infrastructure changes nor creates remote state unless the configuration explicitly uses a backend and the user completes its setup. It does not ignore a compatible lock-file selection in favor of the newest release.

Question 4

New Single answer

Topic: Core Terraform workflow

Skill tested: Choose the appropriate Terraform command sequence for reviewing and applying infrastructure changes.

A release engineer has edited a configuration for a production change. The team requires syntax and internal consistency checks before generating a plan, human review of the proposed changes, and a guarantee that the reviewed plan - not a newly calculated proposal - is applied. No changes may be applied during validation. Which workflow best satisfies these requirements?

Correct Answer: A. Run `terraform validate`, then `terraform plan -out=release.tfplan`, review that plan, and apply it with `terraform apply release.tfplan`.
Explanation:

Validation checks configuration syntax and internal consistency without changing infrastructure. A plan can be saved to a file, reviewed, and supplied to `terraform apply`; applying that saved plan executes the reviewed proposal rather than asking Terraform to create a fresh plan interactively. Running apply first violates the no-changes-during-validation requirement. Applying without the saved file can produce a different plan, while destroying infrastructure is unrelated and potentially destructive.

Question 5

New Multiple answers

Topic: Terraform configuration

Skill tested: Model complex input types and create explicit cross-resource references in HCL.

An application team receives a map of service definitions. Each entry contains a CIDR block and a list of availability zones. For every entry, Terraform must create a network and one subnet per listed zone. The team wants type checking at the module boundary and reliable dependency ordering without manually duplicating subnet identifiers. Which TWO design choices meet these goals? Select TWO.

Correct Answer: D. Use `for_each` over the map for networks and reference each network's generated identifier when configuring its subnets.; E. Declare the input as a typed map of objects containing a string CIDR and a list of strings for zones.
Explanation:

A typed map of objects expresses the expected structure and lets Terraform validate values supplied to the module. `for_each` can create one network per map entry, while subnet configuration can reference the corresponding network resource attributes and iterate over its zones. Those references both supply needed values and establish implicit dependencies. `depends_on` expects resource or module references, not arbitrary text such as a CIDR. Reading identifiers through a file during the same apply is unnecessary and unreliable; an untyped JSON string discards useful type checking.

Question 6

New Single answer

Topic: Terraform modules

Skill tested: Select and constrain a registry module version in a Terraform configuration.

A company uses a public registry module to provision a standardized network. A release must remain reproducible across developer machines and CI, and the team must be able to adopt a newer module release deliberately after testing it. The module source is in the Terraform Registry. Which configuration approach best supports these requirements?

Correct Answer: D. Set the module's `version` argument to a bounded version constraint, commit the configuration, and update the constraint through a reviewed change.
Explanation:

Registry module blocks support a `version` argument, which can constrain the module release selected during initialization. A deliberate configuration change allows the team to test and adopt a newer release. Module versions are not selected through provider constraints in the dependency lock file, and omitting the module version does not provide a stable, intentional release policy. `required_version` is a top-level Terraform CLI version constraint, not a module-release selector.

Question 7

New Single answer

Topic: Terraform state management

Skill tested: Configure a local backend and distinguish local state from remote state locking.

A small engineering group keeps its Terraform state on a shared file server mounted by all operators. They propose configuring the `local` backend and assume it will prevent simultaneous state updates because every operator sees the same file. The group cannot deploy or administer a remote state service. What is the most accurate recommendation?

Correct Answer: A. Use the local backend, recognizing that it stores state locally and does not provide the distributed locking guarantees of a locking-capable remote backend; coordinate access externally.
Explanation:

The local backend stores state in a local file and does not provide distributed state locking for multiple operators sharing a filesystem. A shared mount does not itself create a reliable Terraform locking mechanism, so the team must coordinate operations externally or adopt a backend that supports locking when feasible. A remote backend requires explicit configuration and suitable infrastructure; Terraform does not discover one automatically. Disabling state would undermine Terraform's ability to track managed objects and is not a safe concurrency strategy.

Question 8

New Single answer

Topic: Maintain infrastructure with Terraform

Skill tested: Use Terraform import workflow and state inspection to adopt an existing resource.

A team has an existing cloud security group that must become Terraform-managed without being recreated. The team has added a matching resource block to configuration and verified its arguments. They need to associate the existing object with the resource address, then confirm that Terraform tracks the intended object before planning further changes. Which action is most appropriate?

Correct Answer: B. Run `terraform import` with the resource address and provider-specific object ID, then inspect it with `terraform state show`.
Explanation:

The import workflow associates an existing remote object with a Terraform resource address and its provider-specific identifier. With a matching resource block present, `terraform import` can populate state, and `terraform state show` lets the team inspect the stored attributes. `state rm` removes tracking rather than importing, while destroy would delete the object. A data source can read an existing object but does not make that object a managed resource.

Question 9

New Single answer

Topic: Maintain infrastructure with Terraform

Skill tested: Enable Terraform diagnostic logging to investigate provider or runtime failures.

During a CI run, Terraform exits with a provider-related error that is not sufficiently explained by the normal output. The team wants detailed diagnostic information for one controlled reproduction, while avoiding verbose logs in every routine run. Which approach is best?

Correct Answer: A. Set `TF_LOG=TRACE` for the reproduction and direct diagnostics to a protected log file with `TF_LOG_PATH`, then remove the setting afterward.
Explanation:

Terraform's `TF_LOG` environment variable enables logging at a selected level, with `TRACE` providing highly detailed diagnostics. `TF_LOG_PATH` can direct those logs to a file, which should be protected because diagnostic output may expose sensitive operational details. The settings can be limited to a controlled reproduction and then removed. State inspection does not enable logging, a path alone does not select a log level, and upgrading providers is not a diagnostic logging mechanism.

Question 10

New Multiple answers

Topic: HCP Terraform

Skill tested: Distinguish HCP Terraform workspace contents from run and collaboration behavior.

An infrastructure team is moving from local runs to HCP Terraform workspaces. They need shared state and run history for each environment, a remote execution option, and team-based collaboration. They also want to avoid assuming that a workspace is a general-purpose virtual machine or that it automatically contains every secret available to the organization. Which TWO statements correctly guide the migration? Select TWO.

Correct Answer: A. A workspace associates a configuration working directory and variables with its state and run history; remote execution runs Terraform in HCP Terraform's managed execution environment.; E. Workspace variables can provide Terraform input values and environment variables, with sensitive values marked appropriately and access controlled.
Explanation:

An HCP Terraform workspace brings together configuration and execution settings with its own state and run history; remote execution performs runs in HCP Terraform's managed environment rather than on the operator's machine. Workspace variables can supply Terraform inputs or environment variables, and sensitive values should be treated and access-controlled accordingly. A workspace is not a general-purpose persistent server. Workspace creation does not grant universal access, and remote execution still requires appropriate provider credentials and configuration.

Question 11

New Single answer

Topic: Core Terraform workflow

Skill tested: Choose a state-aware command for comparing real infrastructure with recorded Terraform state.

A service owner suspects that an operator changed an instance size directly in the cloud console. The team wants to know whether the live object differs from Terraform's recorded state before deciding whether to change the configuration. They must not modify infrastructure during this investigation, and the provider can refresh the object's attributes. Which command should they run first?

Correct Answer: C. `terraform plan -refresh-only`, then review the proposed state-only updates without applying them.
Explanation:

A refresh-only plan refreshes Terraform's view of remote objects and proposes updates to state without proposing configuration-driven infrastructure changes. Reviewing that plan allows the owner to detect drift without applying changes. Applying a refresh-only plan would update state, so it is not the first action when the requirement is investigation only. Removing the object from state discards tracking, and a targeted destroy is destructive rather than a safe drift inspection.