HashiCorp certification · Exam Terraform-Associate-003

Terraform-Associate-003 Mock Exam Page 2

HashiCorp Certified: Terraform Associate (003) (HCTA0-003)

Free Terraform-Associate-003 mock exam questions 11–20, each with the answer and an explanation.

20 questions · 33 minutes · free, no sign-up

Free Terraform-Associate-003 questions

11–20 of 58 free
Question 11 Choose 2
Which of the following ate advantages of using infrastructure as code (laC) instead of provisioning with a graphical user interface (GUI)? Choose two correct answers.
Show answerHide answer

Correct answer: A, D Lets you version, reuse, and share infrastructure configurationReduces risk of operator error

Explanation

Explanation:
Infrastructure as Code (IaC) is a fundamental concept in modern DevOps and cloud engineering, enabling teams to define, provision, and manage infrastructure through machine-readable configuration files rather than manual steps in a graphical user interface (GUI). Terraform is a leading IaC tool by HashiCorp, and the advantages it provides go far beyond convenience — it brings consistency, automation, and reliability to infrastructure operations.
The two main advantages of using Infrastructure as Code (IaC) compared to GUI-based provisioning are:

A. Lets you version, reuse, and share infrastructure configuration
One of the biggest benefits of IaC tools like Terraform is version control. When infrastructure is defined in code, you can store that code in version control systems such as Git, just like application code. This allows teams to track changes, review history, and roll back to previous configurations if needed. In a GUI-based setup, such tracking is either impossible or extremely limited since actions are often performed manually through clicks, with no audit trail or code history.
In addition to versioning, IaC makes it possible to reuse and share configurations. Terraform allows you to modularize your infrastructure by creating modules—reusable building blocks for common infrastructure patterns. These modules can be shared across teams, organizations, or even the public Terraform Registry, ensuring consistency and reducing duplication of effort.
For instance, instead of manually creating a VPC, subnets, and security groups through a GUI every time, you can define a reusable module that provisions them in a standardized way. This not only accelerates provisioning but also enforces best practices across deployments.
Thus, IaC enables collaboration, automation, and standardization, all of which are difficult to achieve with manual GUI-based methods.
D. Reduces risk of operator error
Another major advantage of IaC is the reduction of human error. Manual configuration via a GUI often involves repetitive clicking, form-filling, and navigating multiple pages—each step introducing a chance for mistakes such as selecting the wrong instance type, misconfiguring a security group, or deploying to the wrong region.
In contrast, IaC allows you to codify infrastructure definitions, so the same configuration can be applied repeatedly and consistently. The process becomes automated, predictable, and testable. Terraform’s plan command (terraform plan) shows exactly what changes will be made before they are applied, allowing you to verify configurations and detect mistakes early.
Once your infrastructure code is peer-reviewed and tested, you can confidently apply it across multiple environments—development, staging, and production—without introducing inconsistencies. This drastically reduces the risk of manual misconfigurations that can lead to outages, security gaps, or cost overruns.
By integrating Terraform with CI/CD pipelines, organizations can further automate validation, testing, and deployment of infrastructure, effectively eliminating the need for manual steps altogether.

Why the Other Options Are Incorrect
B. Provisions the same resources at a lower cost
IaC does not inherently lower the cost of resources. The cost of infrastructure is determined by the cloud provider and the type of resources provisioned, not by whether they were created using Terraform or a GUI. IaC may indirectly reduce cost through efficiency and automation, but not by changing resource pricing.
C. Secures your credentials
IaC itself does not secure credentials; instead, credential management depends on integrations with secure tools such as HashiCorp Vault, AWS IAM, or environment variables. Terraform can use these securely, but the IaC model alone does not guarantee credential protection. Therefore, this is not a direct advantage of IaC over GUI provisioning.
E. Prevents manual modifications to your resources
IaC does not inherently prevent manual changes. Users with sufficient permissions can still modify resources via the provider’s GUI or CLI. While Terraform can detect drift between configuration and actual state, it doesn’t block manual changes—it only reports them during terraform plan.

