HashiCorpAssociate levelPage 2 of 3

HashiCorp Terraform Associate (004) exam dumps: questions 101 to 200 of 223

Page 2 of the free HashiCorp Terraform Associate (004) question bank for the Terraform Associate 004 exam. Questions 101 to 200 are listed below, the first 5 in full with answers and explanations. Back to page 1 for the exam overview and FAQ.

Question bank last updated June 2026

Free HashiCorp Terraform Associate (004) practice questions

Questions 101 to 105 of 223

Pick an answer before you open the explanation. Each question also has its own page with a permalink.

HashiCorp Terraform Associate (004) Question 101

Single answer4c Use variables and outputs

A platform team maintains a reusable Terraform module that creates an application load balancer and returns its DNS name. Several application teams consume this module from a separate root configuration and want to avoid hardcoding environment-specific values. The platform team also wants to prevent accidental disclosure of a database password passed into the root module during CLI runs. Which configuration best meets these requirements?

  1. A

    Define input variables in the root module for environment-specific values, pass them into the child module through module arguments, declare the database password variable as sensitive = true, and expose the load balancer DNS name from the child module with an output that the root module can reference.

  2. B

    Store all environment-specific values directly inside the child module, mark the load balancer DNS name output as sensitive, and rely on terraform.tfstate to share the value with application teams instead of defining outputs in the root module.

  3. C

    Use local values instead of input variables for environment-specific settings, because locals can be overridden per workspace, and mark the database password output as sensitive so Terraform will not store it in state.

  4. D

    Pass the database password to the child module through an output from the root module, because outputs are the preferred way to send values into modules, and define the load balancer DNS name as a variable in the root module so downstream consumers can read it.

Show answer and explanation

Correct answer: A

Explanation

This scenario tests the correct use of Terraform variables and outputs in a modular design. Best practice is to define environment-specific values as input variables in the root module, optionally set them via tfvars files, CLI flags, environment variables, or Terraform Cloud workspace variables, and then pass them into child modules through module arguments. Child modules return useful computed values, such as a load balancer DNS name, through output blocks. Sensitive input variables can be marked with sensitive = true to reduce exposure in Terraform CLI output, but candidates should remember that sensitivity does not encrypt or remove values from state. Terraform documentation on input variables, output values, module composition, and managing sensitive data all support this pattern.

  • A. Correct.

    Correct. In Terraform, input variables are the standard mechanism for supplying environment-specific values to a root module, and module input arguments are how those values are passed to child modules. Child modules expose values back using output blocks. Marking a variable as sensitive = true helps reduce accidental disclosure in CLI output and plan/apply displays. This matches Terraform's intended flow: variables into modules, outputs out of modules.

  • B. Incorrect.

    Incorrect. Hardcoding environment-specific values inside a reusable child module reduces reusability and makes the module harder to use across environments. Also, outputs are the supported mechanism for exposing values from modules; consumers should not rely on directly reading state files as a sharing strategy. Marking the load balancer DNS name as sensitive is unnecessary unless the value is actually sensitive.

  • C. Incorrect.

    Incorrect. Local values are derived expressions within a module and are not designed as externally supplied inputs. They cannot be overridden the way input variables can. Also, marking an output as sensitive does not prevent a secret from being stored in state; sensitive values are still recorded in state unless handled through provider-specific mechanisms outside Terraform.

  • D. Incorrect.

    Incorrect. Outputs are used to expose values from a module, not to pass values into a child module. To send a database password from the root module to a child module, you use a module argument tied to an input variable in the child module. Likewise, the load balancer DNS name should be produced as an output from the child module, not defined as an input variable in the root module.

HashiCorp Terraform Associate (004) Question 102

Single answer4c Use variables and outputs

Your team maintains a reusable Terraform module that provisions an application load balancer and returns its DNS name. Another team calls this module from a root module and wants to control the environment-specific naming convention while also displaying the final DNS name after apply. They want a solution that keeps the module reusable across dev, staging, and prod without hardcoding values inside the module. Which approach best meets these requirements?

  1. A

    Define an input variable in the child module for the environment name, use that variable in resource naming, and define an output in the child module for the load balancer DNS name. In the root module, pass the environment value into the module block and reference the child module output.

  2. B

    Reference a root module local value directly from inside the child module for the environment name, and print the load balancer DNS name using terraform console after apply instead of defining an output.

  3. C

    Create the environment name as an output in the root module so the child module can read it automatically, and define the load balancer DNS name only as a local value inside the child module.

  4. D

    Hardcode the environment name inside the child module for consistency, and expose the load balancer DNS name by reading the state file manually from the root module.

