Quickly and Easily Pass HashiCorp Exam with Terraform-Associate-004 real Dumps Updated on Jun-2026
Realistic Terraform-Associate-004 Dumps Questions To Gain Brilliant Result
HashiCorp Terraform-Associate-004 Exam Syllabus Topics:
| Topic | Details |
|---|---|
| Topic 1 |
|
| Topic 2 |
|
| Topic 3 |
|
| Topic 4 |
|
| Topic 5 |
|
| Topic 6 |
|
NEW QUESTION # 89
What functionality do providers offer in Terraform?(Pick 3 correct responses)
- A. Group a collection of Terraform configuration files that map to a single state file.
- B. Provision resources for on-premises infrastructure services.
- C. Interact with cloud provider APIs.
- D. Enforce security and compliance policies.
- E. Provision resources for public cloud infrastructure services.
Answer: B,C,E
NEW QUESTION # 90
Running terraform fmt without any flags in a directory with Terraform configuration files will check the formatting of those files, but will never change their contents.
- A. False
- B. True
Answer: A
Explanation:
Rationale for Correct answer:By default, terraform fmt modifies files in place to match Terraform's canonical formatting. The -check flag is required to only check formatting without making changes.
Analysis of Incorrect Options (Distractors):
A: Incorrect because formatting changes are applied automatically by default.
Key Concept:terraform fmt enforces consistent formatting by rewriting files unless instructed otherwise.
NEW QUESTION # 91
A resource block is shown in the Exhibit space of this page. What is the Terraform resource name of that resource block?
- A. test
- B. azurerm_resource_group
- C. ev
- D. azurerm
Answer: C
Explanation:
Rationale for Correct Answer:A Terraform resource block has the following structure:
resource " < RESOURCE TYPE > " " < RESOURCE NAME > " {
}
In the exhibit:
Resource type: azurerm_resource_group
Resource name: dev
The resource name is the second label in the resource block and is used internally by Terraform to reference the resource (e.g., azurerm_resource_group.dev).
Analysis of Incorrect Options (Distractors):
A). azurerm: This is the provider name, not the resource name.
B). azurerm_resource_group: This is the resource type, not the name.
D). test: This is the value of the name argument inside the resource, not the Terraform resource name.
Key Concept:Understanding the distinction between resource type, resource name, and resource arguments in Terraform configurations.
Reference:Terraform Exam Objective - Read, Generate, and Modify Configurations
NEW QUESTION # 92
If you manually destroy infrastructure, what is the best practice reflecting this change in Terraform?
- A. It will happen automatically
- B. Run terraform refresh
- C. Run terraform import
- D. Manually update the state fire
Answer: A
Explanation:
If you manually destroy infrastructure, Terraform will automatically detect the change and update the state file during the next plan or apply. Terraform compares the current state of the infrastructure with the desired state in the configuration and generates a plan to reconcile the differences. If a resource is missing from the infrastructure but still exists in the state file, Terraform will attempt to recreate it. If a resource is present in the infrastructure but not in the state file, Terraform will ignore it unless you use the terraform import command to bring it under Terraform's management. Reference = [Terraform State]
NEW QUESTION # 93
What command can you run to generateDOT (Graphviz)formatted data to visualize Terraform dependencies?
- A. terraform graph
- B. terraform output
- C. terraform show
- D. terraform refresh
Answer: A
Explanation:
terraform graphgeneratesGraphviz DOT formatoutput, which allows visualization ofresource dependenciesin Terraform.
A (terraform refresh)- Incorrect, as it only updates the state file.
C (terraform output)- Incorrect, as it only displays Terraform output values.
D (terraform show)- Incorrect, as it only displays the Terraform state.
Official Terraform Documentation Reference:
terraform graph - HashiCorp Documentation
NEW QUESTION # 94
Exhibit:
Error: Saved plan is stale
The given plan file can no longer be applied because the state was changed by another operation after the plan was created.
You have a saved execution plan containing desired changes for infrastructure managed by Terraform. After running terraform apply my.tfplan, you receive the error shown. How can you apply the desired changes? (Pick the 2 correct responses below.)
- A. Update the current plan file using the terraform state push command.
- B. Force the apply command by adding the flag -lock=false.
- C. Run terraform apply without the saved execution plan.
- D. Refresh the current state data using the -refresh-only flag.
- E. Generate a new execution plan file with terraform plan, and apply the new plan.
Answer: C,E
Explanation:
Rationale for Correct answer:
A: The plan is stale because state changed after it was created. The correct fix is to recreate the plan against the latest state and apply that new plan.
B: Running terraform apply without specifying the old plan causes Terraform to re-plan using the current state and configuration, then apply the resulting changes.
Analysis of Incorrect Options (Distractors):
C: -lock=false disables locking; it does not make an old plan valid and is unsafe in team environments.
D: -refresh-only changes what's recorded in state (when applied) but does not "unstale" an existing saved plan file.
E: terraform state push is for advanced/manual state management and does not update a saved plan file; using it here is inappropriate and risky.
Key Concept: Saved plans are tied to a specific state snapshot; if state changes, you must re-plan.
Reference:
NEW QUESTION # 95
You need to destroy all of the resources in your Terraform workspace, except for aws_instance.ubuntu[1], which you want to keep. How can you tell Terraform to stop managing that specific resource without destroying it?
- A. Change the value of the count argument on the resource.
- B. Run terraform state rm aws_instance.ubuntu[1].
- C. Use a moved block.
- D. Remove the resource block from your configuration.
Answer: B
Explanation:
Rationale for Correct Answer: terraform state rm < address > removes a resource from Terraform state without destroying the real infrastructure. After removal, Terraform "forgets" it and will no longer manage it (unless it's re-imported). That matches the requirement: keep the resource, stop managing it.
Analysis of Incorrect Options (Distractors):
A: Removing the resource block causes Terraform to plan to destroy the resource (because it's in state but no longer in config), which is the opposite of "keep it." B: Changing count can cause Terraform to destroy instances that no longer have an address (depending on indexing), and it doesn't explicitly "stop managing" a specific existing instance safely.
D: moved blocks are for renaming/refactoring addresses while keeping management; they do not stop managing a resource.
Key Concept: Detaching resources from Terraform management using state subcommands (terraform state rm).
Reference: Terraform Objectives - Implement and Maintain State (state manipulation), Navigate Terraform State and Backends (state operations).
NEW QUESTION # 96
Which of the following methods, used to provision resources into a public cloud, demonstrates the concept of infrastructure as code?
- A. curl commands manually run from a terminal
- B. A series of commands you enter into a public cloud console
- C. A sequence of REST requests you pass to a public cloud API endpoint Most Voted
- D. A script that contains a series of public cloud CLI commands
Answer: D
Explanation:
The concept of infrastructure as code (IaC) is to define and manage infrastructure using code, rather than manual processes or GUI tools. A script that contains a series of public cloud CLI commands is an example of IaC, because it uses code to provision resources into a public cloud. The other options are not examples of IaC, because they involve manual or interactive actions, such as running curl commands, sending REST requests, or entering commands into a console. Reference = [Introduction to Infrastructure as Code with Terraform] and [Infrastructure as Code]
NEW QUESTION # 97
Before you can use a new backend or HCP Terraform/Terraform Cloud integration, you must first execute terraform init.
- A. True
- B. False
Answer: A
Explanation:
The terraform init command is required before using a new backend or integrating with HCP Terraform
/Terraform Cloud.
terraform init initializes the working directory and sets up the backend, downloading necessary provider plugins and modules.
If the backend configuration changes, Terraform willrequirere-initialization to apply those changes.
Without running terraform init, Terraform willfailto use a new backend or remote Terraform Cloud workspace.
Official Terraform Documentation Reference:
terraform init - HashiCorp Documentation
NEW QUESTION # 98
One cloud block always maps to a single HCP Terraform/Terraform Cloud workspace.
- A. True
- B. False
Answer: A
Explanation:
Rationale for Correct Answer (True):
A cloud block in Terraform configuration specifies a single Terraform Cloud or HCP Terraform workspace. You cannot use one cloud block for multiple workspaces.
Analysis of Incorrect Option:
False: Incorrect because a cloud block is a one-to-one mapping with a single workspace.
Key Concept:
Cloud blocks manage remote operations and backend configuration tied to one workspace.
Reference:
Terraform Exam Objective - Manage Terraform Workspaces and Cloud.
NEW QUESTION # 99
A provider configuration block is required in every Terraform configuration.
Example:
- A. False
- B. True
Answer: A
Explanation:
A provider configuration block is not required in every Terraform configuration. A provider configuration block can be omitted if its contents would otherwise be empty. Terraform assumes an empty default configuration for any provider that is not explicitly configured. However, some providers may require some configuration arguments (such as endpoint URLs or cloud regions) before they can be used. A provider's documentation should list which configuration arguments it expects. For providers distributed on the Terraform Registry, versioned documentation is available on each provider's page, via the "Documentation" link in the provider's header1. References = [Provider Configuration]1
NEW QUESTION # 100
Where can Terraform not load a provider from?
- A. Plugins directory
- B. Provider plugin chance
- C. Official HashCrop Distribution on releases.hashcrop.com
- D. Source code
Answer: D
Explanation:
This is where Terraform cannot load a provider from, as it requires a compiled binary file that implements the provider protocol. You can load a provider from a plugins directory, a provider plugin cache, or the official HashiCorp distribution on releases.hashicorp.com.
NEW QUESTION # 101
The -refresh-only parameter will update your state file when used with terraform plan.
- A. False
- B. True
Answer: A
Explanation:
Rationale for Correct Answer: terraform plan -refresh-only refreshes (reconciles) the state with the real infrastructure only for the purpose of the plan output. It does not persist (write) those updates to the state file.
To actually update the stored state, you must run terraform apply -refresh-only (or a normal terraform apply).
This matches the Terraform CLI objective: plan previews changes; apply makes changes (including writing state).
Analysis of Incorrect Options (Distractors):
A (True): Incorrect because terraform plan does not write state; it only calculates and displays what would change.
Key Concept: The plan vs apply workflow and when Terraform writes state.
Reference: Terraform Objectives - Implement and Maintain State (state behavior and refresh) and Understand Terraform Basics and CLI (plan vs apply workflow).
NEW QUESTION # 102
Which of these are features of HCP Terraform/Terraform Cloud? (Pick the 2 correct responses)
- A. A web-based user interface (UI).
- B. Remote state storage.
- C. Automated infrastructure deployment visualization.
- D. Automatic backups of configuration and state.
Answer: A,B
Explanation:
Terraform Cloud provides features like remote state storage and a web-based user interface for managing your Terraform runs. While it offers robust infrastructure as code capabilities, automatic backups of configuration and state are not directly provided by Terraform Cloud; instead, the state is stored remotely and secured.
References:
Terraform Cloud Features
NEW QUESTION # 103
Exhibit:
data " vsphere_datacenter " " dc " {}
resource " vsphere_folder " " parent " {
path = " Production "
type = " vm "
datacenter_id = _________
}
You want to pass the id of the vsphere_datacenter data source to the datacenter_id argument of the vsphere_folder resource. Which reference would you use?
- A. vsphere_datacenter.dc.id
- B. data.vsphere_datacenter.dc
- C. data.de.id
- D. data.vsphere_datacenter.de.id
Answer: D
Explanation:
Rationale for Correct answer: Data sources are referenced with: data. < TYPE > . < NAME > . < ATTRIBUTE > .For a vSphere datacenter data source, the correct reference to its id is:data.
vsphere_datacenter. < name > .id.# Given the options, only A follows the correct data-source addressing pattern and includes the .id attribute.
Analysis of Incorrect Options (Distractors):
B: Incorrect-missing the data. prefix, so it looks like a managed resource reference.
C: Incorrect-missing the attribute (.id).
D: Incorrect-missing the data source type and name.
Key Concept: Correct HCL reference syntax for data sources.
Reference: Terraform Objectives - Read, Generate, and Modify Configurations (references and expressions).
NEW QUESTION # 104
You created infrastructure outside the Terraform workflow that you now want to manage using Terraform. Which command brings the infrastructure into Terraform state?
- A. terraform import
- B. terraform init
- C. terraform get
- D. terraform refresh
Answer: A
Explanation:
The terraform import command allows Terraform to takeexistinginfrastructure andbring it under Terraform's management.
A (terraform get)is incorrect because it is used to fetch modules.
B (terraform refresh)is incorrect because it only updates Terraform's state to match the infrastructure but does not import resources.
D (terraform init)is incorrect because it only initializes the Terraform working directory.
Official Terraform Documentation Reference:
terraform import - HashiCorp Documentation
NEW QUESTION # 105
You ' re writing a Terraform configuration that needs to read input from a local file called id_rsa.pub . Which built-in Terraform function can you use to import the file ' s contents as a string?
- A. filebase64( " id_rsa.pub " )
- B. file( " id_rsa.pub " )
- C. templaTefil( " id_rsa.pub " )
- D. fileset < " id_rsa.pub " )
Answer: B
Explanation:
To import the contents of a local file as a string in Terraform, you can use the built-in file function. By specifying file( " id_rsa.pub " ), Terraform reads the contents of the id_rsa.pub file and uses it as a string within your Terraform configuration. This function is particularly useful for scenarios where you need to include file data directly into your configuration, such as including an SSH public key for provisioning cloud instances.References = This information is a standard part of Terraform ' s functionality with built-in functions, as outlined in Terraform ' s official documentation and commonly used in various Terraform configurations.
NEW QUESTION # 106
You've used Terraform to deploy a virtual machine and a database. You want to replace this virtual machine instance with an identical one without affecting the database. What is the best way to achieve this using Terraform?
- A. Delete the Terraform VM resources from your Terraform code then run terraform plan and terraform apply
- B. Use the terraform state rm command to remove the VM from state file
- C. Use the terraform apply command targeting the VM resources only
- D. Use the terraform taint command targeting the VMs then run terraform plan and terraform apply
Answer: D
Explanation:
The terraform taint command marks a resource as tainted, which means it will be destroyed and recreated on the next apply. This way, you can replace the VM instance without affecting the database or other resources. References = [Terraform Taint]
NEW QUESTION # 107
What does terraform destroy do?
- A. Destroys all infrastructure in the configured Terraform provider.
- B. Destroys all infrastructure in the Terraform state file.
- C. Destroys the Terraform state file, leaving the infrastructure intact.
- D. Destroys all Terraform code files in the current directory, leaving the state file intact.
Answer: B
Explanation:
* Rationale for Correct answer:terraform destroy removes all resources currently tracked in the Terraform state file by issuing destroy requests to the configured providers. It does not delete configuration files or providers themselves.
* Analysis of Incorrect Options (Distractors):
* B: Terraform never deletes configuration files.
* C: Terraform only destroys resources it manages, not all provider infrastructure.
* D: Terraform does not delete the state file by default.
* Key Concept:terraform destroy enforces removal of all managed infrastructure.
Reference:Terraform Exam Objective - Use Terraform to Manage Infrastructure
NEW QUESTION # 108
Which of the following should you put into the required_providers block?
- A. version = ">= 3.1"
- B. version >= 3.1
- C. version ~> 3.1
Answer: A
Explanation:
The required_providers block is used to specify the provider versions that the configuration can work with.
The version argument accepts a version constraint string, which must be enclosed in double quotes. The version constraint string can use operators such as >=, ~>, =, etc. to specify the minimum, maximum, or exact version of the provider. For example, version = ">= 3.1" means that theconfiguration can work with any provider version that is 3.1 or higher. References = [Provider Requirements] and [Version Constraints]
NEW QUESTION # 109
What is the provider for this resource?
- A. Vpc
- B. aws
- C. Main
- D. Test
Answer: B
Explanation:
In the given Terraform configuration snippet:
resource "aws_vpc" "main" {
name = "test"
}
The provider for the resource aws_vpc is aws. The provider is specified by the prefix of the resource type. In this case, aws_vpc indicates that the resource type vpc is provided by the aws provider.
Reference:
Terraform documentation on providers: Terraform Providers
NEW QUESTION # 110
You are creating a reusable Terraform configuration and want to include an optional billing_dept tag so your Finance team can track team-specific spending on resources. Which of the following billing_dept variable declarations will achieve this?
- A. variable "billing_dept" { default =}
- B. variable "billing_dept" { type = optional(string)}
- C. variable "billing_dept" { optional = true}
- D. variable "billing_dept" { type = default}
Answer: B
Explanation:
Rationale for Correct answer: To make a variable optional, you define a type that allows omission. Using optional(string) indicates the input may be unset (commonly used when the variable is part of an object type, or when you want to explicitly model optionality). This supports reusable configs where the tag is included only when provided.
Analysis of Incorrect Options (Distractors):
A: Invalid syntax-type = default is not a valid type declaration.
B: Invalid syntax-default must have a value.
D: Invalid-there is no optional = true argument for variable blocks.
Key Concept: Input variable type constraints and optional inputs.
Reference:
NEW QUESTION # 111
terraform apply is failing with the following error. What next step should you take to determine the root cause of the problem?
Error:
yaml
CopyEdit
Error loading state: AccessDenied: Access Denied
status code: 403, request id: 288766CE5CCA24A0, host id: web.example.com
- A. Review syslog for Terraform error messages.
- B. Review /var/log/terraform.log for error messages.
- C. Set TF_LOG=DEBUG.
- D. Run terraform login to reauthenticate with the provider.
Answer: C
Explanation:
The error messageindicates an authentication issue (403 - Access Denied), which requiresdebugging Terraform logs.
Setting TF_LOG=DEBUG enablesdetailed logs, providing insights into API requests, state loading, and authentication errors.
Terraformdoes not log errors in /var/log/terraform.log or syslog, making optionsC and D incorrect.
A (terraform login)is only relevant forTerraform Cloud, but this error appears to be related toprovider authentication.
Official Terraform Documentation Reference:
Debugging Terraform
NEW QUESTION # 112
Exhibit:
module " web_stack " {
source = " ./modules/web_stack "
}
Your configuration defines the module block shown in the exhibit. The web_stack module accepts an input variable named servers. Which of the following changes to the module block sets the servers variable to the value of 3?
- A. module " web_stack " {
source = " ./modules/web_stack "
inputs = { servers = 3 }
} - B. module " web_stack " {
source = " ./modules/web_stack "
var.servers = 3
} - C. module " web_stack " {
source = " ./modules/web_stack "
servers = 3
} - D. module " web_stack " {
source = " ./modules/web_stack "
inputs.servers = 3
}
Answer: C
Explanation:
Detailed Explanation:
* Rationale for Correct Answer: Module input variables are set by providing arguments in the module block whose names match the module's declared variables. Since the module expects servers, you pass it directly as servers = 3. This is the standard Terraform module input pattern.
* Analysis of Incorrect Options (Distractors):
* A: Incorrect. var.servers is how you reference an input variable in expressions, not how you assign a module input. Module inputs are set as arguments, not through the var. namespace.
* B: Incorrect. Terraform module blocks do not use an inputs = { ... } argument (that pattern is common in some other tools, but not Terraform).
* D: Incorrect. inputs.servers is not valid HCL syntax for setting module input arguments.
* Key Concept: Passing input variables to modules by setting arguments on the module block.
Reference: Interact with Terraform Modules - module input variables and how they're assigned in a module block.
NEW QUESTION # 113
Outside of the required_providers block, Terraform configurations always refer to providers by their local names.
- A. False
- B. True
Answer: A
Explanation:
Outside of the required_providers block, Terraform configurations can refer to providers by either their local names or their source addresses. The local name is a short name that can be used throughout the configuration, while the source address is a global identifier for the provider in the format registry.terraform.io/namespace/type. For example, you can use either aws or registry.terraform.io/hashicorp/aws to refer to the AWS provider.
NEW QUESTION # 114
......
Start your Terraform-Associate-004 Exam Questions Preparation: https://www.testsimulate.com/Terraform-Associate-004-study-materials.html