Reference:
According to HashiCorp’s documentation:
“Terraform allows you to version, reuse, and share your configurations, making it easier to automate and standardize your infrastructure.”
“Because infrastructure is defined in code, you can preview changes before applying them, reducing the risk of human error.”

Source:
Terraform — Infrastructure as Code Overview
Terraform Documentation: Command Line Interface (CLI)

Question 12 Choose 1
When do you need to explicitly execute Terraform in refresh-only mode?
Show answerHide answer

Correct answer: C Before every terraform import.

Explanation

Explanation:
You need to explicitly execute Terraform in refresh-only mode after running terraform import to ensure the state file accurately reflects the real-world attributes of the imported resource. The terraform import command only adds the resource to the state—it does not populate its attributes. Running terraform apply -refresh-only fetches the actual configuration from the provider and updates the state without making changes to infrastructure. This step is critical to avoid drift and incorrect plans.
Without a refresh, terraform plan may show unexpected changes or attempt to recreate the resource, since the state lacks real attribute data. Refresh-only mode ensures the state is synchronized with the actual infrastructure before further planning or applying.
reference:
Terraform Apply -refresh-only
Terraform Import

Why other options are incorrect:
A. Before every terraform plan
Incorrect because terraform plan already performs a state refresh by default unless explicitly disabled with -refresh=false. There’s no need to run refresh-only mode separately.
B. Before every terraform apply Also
incorrect. Like plan, terraform apply refreshes state unless -refresh=false is used. Refresh-only mode is only needed when you want to update state without applying changes.
D. None of the above
Incorrect because there is a valid use case—after terraform import—where refresh-only mode is explicitly required to ensure state accuracy.

Summary:
Use terraform apply -refresh-only after importing resources to populate the state with real-world attributes. This prevents drift and ensures accurate planning. It is not needed before every plan or apply, as those commands already refresh state by default.

References:
HashiCorp Terraform CLI: Apply -refresh-only
HashiCorp Terraform CLI: Import
Terraform Docs: State Management
Question 13 Choose 1
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.
Show answerHide answer

Correct answer: A True

Explanation

Explanation:
In a HashiCorp Cloud Platform (HCP) Terraform or Terraform Cloud workspace connected to a version control system (VCS) repository, speculative plan runs are automatically triggered when changes are merged or committed to the configured branch of the repository. This behavior is a core feature of Terraform Cloud’s integration with VCS providers like GitHub, GitLab, or Bitbucket. Speculative plans evaluate proposed changes without applying them, providing a preview of the infrastructure modifications that would result from the changes in the code. This allows teams to review potential impacts before initiating an apply operation, enhancing safety and collaboration in infrastructure management.
When a workspace is linked to a VCS repository, Terraform Cloud monitors the specified branch for changes. Upon detecting a commit or merge (e.g., via a pull request or direct commit), it automatically initiates a speculative plan run. This run executes a terraform plan based on the updated configuration in the repository, generating an output that shows the resources that would be created, modified, or deleted. These speculative plans are non-destructive, meaning they do not alter the actual infrastructure, making them ideal for validating changes in a CI/CD pipeline or collaborative workflows. This automation streamlines the review process, ensuring that infrastructure changes are vetted promptly.
For example,
if a developer commits a change to a Terraform configuration file in the linked branch (e.g., adding a new AWS EC2 instance), Terraform Cloud detects the change, pulls the updated code, and runs a speculative plan. The plan’s output is then visible in the Terraform Cloud UI, where team members can review it. This feature supports governance by allowing teams to catch errors or unintended changes early, especially in environments with multiple contributors. The automatic triggering of speculative plans is configurable in Terraform Cloud. Workspaces can be set to auto-apply changes or require manual approval, but speculative plans run by default on VCS changes unless explicitly disabled (e.g., by pausing the workspace or modifying run triggers). This behavior distinguishes Terraform Cloud’s VCS-driven workflows from CLI-driven workflows, where plans must be manually initiated.