Show answer and explanation

Correct answer: A

Explanation

Terraform modules are designed to have clear interfaces: input variables accept values into a module, and outputs return selected values to the caller. In this scenario, the child module should declare a variable such as environment and use it in naming logic, while also declaring an output for the load balancer DNS name. The root module passes the environment-specific value in the module block and can reference the result with module.<module_name>.<output_name>. This is consistent with Terraform documentation and best practices for reusable modules. A key exam concept is understanding that variables flow into modules, outputs flow out of modules, and values are not shared implicitly across module boundaries.

  • A. Correct.

    Correct. This is the standard Terraform pattern for reusable modules: pass configurable values into a child module using input variables and expose values from the child module using outputs. The root module can set different values for different environments in the module block, and then reference the returned value as module... This keeps the module portable and avoids coupling it to a specific environment.

  • B. Incorrect.

    Incorrect. Child modules cannot directly access local values, variables, or resources from the root module unless those values are explicitly passed in as input arguments. Also, using terraform console is not a substitute for a module output when a value should be intentionally exposed for downstream use or visibility after apply.

  • C. Incorrect.

    Incorrect. Outputs do not flow automatically from the root module into child modules. Outputs expose values outward from a module to its caller; they are not an input mechanism. Likewise, if the DNS name needs to be exposed to the calling module, defining it only as a local value in the child module will not make it available outside that module.

  • D. Incorrect.

    Incorrect. Hardcoding the environment name inside the child module reduces reusability and violates the requirement to support multiple environments without changing module code. Reading the state file manually is not the intended mechanism for consuming module values; outputs are the supported and safer interface for exposing data from a module.

HashiCorp Terraform Associate (004) Question 103

Single answer4c Use variables and outputs

A team maintains a reusable Terraform module that creates an AWS application stack. The module already defines an input variable instance_count and creates an Application Load Balancer. Another team wants to consume this module from a root configuration, set instance_count differently for dev and prod, and expose the ALB DNS name after terraform apply so it can be used by a deployment script. Which approach best meets these requirements while following Terraform best practices for variables and outputs?

  1. A

    Define instance_count as an input variable in the module, pass environment-specific values from the root module using .tfvars files or -var-file, and add an output block in the module for the ALB DNS name that the root module can expose if needed.

  2. B

    Hardcode instance_count inside the child module for each environment and read the ALB DNS name directly from the Terraform state file in the deployment script instead of defining outputs.

  3. C

    Set instance_count by editing .terraform/terraform.tfstate before each run, and use terraform console in the deployment script to look up the ALB DNS name after apply.

  4. D

    Use an environment variable only for the ALB DNS name, but keep instance_count as a local value inside the child module so consumers cannot override it.

Show answer and explanation

Correct answer: A

Explanation

Terraform distinguishes between input variables, which parameterize configurations and modules, and outputs, which expose values after planning/applying. In this scenario, instance_count should remain an input variable so the root module can provide different values for dev and prod through variable assignment methods such as terraform.tfvars, *.auto.tfvars, CLI -var or -var-file, or environment variables using the TF_VAR_name convention. The ALB DNS name is a computed value from managed resources, so it should be exposed with an output block in the child module and optionally re-exposed by the root module for external consumption. This matches Terraform best practices and the documented module interface model: variables define what goes into a module, and outputs define what comes out of it. Using outputs is also preferable to parsing state directly, since outputs provide a stable, intentional interface for users and automation.

  • A. Correct.

    Correct. This is the recommended Terraform pattern. Input variables let module consumers provide environment-specific values without modifying module code. In practice, the root module can pass values through variable definitions, terraform.tfvars, *.auto.tfvars, or -var-file. Outputs are the supported way to expose useful values, such as an ALB DNS name, from a child module to the root module and then to external tooling. This keeps the module reusable and avoids coupling automation to the raw state format.

  • B. Incorrect.

    Incorrect. Hardcoding environment-specific values inside the child module makes the module less reusable and forces code changes for each environment. Reading values directly from the state file is also not a best practice for normal consumption because outputs are the intended interface for exposing values. State structure is an implementation detail and may include sensitive or internal data not meant for external scripts.

  • C. Incorrect.

    Incorrect. Terraform state should not be manually edited to set variable values. Variable values are supplied through Terraform's input variable mechanisms, not by changing state. Using terraform console as part of a deployment script to extract values is also not the normal interface for automation. Outputs, especially via terraform output, are the proper way to retrieve post-apply values.

  • D. Incorrect.

    Incorrect. Environment variables can be used to set input variables with the TF_VAR_ prefix, but an ALB DNS name created by resources is not an input that should be provided externally. It should be exposed as an output. Keeping instance_count as an unchangeable local value in the child module prevents consumers from configuring the module per environment, which conflicts with the scenario's requirement.

