HashiCorp Terraform Associate 004 Practice Questions with Explanations
Free HashiCorp Terraform Associate 004 practice questions. 39 of them, each with the correct answer, a full explanation, and the reason every other option is wrong. These are real questions from the 004 exam, not paraphrases, and every explanation is written out rather than just marking the right letter.
They are drawn from the same bank as the full 004 pack, which has 147 questions in total.
Get the full 004 question bank (147 questions) →
004 practice questions
Question 1
IaC (Infrastructure as Code) can be stored in a version control system along with application code.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: A
Infrastructure as Code is specifically designed to be stored in version control systems like Git alongside application code. This enables teams to track changes, collaborate, maintain history, and apply DevOps practices to infrastructure just as they do with application code.
Why the other options are wrong:
- B. IaC is fundamentally built for version control integration and this is a core principle of infrastructure management.
Question 2
It is best practice to store secret data in the same version control repository as your Terraform configuration.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: B
Storing secret data such as API keys, passwords, and credentials directly in a version control repository is a critical security vulnerability. Best practice requires storing secrets in dedicated secret management systems like AWS Secrets Manager, HashiCorp Vault, or environment variables, keeping them separate from code repositories.
Why the other options are wrong:
- A. Storing secrets in version control creates significant security risks as the repository history may expose sensitive data to unauthorized users.
Question 3
Which is an advantage of using IaC (Infrastructure as Code) that is not possible when provisioning with a GUI (Graphical User Interface)?
- A. Let's you version, reuse, and share infrastructure configuration.
- B. Secures your credentials.
- C. Provisions the same resources at a lower cost.
- D. Prevents manual modifications to your resources.
Show answer and explanation ▾
Correct answer: A
The unique advantage of IaC that GUI provisioning cannot provide is the ability to version, reuse, and share infrastructure configuration. IaC allows infrastructure definitions to be treated as code, enabling version control, code reuse across projects, and easy sharing among team members, which are not feasible with GUI-based provisioning.
Why the other options are wrong:
- B. Both IaC and GUI provisioning can be insecure if credentials are mishandled; this is not an IaC-exclusive advantage.
- C. Cost is determined by resource usage, not the provisioning method; both approaches provision identical resources at the same cost.
- D. Neither IaC nor GUI provisioning inherently prevents manual modifications; both require additional controls like role-based access to prevent drift.
Question 4
What is an advantage of immutable infrastructure?
- A. Automatic infrastructure upgrades
- B. In-place infrastructure upgrades
- C. Quicker infrastructure upgrades
- D. Less complex infrastructure upgrades
Show answer and explanation ▾
Correct answer: C
Immutable infrastructure enables quicker infrastructure upgrades because new instances are created with updated configurations and old instances are replaced rather than modified in-place. This approach reduces deployment time, complexity, and the risk of partial failures since the entire infrastructure is replaced atomically.
Why the other options are wrong:
- A. Immutable infrastructure does not provide automatic upgrades; upgrades still require intentional deployment.
- B. Immutable infrastructure explicitly avoids in-place upgrades by replacing entire instances.
- D. While immutable infrastructure can reduce complexity, the primary advantage over mutable approaches is faster deployment speed.
Question 5
What is the primary purpose of IaC (Infrastructure as Code)?
- A. To define a pipeline to test and deliver software.
- B. To provision infrastructure cheaply.
- C. To programmatically create and configure resources.
- D. To define a vendor-agnostic API.
Show answer and explanation ▾
Correct answer: C
The primary purpose of Infrastructure as Code is to programmatically create and configure infrastructure resources. IaC enables infrastructure to be provisioned, modified, and managed through code rather than manual processes, providing repeatability, consistency, and automation.
Why the other options are wrong:
- A. Defining deployment pipelines is the purpose of CI/CD tools, not the primary purpose of IaC.
- B. Cost reduction is a potential benefit but not the primary purpose of IaC.
- D. While some IaC tools may support multiple vendors, defining vendor-agnostic APIs is not the primary purpose of IaC.
Question 6
Your team adopts an AWS CloudFormation as the standardized method for provisioning public cloud resources. Which scenario presents a challenge for your team?
- A. Deploying new infrastructure into Microsoft Azure.
- B. Automating a manual, web console-based provisioning process.
- C. Building a reusable code base that can deploy resources into any AWS region.
- D. Managing a new application stack built on AWS-native services.
Show answer and explanation ▾
Correct answer: A
AWS CloudFormation is AWS-specific and cannot deploy resources to Microsoft Azure or other cloud providers. A team standardized on CloudFormation would face significant challenges when required to provision infrastructure outside the AWS ecosystem, as they would need to learn and adopt different tools for other cloud platforms.
Why the other options are wrong:
- B. CloudFormation is excellent for automating manual web console-based provisioning; this is a primary use case.
- C. CloudFormation supports multi-region deployments within AWS through parameters and regional references.
- D. CloudFormation is designed specifically for managing AWS-native services and workloads.
Question 7
Which is not a benefit of adopting IaC (Infrastructure as Code)?
- A. Reusability of code
- B. Automation
- C. A GUI (Graphical User Interface)
- D. Versioning
Show answer and explanation ▾
Correct answer: C
A GUI (Graphical User Interface) is not a benefit of adopting IaC; in fact, IaC explicitly moves away from GUI-based provisioning toward code-based management. The actual benefits of IaC include reusability of code, automation of infrastructure provisioning, and versioning of infrastructure configurations.
Why the other options are wrong:
- A. Reusability of code is a direct benefit of IaC, allowing templates and modules to be reused across projects.
- B. Automation is a core benefit of IaC, eliminating manual provisioning steps.
- D. Versioning is a fundamental benefit of IaC, enabling infrastructure to be tracked and managed like application code.
Question 8
Your team often uses API calls to create and manage cloud infrastructure. In what ways does Terraform differ from conventional infrastructure management approaches?
- A. Terraform replaces cloud provider APIs with its own protocols, enabling automated deployments.
- B. Terraform describes infrastructure with version-controlled, repeatable configurations that specify the desired state.
- C. Terraform is merely a wrapper for cloud provider APIs, so there is little to no difference in calling the API directly.
- D. Terraform enforces infrastructure through imperative scripts to ensure tasks are completed in the proper order.
Show answer and explanation ▾
Correct answer: B
Terraform describes infrastructure with version- controlled, repeatable configurations that specify the desired state. Terraform differs fundamentally from conventional infrastructure management by using declarative configuration files that describe the desired state of infrastructure. These configurations are version-controlled, repeatable, and enable teams to manage infrastructure through code rather than manual API calls or imperative scripts. Terraform abstracts away the complexity of directly calling cloud provider APIs while maintaining compatibility with them.
Why the other options are wrong:
- A. Terraform does not replace cloud provider APIs; it abstracts and simplifies interaction with them.
- C. While Terraform uses cloud provider APIs under the hood, it provides significant abstraction and differs substantially from calling APIs directly.
- D. Terraform uses declarative configuration, not imperative scripts, to define the desired state rather than procedural steps.
Question 9
Which of these workflows is only enabled by the use of Infrastructure as Code?
- A. Automatic scaling of resources based on application load.
- B. Cost optimization of infrastructure deployment.
- C. Role-based access control of cloud resources.
- D. Reviewing the proposed changes for potential security issues.
Show answer and explanation ▾
Correct answer: D
Reviewing proposed changes for potential security issues is uniquely enabled by Infrastructure as Code. When infrastructure is defined as code, changes can be submitted as code reviews (pull requests) before deployment, allowing security teams and peers to inspect the changes for vulnerabilities and policy violations. Options A, B, and C can all be accomplished through various means independent of IaC.
Why the other options are wrong:
- A. Automatic scaling is enabled by cloud provider features and can be configured manually or through IaC.
- B. Cost optimization can be achieved through manual resource selection and cloud provider cost analysis tools.
- C. Role-based access control is a cloud provider feature independent of whether infrastructure is managed through code.
Question 10
What does Terraform use to deploy infrastructure for different cloud providers?
- A. Custom APIs developed by HashiCorp
- B. Vendors' CLI tools
- C. Vendors' UI
- D. Vendor-specific providers
Show answer and explanation ▾
Correct answer: D
Terraform uses vendor-specific providers to deploy infrastructure for different cloud platforms. Each provider contains the logic to interact with a particular cloud service's API, abstracting the vendor's API complexity into a consistent Terraform configuration syntax. Providers are the core mechanism enabling Terraform to work across AWS, Azure, Google Cloud, and thousands of other platforms.
Why the other options are wrong:
- A. Terraform uses vendor APIs, not custom APIs developed by HashiCorp, to interact with cloud services.
- B. Terraform does not depend on or wrap vendors' CLI tools for deployment.
- C. Terraform does not use cloud provider UIs; it interacts programmatically through APIs via providers.
Question 11
How can you enable verbose logging to troubleshoot?
- A. Set the log level command line flag.
- B. Set the TF_LOG environment variable.
- C. Set the log level in your terraform block.
Show answer and explanation ▾
Correct answer: B
The TF_LOG environment variable enables verbose logging in Terraform for troubleshooting purposes. Setting this variable to DEBUG, TRACE, or other log levels outputs detailed diagnostic information about Terraform's execution, API calls, and internal operations. This is the standard and documented method for enabling verbose logging in Terraform.
Why the other options are wrong:
- A. Terraform does not use a log level command line flag for verbose logging.
- C. While the terraform block configures provider behavior and backend settings, it is not used to set logging verbosity.
Question 12
Which command lets you experiment with Terraform expressions?
- A. terraform console
- B. terraform env
- C. terraform validate
- D. terraform test
Show answer and explanation ▾
Correct answer: A
The terraform console command provides an interactive REPL environment where you can experiment with and evaluate Terraform expressions, functions, and variable values. This is useful for testing expressions before using them in configurations or for debugging complex variable interpolations.
Why the other options are wrong:
- B. terraform env manages Terraform workspaces and is not used for expression evaluation.
- C. terraform validate checks configuration syntax and validity but does not provide an interactive expression environment.
- D. terraform test runs test files but does not provide an interactive console for expression experimentation.
Question 13
You can install Community/Partner plugins using terraform init.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: A
The terraform init command can install Community and Partner providers and plugins from the Terraform Registry. When you reference a provider in your configuration, terraform init automatically downloads and installs the required provider, enabling use of community- developed and vendor-partner plugins alongside official providers.
Question 14
Terraform can only manage resource dependencies if you set them explicitly with the depends_on argument.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: B
Terraform automatically infers resource dependencies based on resource references and attributes without requiring explicit depends_on arguments. When one resource references another resource's output or attribute, Terraform builds a dependency graph and deploys resources in the correct order automatically. The depends_on argument is only necessary for implicit dependencies that Terraform cannot detect from configuration references.
Why the other options are wrong:
- A. Terraform infers most dependencies automatically from resource references; explicit depends_on is only needed for implicit dependencies.
Question 15
Which of the following is not a valid Terraform collection type?
- A. set
- B. list
- C. map
- D. tree
Show answer and explanation ▾
Correct answer: D
Terraform supports three collection types: list, map, and set. The tree type does not exist in Terraform's type system. Lists are ordered collections of values of the same type, maps are key-value pairs, and sets are unordered collections of unique values.
Why the other options are wrong:
- A. Set is a valid Terraform collection type for storing unique values.
- B. List is a valid Terraform collection type for ordered sequences.
- C. Map is a valid Terraform collection type for key-value pairs.
Question 16
A resource block is space of this page. resource "aws_vpc" "main" { name = "test" } What is the provider for this resource?
- A. main
- B. vpc
- C. aws
- D. test
Show answer and explanation ▾
Correct answer: C
In a Terraform resource block, the provider is the first argument in the resource declaration. The syntax is resource "provider_type" "local_name", so in resource "aws_vpc" "main", the provider is aws. The resource type is vpc and main is the local reference name.
Why the other options are wrong:
- A. Main is the local name assigned to this resource instance, not the provider.
- B. Vpc is the resource type within the aws provider, not the provider itself.
- D. Test is a value assigned to the name argument, not the provider.
Question 17
You must use different Terraform commands depending on the cloud provider you use.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: B
Terraform is cloud-agnostic and uses the same core commands regardless of the target cloud provider. The terraform plan, apply, destroy, and other commands work identically whether deploying to AWS, Azure, Google Cloud, or any other supported provider. The differences are handled through provider configurations, not different commands.
Why the other options are wrong:
- A. This is false; Terraform uses the same commands across all cloud providers.
Question 18
Terraform providers are always installed from the internet.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: B
Terraform providers are not always installed from the internet. Providers can be installed from the Terraform Registry, local filesystem, or other sources. Additionally, once a provider is cached locally, Terraform can use the cached version without downloading from the internet. The terraform init command manages provider installation based on the configuration.
Why the other options are wrong:
- A. This is false; providers can be sourced locally or from caches without internet access.
Question 19
You need to determine from which paths Terraform is loading the providers referenced in your *.tf files. How can you enable additional logging to see this information?
- A. Set the environment variable TF_VAR_log=TRACE.
- B. Set the environment variable TF_LOG=TRACE.
- C. Set the environment variable TF_LOG=PATH.
- D. Set verbose logging for each provider in your Terraform configuration.
Show answer and explanation ▾
Correct answer: B
The TF_LOG environment variable controls Terraform logging verbosity, with TRACE being the most detailed level that shows provider loading paths and other low-level operations. Setting TF_LOG=TRACE enables the diagnostic output needed to see from which paths providers are being loaded.
Why the other options are wrong:
- A. TF_VAR_log is not a valid environment variable; TF_VAR prefix is for input variables.
- C. PATH is not a valid TF_LOG value; the correct value is TRACE.
- D. Verbose logging is not configured per-provider in the Terraform configuration file; it uses the TF_LOG environment variable.
Question 20
Terraform requires using a different provider for each cloud provider where you want to deploy resources.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: A
Terraform requires a different provider for each cloud platform. Each provider (aws, azurerm, google, etc.) has its own configuration and manages resources specific to that cloud platform. To deploy to multiple clouds, you must explicitly configure and use multiple providers.
Why the other options are wrong:
- B. This is false; Terraform requires different providers for different cloud platforms.
Question 21
Terraform cannot use a newly-defined cloud backend until it has been initialized with terraform init.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: A
Terraform requires the terraform init command to initialize a backend configuration before it can be used. This command sets up the backend infrastructure, validates the configuration, and prepares Terraform to manage state using that backend. Without running terraform init, Terraform cannot interact with a newly-defined backend.
Why the other options are wrong:
- B. This is false; terraform init is mandatory for initializing a new backend.
Question 22
You have a list of numbers that represents the number of free CPU cores on each virtual cluster: numcpus = [ 18, 3, 7, 11, 2] What Terraform built-in function would you use to select the largest number from the list?
- A. top(numcpus)
- B. max(numcpus)
- C. ceil(numcpus)
- D. high[numcpus]
Show answer and explanation ▾
Correct answer: B
The max() function is the Terraform built-in function that returns the largest value from a list of numbers. When called with a list like numcpus, it evaluates all elements and returns the maximum value, which would be 18 in this case.
Why the other options are wrong:
- A. top() is not a valid Terraform function.
- C. ceil() rounds a number up to the nearest integer but does not select the maximum from a list.
- D. high[numcpus] is not valid Terraform syntax; indexing with brackets is for accessing specific elements, not finding the maximum.
Question 23
Which of these is stored in the .terraform directory?
- A. Providers and modules
- B. Lock file
- C. State file
- D. Configuration files
Show answer and explanation ▾
Correct answer: A
The .terraform directory stores downloaded providers and modules required by your configuration. When you run terraform init, Terraform downloads the necessary providers and modules into this directory so they can be used during planning and applying. The lock file is stored at the root level as .terraform.lock.hcl, the state file is stored at the root as terraform.tfstate, and configuration files remain in your working directory.
Why the other options are wrong:
- B. The lock file (.terraform.lock.hcl) is stored in the root directory, not in .terraform.
- C. The state file (terraform.tfstate) is stored in the root directory, not in .terraform.
- D. Configuration files are stored in your working directory, not in .terraform.
Question 24
A variable block is shown in the Exhibit space on this page: You will use this variable as the value for the tags argument in several resources. The data format must be a set of key value pairs. Which type argument would you use?
- A. type = map(string)
- B. type = any
- C. type = list(string)
- D. type = object({ tags = string})
Show answer and explanation ▾
Correct answer: A
The variable 'tags' needs to store metadata tags as key-value pairs for resources. In Terraform, a map(string) type is the standard and most appropriate choice for representing a collection of key-value pairs where both keys and values are strings. This allows users to pass tags like {environment = "prod", team = "devops"} to resources. The map type natively supports the key-value pair structure required for tagging resources across multiple Terraform resources.
Why the other options are wrong:
- B. type = any is too permissive and lacks type safety; it defeats the purpose of variable validation and doesn't explicitly communicate that key-value pairs are expected.
- C. type = list(string) represents an ordered collection of strings, not key-value pairs, making it unsuitable for metadata tags that require distinct keys and values.
- D. type = object({tags = string}) defines an object with a single 'tags' property of string type, not a collection of key-value pairs, and would not properly represent multiple tag entries.
Question 25
Which of the following is allowed as a Terraform variable name?
- A. name
- B. source
- C. version
- D. count
Show answer and explanation ▾
Correct answer: A
The variable name 'name' is a valid identifier for a Terraform variable. The options 'source', 'version', and 'count' are reserved keywords or meta-arguments in Terraform that cannot be used as variable names. Reserved words and meta-arguments are protected syntax elements that serve specific purposes in Terraform configurations.
Why the other options are wrong:
- B. source is a reserved keyword used in module and provider blocks.
- C. version is a reserved keyword used in provider version constraints.
- D. count is a reserved meta-argument used for resource iteration.
Question 26
Terraform providers are part of the Terraform core binary.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: B
Terraform providers are not part of the core binary. Providers are separate plugins that Terraform downloads and manages independently. The Terraform core binary contains the language interpreter and primary commands, while providers are distributed separately and downloaded on demand during terraform init based on your configuration requirements.
Question 27
Where can Terraform not load a provider from?
- A. Provider plugin cache
- B. Source code
- C. Official HashiCorp distribution on releases.hashicorp.com
- D. Plugins directory
Show answer and explanation ▾
Correct answer: B
Terraform cannot load a provider from source code directly. Providers must be compiled binaries. Terraform can load providers from the provider plugin cache (local directory), the official HashiCorp distribution on releases.hashicorp.com, and the plugins directory. Source code would need to be compiled first before it could be used as a provider plugin.
Why the other options are wrong:
- A. Terraform can load providers from the local provider plugin cache.
- C. Terraform can load providers from the official HashiCorp releases.hashicorp.com distribution.
- D. Terraform can load providers from the plugins directory in .terraform.
Question 28
terraform init creates an example main.tf file in the current directory.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: B
The terraform init command does not create an example main.tf file. It only initializes the working directory by downloading necessary providers and modules based on existing configuration files. You must create your own configuration files before or after running init. The command prepares the environment but does not generate sample Terraform code.
Question 29
Which command must you run before you run a plan or apply for the first time?
- A. terraform validate
- B. terraform workspace
- C. terraform import
- D. terraform init
Show answer and explanation ▾
Correct answer: D
The terraform init command must be run first before any plan or apply operation. This command initializes the working directory, downloads required providers and modules, and prepares the environment for Terraform operations. Without running init, Terraform lacks the necessary dependencies to execute plans or apply configurations.
Why the other options are wrong:
- A. terraform validate checks configuration syntax but does not initialize the working directory.
- B. terraform workspace manages state file workspaces but is not a prerequisite.
- C. terraform import brings existing resources into state but requires init to have already run.
Question 30
As a developer, you want to ensure your plugins are up-to-date with the latest versions. Which Terraform command should you use?
- A. terraform apply -upgrade
- B. terraform providers -upgrade
- C. terraform init -upgrade
- D. terraform refresh -upgrade
Show answer and explanation ▾
Correct answer: C
The terraform init -upgrade command downloads and installs the latest versions of providers and modules allowed by version constraints in your configuration. The -upgrade flag tells init to check for and download newer versions rather than using cached versions. This is the correct way to ensure plugins are up-to-date with the latest compatible versions.
Why the other options are wrong:
- A. terraform apply does not have an -upgrade flag for provider updates.
- B. terraform providers does not accept an -upgrade flag; it only lists provider information.
- D. terraform refresh does not have an -upgrade flag for updating providers.
Question 31
You modified your local Terraform configuration and ran terraform plan to review the changes. Simultaneously, your teammate manually modified the infrastructure component you are working on. Since you already ran terraform plan locally, the execution plan for terraform apply will be the same.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: B
When terraform plan is executed, it captures the current state at that moment. If a teammate manually modifies infrastructure between your terraform plan and terraform apply, the actual infrastructure state has changed. When terraform apply runs, it will refresh the state and detect these manual changes, potentially resulting in a different execution plan than what was originally generated by terraform plan.
Why the other options are wrong:
- A. The execution plan will differ because Terraform will detect the manual infrastructure changes made after the plan was created.
Question 32
Which is the correct workflow for deploying new infrastructure with Terraform?
- A. 1. Write Terraform configuration. 2. Run terraform apply to create infrastructure. 3. Use terraform validate to confirm Terraform deployed resources correctly.
- B. 1. Write Terraform configuration. 2. Run terraform init to initialize the working directory or workspace. 3. Run terraform apply.
- C. 1. Write Terraform configuration. 2. Run terraform plan to initialize the working directory or workspace. 3. Run terraform apply to create the infrastructure.
- D. 1. Write Terraform configuration. 2. Run terraform show to view proposed changes. 3. Run terraform apply to create new infrastructure.
Show answer and explanation ▾
Correct answer: B
The correct workflow requires initializing the working directory first with terraform init, which downloads provider plugins and sets up the backend. After initialization, terraform plan reviews changes and terraform apply executes them. Option A skips initialization and validation order is wrong. Option C incorrectly states terraform plan initializes the directory. Option D uses terraform show instead of plan.
Why the other options are wrong:
- A. This skips the critical terraform init step and runs validate after apply, which is backwards.
- C. terraform plan does not initialize the working directory; terraform init is required for that purpose.
- D. terraform show displays existing state, not proposed changes; terraform plan is needed for that.
Question 33
After creating a new Terraform configuration, your config passes terraform validate but gives an "Access Denied" error from the cloud provider when running terraform plan. Why didn't validate catch this issue?
- A. The working directory was not initialized, so the cloud provider plugin wasn't available to use when running the terraform validate command.
- B. The remote backend wasn't configured, so terraform validate couldn't load the state and detect the missing credentials.
- C. terraform validate only checks if a configuration is syntactically correct and internally consistent, and does not communicate with providers.
- D. Variables are only applied and validated during a terraform plan, so validate assumed defaults and returned the success message.
Show answer and explanation ▾
Correct answer: C
terraform validate performs only syntactic and internal consistency checking of the configuration code itself. It does not interact with cloud providers, authenticate credentials, or contact remote systems. Authentication errors only surface when terraform plan attempts to communicate with the actual provider, requiring valid credentials and permissions.
Why the other options are wrong:
- A. The working directory does not need to be initialized for validate to work, and validate does not use provider plugins.
- B. The remote backend configuration is not required for validate to function; validate works locally on syntax alone.
- D. Variables are validated during terraform plan and apply, but this is unrelated to why provider authentication errors are not caught by validate.
Question 34
Only the user that generated a terraform plan may apply it.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: B
Terraform plans are not locked to specific users. Any user with appropriate credentials and access to the state file can apply a plan that was created by another user. Plans are simply stored execution specifications that can be passed between team members and applied by whoever has the necessary permissions.
Why the other options are wrong:
- A. There is no restriction in Terraform requiring the same user to both generate and apply a plan.
Question 35
terraform apply will fail if you have not run terraform plan first to update the plan output.
- A. True
- B. False
Show answer and explanation ▾
Correct answer: B
terraform apply can be executed independently without a preceding terraform plan command. When apply runs without a saved plan file, it automatically generates its own plan internally and then executes it after confirmation. The terraform plan command is optional and useful for review purposes, but not a prerequisite for apply.
Why the other options are wrong:
- A. terraform apply is designed to work standalone and will generate its own plan if one is not provided.
Question 36
What's the proper syntax for the plan command?
- A. terraform plan -generate-config-out=tfplan
- B. terraform plan -target=tfplan
- C. terraform plan -out=tfplan
- D. terraform plan -var-file=tfplan
Show answer and explanation ▾
Correct answer: C
The correct syntax for saving a terraform plan to a file is terraform plan -out=tfplan. This flag specifies the output location for the plan file, which can then be passed to terraform apply for deterministic execution. The -out flag is the standard Terraform option for this purpose.
Why the other options are wrong:
- A. -generate-config-out is not a valid terraform plan flag.
- B. -target is used to select specific resources, not to save plan output.
- D. -var-file is used to pass variable values from a file, not to output plans.
Question 37
Which syntax check returns an error when you run terraform validate?
- A. None of these will return an error.
- B. There is a missing variable block.
- C. The state file does not match the current infrastructure.
- D. The code contains tabs for indentation instead of spaces.
Show answer and explanation ▾
Correct answer: A
terraform validate only checks syntax and internal consistency of configuration code. None of the listed options will actually cause validate to return an error. Missing variable blocks are allowed in Terraform, state file mismatches are not checked by validate, and indentation with tabs versus spaces is not validated (HCL is flexible with whitespace).
Why the other options are wrong:
- B. Missing variable blocks are syntactically valid in Terraform and do not cause validate to error.
- C. State file mismatches are not checked by validate; that is a runtime concern during plan or apply.
- D. Terraform's HCL parser accepts both tabs and spaces for indentation without error.
Question 38
What is the purpose of the .terraform directory in a Terraform workspace?
- A. The directory contains plugins and modules that Terraform downloads during initialization, along with other important information.
- B. The directory contains the provide credentials and the .tfvars files to prevent them from being committed to version control by accident.
- C. The directory is where Terraform creates and maintains the state file to track the underlying resources it creates and manages.
- D. The directory is used to convert and store Terraform configuration files into API calls to communicate with the targeted platform.
Show answer and explanation ▾
Correct answer: A
The .terraform directory is created during terraform init and stores downloaded provider plugins, modules, and backend configuration data. It is essential for Terraform's operation and should not be committed to version control. Option C incorrectly describes where the state file is stored (typically as terraform.tfstate in the working directory, not within .terraform). Option B describes files that should be gitignored but not stored in .terraform. Option D describes the function of providers themselves, not the directory.
Why the other options are wrong:
- B. Credential files and .tfvars are kept outside .terraform and managed separately through .gitignore.
- C. The state file is stored in the working directory as terraform.tfstate, not inside the .terraform directory.
- D. Conversion to API calls is the function of providers, not the purpose of the .terraform directory.
Question 39
How can terraform plan aid in the development process?
- A. Validates your expectations against the execution plan without permanently modifying state.
- B. Reconciles Terraform's state against deploys resources and permanently modifies state using the current status of deployed resources.
- C. Initializes your working directory containing your Terraform configuration files.
- D. Formats your Terraform configuration files.
Show answer and explanation ▾
Correct answer: A
terraform plan generates an execution plan showing what changes will be made to infrastructure without actually applying them. This allows you to review and validate that the planned changes match your expectations before committing them. Option B describes terraform apply, not plan. Option C describes terraform init. Option D describes terraform fmt.
Why the other options are wrong:
- B. This describes terraform apply behavior, which actually modifies state and resources.
- C. This describes the terraform init command, not plan.
- D. This describes the terraform fmt command for code formatting.
Get the complete 004 bank
These 39 questions are roughly 30% of the bank. The full pack has 147 real 004 questions, each with the same depth of explanation, plus a questions-only PDF for timed practice and free updates forever.
View the full HashiCorp Terraform Associate 004 question bank →