Why the other option is incorrect:
B. False:
This is incorrect because speculative plan runs are indeed triggered automatically when changes are committed or merged to the linked VCS repository in a Terraform Cloud workspace. This is a standard feature of VCS-integrated workspaces, designed to provide immediate feedback on infrastructure changes.

References:
HCP Terraform: Version Control Workflow
Terraform Cloud: Runs and Plans
Terraform Cloud: Speculative Plans
Question 14 Choose 1
Which Terraform command checks that your configuration syntax is correct?
Show answerHide answer

Correct answer: A terraform validate

Explanation

Explanation:
This question is testing your understanding of the specific purpose of different Terraform CLI commands. Let's examine what each one does:

A. terraform validate:
Correct. This command's primary function is to check the configuration files in the current directory for syntax errors and internal consistency. It verifies that the configuration is valid HCL (HashiCorp Configuration Language) and that basic arguments and references are correct. It does not require initialization or access to remote services.
B. terraform init:
Incorrect. The init command is the first command you run. It initializes a working directory containing Terraform configuration files. This involves downloading the required provider plugins and setting up the backend. While it may fail if the configuration syntax is severely broken, its main job is not syntax validation but initialization.
C. terraform show:
Incorrect. This command is used to read and display a human-readable version of a state file or a saved plan file. It is a read-only command for inspection and does not perform any validation on your configuration syntax.
D. terraform fmt:
Incorrect. This command is used to rewrite your configuration files to a canonical format and style. It corrects style and formatting (like indentation and spacing) but does not check for or report syntax errors. A file can be syntactically incorrect (e.g., missing a closing brace) but still be processed by fmt, which might just format the parts it can parse.

In summary:
Use terraform validate to check for syntax and basic configuration errors.
Use terraform fmt to automatically fix style and formatting.

Reference:
HashiCorp Documentation: Command: validate
Question 15 Choose 1
You are using a networking module in your Terraform configuration with the name label my-network. In your main configuration you have the following code:



What must you do to successfully retrieve this value from your networking module?
Show answerHide answer

Correct answer: C Define the attribute vnet_id as an output in the networking module

Explanation

Explanation:
To successfully retrieve module.my_network.vnet_id in your main configuration, the networking module must explicitly define vnet_id as an output. Terraform modules expose values to parent configurations only through output blocks. Without this, referencing module.my_network.vnet_id will result in a validation error like:
Code
Error: Reference to undeclared output value
This means the module does not declare vnet_id as an output, even if it uses or computes it internally.
Fix: Inside the networking module (e.g., modules/networking/outputs.tf), add:
hcl
output "vnet_id" {
value =
}

Then your main config can safely reference:
hcl
output "net_id" {
value = module.my_network.vnet_id
}

Reference:
Terraform Modules - Outputs
Terraform CLI - validate

❌ Why Other Options Are Incorrect
A. Change the reference value to my-network,outputs,vmet_id
❌ Invalid syntax. Terraform does not use comma-separated references. Also, vmet_id appears to be a typo.
B. Define the attribute vmet_id as a variable in the networking module
❌ Variables are for input, not for exposing values out. You need an output, not a variable.
D. Change the reference value module.my,network,outputs,vnet_id
❌ Again, invalid syntax. Terraform uses dot notation (module.my_network.vnet_id), not comma-separated paths.

📝Summary
To access a value from a module, it must be declared as an output. Option C is correct because it ensures vnet_id is exposed from the networking module, allowing your main configuration to reference it without error. All other options misuse Terraform syntax or confuse inputs with outputs.
Question 16 Choose 1
How would you reference the "name’’ value of the second instance of this resource?

Show answerHide answer

Correct answer: B element(aws_instance.web, 2)

Explanation

Explanation:
In Terraform, when using count to create multiple instances of a resource, each instance is indexed starting from 0. So the second instance has an index of 1.
To reference an attribute (like name) of the second instance, use:
hcl
element(aws_instance.web[*].name, 1)
This uses the element() function to safely access the name attribute of the second instance in the list of all instances.