HashiCorp Terraform Associate (004) Question 104

Single answer4c Use variables and outputs

A team maintains a reusable Terraform module that creates a virtual network and several subnets. They want the root module to supply a map of subnet definitions, and they want other parts of the configuration to consume the created subnet IDs after apply. The current implementation uses hard-coded subnet values inside the module, which makes it difficult to reuse across environments. Which approach best improves this design while following Terraform best practices for variables and outputs?

  1. A

    Define an input variable in the module for the subnet definitions, pass environment-specific values from the root module, and expose the created subnet IDs with an output value.

  2. B

    Place the subnet definitions directly in a local value inside the child module and use terraform console to read the subnet IDs after apply instead of defining outputs.

  3. C

    Define the subnet map as an output in the root module so child modules can read it automatically, and hard-code the resulting subnet IDs in dependent resources.

  4. D

    Store the subnet definitions in a tfstate file and reference them directly from the module so the module can avoid variables and outputs.

Show answer and explanation

Correct answer: A

Explanation

Terraform modules should define clear interfaces: input variables for values passed into the module and output values for data exposed from the module. In this scenario, the subnet definitions vary by environment, so they should be passed from the root module into the child module using a variable, often with a structured type such as map(object(...)) for validation and clarity. After the subnets are created, the module should return their IDs through outputs so the root module or dependent resources can reference them. This follows Terraform documentation and best practices for module composition, reusability, and dependency handling. Local values are internal-only helpers, not external interfaces. Outputs are the proper mechanism for exporting resource attributes, and child modules cannot automatically read root outputs.

  • A. Correct.

    Correct. This is the recommended Terraform pattern. Input variables make a module reusable by allowing callers to provide environment-specific values, such as a map of subnet definitions. Output values are the supported way to expose data from a child module, such as created subnet IDs, to the root module or other consuming configurations. This matches Terraform's intended module interface design: variables for input, outputs for exported results.

  • B. Incorrect.

    Incorrect. Local values are useful for internal transformation or reducing repetition, but they are not a substitute for module inputs when the values need to vary by environment. Using terraform console is also not a mechanism for passing values between resources or modules; it is only an interactive inspection tool. Without outputs, other parts of the configuration cannot reliably consume the subnet IDs.

  • C. Incorrect.

    Incorrect. Outputs do not flow downward into child modules. Child modules receive values only through input arguments that map to declared variables. Also, hard-coding generated subnet IDs in dependent resources defeats the purpose of Terraform dependency management and breaks portability across environments.

  • D. Incorrect.

    Incorrect. Terraform state is not intended to be used as a general input source for module configuration. Directly relying on tfstate contents instead of variables and outputs is not a best practice and creates tight coupling and fragility. When sharing data across configurations, Terraform supports explicit mechanisms such as outputs and, in some cases, remote state data sources, but not using state files as a replacement for module interfaces.

HashiCorp Terraform Associate (004) Question 105

Single answer4c Use variables and outputs

A team maintains a reusable Terraform module that creates a VPC and several subnets. Multiple application teams consume this module from separate root configurations. The networking team wants consumers to be able to override the CIDR block when needed, but use a safe default otherwise. They also want each consuming root module to easily access the VPC ID after apply so it can be passed to other modules. Which configuration best meets these requirements using Terraform variables and outputs?

  1. A

    Define a variable in the child module for the CIDR block with a default value, use that variable in the VPC resource, and define an output in the child module that exposes the VPC ID. In the root module, optionally set the variable when calling the module and reference module.network.vpc_id where needed.

  2. B

    Hardcode the CIDR block inside the child module and define a local value in the root module for the VPC ID so other modules can read it after apply.

  3. C

    Define the CIDR block as an output in the child module and pass the VPC ID into the root module as an input variable after the VPC is created.

  4. D

    Create a terraform.tfvars file inside the child module to store the CIDR block default and use an output in the root module to automatically expose all child module resource attributes.

Show answer and explanation

Correct answer: A

Explanation

Terraform separates configurable inputs and exported values through variables and outputs. In reusable module design, define input variables in the child module for values callers may customize, optionally with default values for sensible behavior when no override is provided. Define outputs in the child module for values the caller needs after resource creation, such as IDs, ARNs, or IPs. The calling root module passes input values in the module block and reads exported values using the syntax module.<module_name>.<output_name>. Best practice is to expose only the values consumers need rather than raw internal implementation details. This matches Terraform documentation for input variables, output values, and module composition.

  • A. Correct.

    Correct. This is the intended Terraform pattern for reusable modules. Input variables let module authors define configurable inputs, including optional defaults. Outputs let child modules expose selected values, such as a VPC ID, to the calling root module. A consumer can override the default by passing an argument in the module block, and can then reference the exported value as module...

  • B. Incorrect.

    Incorrect. Hardcoding the CIDR block removes the flexibility required by the scenario. Also, a root-module local value cannot directly serve as a mechanism to expose a child module's resource ID unless that value is derived from a proper module output. Locals are only internal expressions within a module and are not a substitute for child module outputs.

  • C. Incorrect.

    Incorrect. Outputs are for values produced by a module and consumed by its caller, not for accepting configuration into the module. Likewise, the VPC ID is created by the child module, so it should be exposed as an output rather than passed back into the root module as an input variable after creation. This reverses Terraform's intended data flow.

  • D. Incorrect.

    Incorrect. terraform.tfvars files are primarily used by the root module when supplying values to input variables during CLI-driven runs. A child module should define defaults in variable blocks, not rely on a tfvars file packaged inside the module for default behavior. Also, root outputs do not automatically expose all child module resource attributes; only explicitly defined child outputs are accessible.

Timed practice exam

Take a HashiCorp Terraform Associate (004) practice test under exam conditions

70 questions in 60 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam

HashiCorp Terraform Associate (004) practice questions 101 to 200 of 223