Alternatively, you can directly reference:
hcl
aws_instance.web[1].name
Both are valid, but element() is often used for compatibility with older Terraform versions or dynamic indexing.

❌ Why Other Options Are Incorrect
A. aws_instance.web(2),name
❌ Invalid syntax. Terraform uses square brackets [], not parentheses () or commas.
C. aws_instance-web(1)
❌ Incorrect resource naming and syntax. Hyphens are not valid in resource references.
D. aws_instance_web(1),name
❌ Wrong format. Terraform does not use commas or underscores this way.
E. Aws_instance,web,* , name
❌ Completely invalid syntax. Terraform does not support this format.

📚 Reference
Terraform: Resource Count and Indexing
Terraform: element() Function
Question 17 Choose 2
Which two steps are required to provision new infrastructure in the Terraform workflow? Choose two correct answers.
Show answerHide answer

Correct answer: A, E Planapply

Explanation

Explanation:
The Terraform workflow for provisioning new infrastructure follows a structured process to ensure safe and predictable infrastructure management. The two essential steps required are:
A. Plan:
The terraform plan command generates an execution plan that outlines what actions Terraform will take to achieve the desired state defined in the configuration files. It compares the current infrastructure state (stored in the state file) with the configuration and previews the resources to be created, modified, or destroyed. This step is critical for reviewing changes before applying them, ensuring accuracy and minimizing risks.
E. Apply:
The terraform apply command executes the planned actions to provision or update the infrastructure. It uses the plan generated earlier (or creates one if none is provided) to create, modify, or delete resources in the target provider (e.g., AWS, Azure) based on the configuration. This step finalizes the infrastructure deployment after plan validation.

Why other options are incorrect:
B. Import:
The terraform import command is used to bring existing infrastructure into Terraform management by mapping it to a resource in the configuration. It is not required for provisioning new infrastructure, as it applies to pre-existing resources.
C. Validate:
The terraform validate command checks the syntax and basic configuration integrity of Terraform files but does not provision infrastructure. It is an optional step for validation, not a required part of provisioning.
D. Init:
The terraform init command initializes a Terraform working directory by downloading providers and modules. While necessary to set up the environment before planning or applying, it is a preparatory step, not a direct part of the provisioning process itself.
The typical workflow for provisioning new infrastructure involves running terraform init (if not already initialized), followed by terraform plan to preview changes, and terraform apply to execute them. Thus, only Plan and Apply are the core steps for provisioning.

References:
HashiCorp Terraform Documentation: Terraform Workflow
HashiCorp Terraform Documentation: terraform plan
HashiCorp Terraform Documentation: terraform apply
Question 18 Choose 1
When using multiple configuration of the same Terraform provider, what meta-argument must you include in any non-default provider configurations?
Show answerHide answer

Correct answer: A Alias

Explanation

Explanation:
When using multiple configurations of the same Terraform provider (e.g., multiple AWS regions or distinct credentials within the AWS provider), you must define multiple provider blocks to handle these configurations. To differentiate these non-default provider configurations from the default one, the alias meta-argument is required. The alias assigns a unique identifier to each non-default provider configuration, allowing resources to explicitly reference them. For example, in an AWS provider setup, you might have a default provider for us-east-1 and an aliased provider (e.g., aws.west) for us-west-2, enabling resources to specify which provider to use. The default provider configuration is implicitly used if no alias is specified, but any additional provider configuration must include an alias to be referenced in resource blocks using the provider argument. Without alias, Terraform would not recognize multiple provider instances, leading to configuration errors.

Why other options are incorrect:
B. Id:
The id meta-argument is not used for provider configurations. It is typically an attribute of resources to identify them in the state, not for distinguishing provider instances.
C. Depends_on:
The depends_on meta-argument specifies explicit dependencies between resources or modules, not provider configurations. It is unrelated to managing multiple provider instances.
D. name:
There is no name meta-argument for provider configurations. The alias serves the purpose of naming or identifying non-default provider configurations.