Every question has a page with the answer and explanation. Numbers are stable, so you can bookmark or share them. The bank is split into 3 pages of up to 100 questions.

  1. 101.A platform team maintains a reusable Terraform module that creates an application load balancer and returns...
  2. 102.Your team maintains a reusable Terraform module that provisions an application load balancer and returns its...
  3. 103.A team maintains a reusable Terraform module that creates an AWS application stack. The module already...
  4. 104.A team maintains a reusable Terraform module that creates a virtual network and several subnets. They want...
  5. 105.A team maintains a reusable Terraform module that creates a VPC and several subnets. Multiple application...
  6. 106.A platform team wants a reusable Terraform module to create network security rules for multiple applications....
  7. 107.A platform team wants a reusable Terraform module to configure multiple application environments. Each...
  8. 108.A platform team wants to standardize how application environments are defined in Terraform. They want a...
  9. 109.A platform team wants to standardize how application environments are defined in Terraform. Each environment...
  10. 110.A platform team wants to standardize how application teams define firewall rules in a reusable Terraform...
  11. 111.A team manages application settings in Terraform using a map variable and wants to pass those settings to a...
  12. 112.A platform team uses Terraform to create security groups for multiple application components. They want each...
  13. 113.A platform team wants to standardize tags across environments. They receive a variable environment with...
  14. 114.A platform team maintains a Terraform module that creates application subnets in multiple availability zones....
  15. 115.A platform team wants to standardize tags across AWS resources in Terraform. They receive an input variable...
  16. 116.Your team provisions AWS infrastructure with Terraform. An application EC2 instance must not be created until...
  17. 117.A team manages AWS infrastructure with Terraform. In one module, an EC2 instance is created and then a...
  18. 118.A team is provisioning AWS infrastructure with Terraform. In one module, an EC2 instance is created and...
  19. 119.A team is provisioning an AWS application stack with Terraform. An EC2 instance must not be created until a...
  20. 120.A team manages AWS infrastructure with Terraform. In one module, an EC2 instance must download a bootstrap...
  21. 121.A platform team maintains a reusable Terraform module that creates an Amazon EC2 security group. The module...
  22. 122.A platform team maintains a reusable Terraform module that creates an AWS security group. To reduce...
  23. 123.A platform team maintains a reusable Terraform module that creates an AWS security group. They want to...
  24. 124.A platform team maintains a reusable Terraform module that provisions an AWS Application Load Balancer. The...
  25. 125.A platform team maintains a reusable Terraform module that provisions an AWS EC2 instance. The module accepts...
  26. 126.A team uses Terraform to provision cloud infrastructure and needs to supply database administrator...
  27. 127.Your team uses Terraform in a CI/CD pipeline to provision cloud infrastructure. A recent security review...
  28. 128.A platform team uses Terraform Cloud to provision infrastructure in AWS. Their current configuration...
  29. 129.A platform team uses Terraform in a CI/CD pipeline to provision database users and application...
  30. 130.Your team uses Terraform Cloud to provision infrastructure in AWS. A current configuration passes an AWS...
  31. 131.Your team maintains a reusable Terraform module that creates a VPC and related networking resources. The...
  32. 132.Your team maintains a reusable Terraform module that creates an AWS VPC, subnets, and route tables. Several...
  33. 133.A platform team maintains a reusable Terraform module that provisions an AWS VPC. Several application teams...
  34. 134.Your team maintains a reusable Terraform module named network that provisions a VPC and subnets. Several...
  35. 135.Your team maintains a reusable Terraform module that creates an AWS VPC, subnets, and route tables. Several...
  36. 136.Your team maintains a reusable Terraform module for VPC networking in a separate Git repository. A project...
  37. 137.A platform team maintains a reusable Terraform module in a Git repository. The repository contains multiple...
  38. 138.A platform team maintains a reusable VPC module in a Git repository. The networking team wants application...
  39. 139.A platform team wants to standardize how application teams consume Terraform modules. One team currently...
  40. 140.A platform team maintains a reusable VPC module in a Git repository. For production stability, application...
  41. 141.Your team maintains a reusable Terraform module named network that declares variable "region" {} and uses it...
  42. 142.A team maintains a root Terraform configuration that deploys networking and compute resources. They recently...
  43. 143.A team maintains a root Terraform configuration that deploys networking and then calls a child module named...
  44. 144.A team maintains a root Terraform configuration that deploys networking and calls a child module named "app"....
  45. 145.Your team maintains a reusable Terraform module in ./modules/network that declares: variable "environment" {...
  46. 146.Your team maintains a reusable Terraform module named network in a private Git repository. A root...
  47. 147.Your team maintains a reusable Terraform module named "network" in a private Git repository. A root...
  48. 148.A platform team created a reusable Terraform module in a separate Git repository to provision an AWS VPC....
  49. 149.Your team maintains a reusable Terraform module named network in a private Git repository. The module creates...
  50. 150.Your team maintains a reusable Terraform module named network in a private Git repository. The module creates...
  51. 151.Your team uses a shared VPC module from the Terraform Registry in several environments. The current...
  52. 152.Your team uses a shared VPC module from the public Terraform Registry. The root module currently references...
  53. 153.Your team uses a shared VPC module from the public Terraform Registry in several environments. The current...
  54. 154.Your team uses a shared VPC module from the public Terraform Registry in several environments. In production,...
  55. 155.Your team uses a shared VPC module from the public Terraform Registry in several environments. The production...
  56. 156.A platform team currently stores Terraform state in a local file on an engineer's laptop. After a recent...
  57. 157.A team stores Terraform state remotely in an S3 backend with state locking enabled through DynamoDB. During a...
  58. 158.A team has been managing AWS infrastructure with Terraform using a local state file stored on an engineer's...
  59. 159.A team has been managing AWS infrastructure with Terraform using a local state file stored on an engineer's...
  60. 160.A small development team is using Terraform to provision resources for a non-production environment. Their...
  61. 161.A small operations team stores their Terraform configuration in Git and runs terraform apply manually from a...
  62. 162.A small team is building a proof-of-concept with Terraform on a single developer workstation. They have not...
  63. 163.A small development team is using Terraform to manage a test environment from their laptops. They have not...
  64. 164.A small operations team is using Terraform to manage a test environment from a shared jump host. Their...
  65. 165.A team stores Terraform state remotely in Amazon S3 and uses a DynamoDB table for state locking. During a...
  66. 166.A team stores Terraform state for a shared AWS environment in a remote backend and has started seeing...
  67. 167.Your team stores Terraform state for a shared production workspace in a remote backend. During a release, one...
  68. 168.A team stores Terraform state remotely in Amazon S3 and uses a DynamoDB table for state locking. During a...
  69. 169.A platform team stores Terraform state for a shared AWS environment in an S3 backend with a DynamoDB table...
  70. 170.A team has been storing Terraform state locally for an AWS-based production environment. To improve...
  71. 171.A platform team is migrating a Terraform configuration from local state to a shared remote state stored in...
  72. 172.A team is migrating a Terraform configuration from local state to an S3 remote backend so multiple engineers...
  73. 173.A platform team is migrating a Terraform configuration from local state to a shared Amazon S3 backend so...
  74. 174.A team is migrating a Terraform configuration from local state to a shared remote state stored in Amazon S3...
  75. 175.Your team manages an AWS security group with Terraform. An administrator manually changed the security...
  76. 176.Your team manages an AWS security group with Terraform. A cloud administrator manually added an extra inbound...
  77. 177.Your team manages an AWS security group with Terraform. A teammate manually added an extra inbound rule in...
  78. 178.A team manages an AWS security group with Terraform. During an incident, an engineer manually added an...
  79. 179.A team uses Terraform to manage an AWS VPC and several subnets. One subnet was deleted manually in the AWS...
  80. 180.Your team manages production infrastructure with Terraform using a remote backend. During an incident review,...
  81. 181.A team manages an AWS VPC with Terraform. Last week, a network engineer manually changed one security group's...
  82. 182.A team manages an AWS VPC with Terraform. Another administrator manually added a new route to the route table...
  83. 183.Your team manages a production VPC with Terraform. During troubleshooting, an engineer manually deleted one...
  84. 184.Your team has an existing AWS S3 bucket named company-logs-prod that was created manually and is already in...
  85. 185.Your team has an existing AWS S3 bucket named company-logs-prod that was created manually and is already in...
  86. 186.Your team has been manually managing an AWS S3 bucket named company-logs for several months. You now want...
  87. 187.Your team has an existing AWS security group named "web-sg" that was created manually in the AWS console. You...
  88. 188.Your team has an Amazon EC2 instance that was created manually in AWS and is already running in production....
  89. 189.A teammate reports that a Terraform-managed AWS EC2 instance was manually modified in the AWS console, and...
  90. 190.Your team stores Terraform state remotely in an S3 backend. After a recent apply, a developer reports that an...
  91. 191.A platform engineer is troubleshooting a Terraform-managed AWS environment after a teammate manually changed...
  92. 192.A team stores Terraform state remotely and has just imported an existing AWS security group into their...
  93. 193.Your team stores Terraform state remotely in an S3 backend. After a recent apply, an engineer reports that...
  94. 194.A platform engineer runs terraform plan in a CI job and gets a generic provider-related error that does not...
  95. 195.A platform engineer runs terraform init in a CI job and it intermittently fails while downloading a provider...
  96. 196.A platform engineer runs terraform apply in a CI job and sees a generic provider error during refresh: Error:...
  97. 197.A platform engineer runs terraform init in a CI job and it fails intermittently while downloading a provider...
  98. 198.A platform engineer runs terraform init in a CI job and it fails while downloading a provider from the...
  99. 199.A platform team is migrating from local Terraform execution to HCP Terraform. They want every infrastructure...
  100. 200.A platform team is migrating from local Terraform execution to HCP Terraform so they can centralize state,...