References:
HashiCorp Terraform Documentation: Provider Configuration
HashiCorp Terraform Documentation: Multiple Provider Instances
Question 19 Choose 1
You ate making changes to existing Terraform code to add some new infrastructure. When is the best time to run terraform validate?
Show answerHide answer

Correct answer: C Before you run terraform plan so you can validate your code syntax

Explanation

Explanation:
The terraform validate command is a lightweight, fast check that focuses solely on your configuration files. It verifies that the code is syntactically valid and internally consistent.

Let's evaluate the options:
A. After you run terraform apply so you can validate your infrastructure:
Incorrect. terraform validate does not check your actual, deployed infrastructure. It only checks the configuration code. To validate infrastructure, you would use tools like terraform show to inspect the state, or use provider-specific checks.
B. Before you run terraform apply so you can validate your provider credentials:
Incorrect. terraform validate does not authenticate with or check your provider credentials (e.g., AWS access keys). Credentials are verified during terraform plan and terraform apply when Terraform needs to communicate with the provider's API.
C. Before you run terraform plan so you can validate your code syntax:
Correct. This is the ideal time. Running validate immediately after writing your code catches basic syntax errors, typos in attribute names, and incorrect references before you run a more time-consuming plan. This creates an efficient feedback loop: validate your code locally, then if it passes, run plan to see what changes will be made against the real remote state.
D. After you run terraform plan so you can validate that your state file is consistent with your infrastructure:
Incorrect. The plan command itself is the primary tool for detecting inconsistencies (drift) between your state file and real infrastructure. Running validate after plan is redundant for this purpose, as validate does not interact with the state file or real infrastructure at all.

The Logical Order for Code Changes:
Write your code changes.
Run terraform validate to catch quick syntax errors.
Run terraform plan to see the execution plan against the remote API and state.
Run terraform apply to implement the changes.

Reference:
HashiCorp Documentation: Command: validate
"The terraform validate command validates the configuration files in a directory, referring only to the configuration and not to any remote services such as remote state, provider APIs, etc."
Question 20 Choose 2
You have provisioned some virtual machines (VMs) on Google Cloud Platform (GCP) using the gcloud command line tool. However, you are standardizing with Terraform and want to manage these VMs using Terraform instead. What are the two things you must do to achieve this? Choose two correct answers.
Show answerHide answer

Correct answer: B, C Write Terraform configuration for the existing VMsUse the terraform import command for the existing VMs

Explanation

Explanation:
To manage existing GCP VMs with Terraform, you must:

1. Write Terraform Configuration (.tf files)
Terraform requires a resource block that describes the VM you want to manage. This configuration must match the existing VM’s attributes (e.g., name, zone, machine type) so Terraform can associate the resource with the actual infrastructure.
Example:
hcl
resource "google_compute_instance" "example" {
name = "my-vm"
machine_type = "e2-medium"
zone = "us-central1-a"
# other required attributes
}

Reference:
Terraform Google Provider Docs
2. Use terraform import
After writing the configuration, use the terraform import command to link the existing GCP VM to the Terraform state.
Example:
terraform import google_compute_instance.example my-project/us-central1-a/my-vm This command does not create the resource—it simply tells Terraform to track it.

Reference:
Terraform CLI: import

❌ Why Other Options Are Incorrect
A. Run the terraform Import-gcp command
❌ Invalid command. Terraform does not have a command called import-gcp.
D. Provision new VMs using Terraform with the same VM names
❌ This would create duplicate resources. You want to manage existing VMs, not recreate them.

📝 Summary
To bring existing GCP VMs under Terraform management, you must write matching configuration and then import them into state using terraform import. This ensures Terraform can track and manage the resources without recreating them.
Full mock exam

Sit the Terraform-Associate-003 exam before exam day

Full-length mocks with the same number of questions and the same time limit as the real Terraform-Associate-003 exam. Every attempt draws a new set of questions from the full bank, so you can keep going until you pass comfortably.

Get full Terraform-Associate-003 mock exam
  • 65questions per mock
  • 105 mintime limit
  • 194questions in the bank
  • Newmock on every attempt