HashiCorp Certified: Terraform Associate (004) · Domain 5 · 13% of exam

Terraform Modules

Drill 19 practice questions focused entirely on Terraform Modules for the HashiCorp Terraform Associate exam. Tap an answer for instant feedback and a full explanation — no sign-up, always free.

Verified answer19 questions
Question 1 of 19

A developer is refactoring a Terraform configuration into a reusable child module for provisioning S3 buckets. Inside the root module, a variable named 'environment' is defined and used. When the developer references var.environment inside the child module's main.tf, Terraform reports an error that the variable is not declared. What is the correct way to make the parent's 'environment' value available to the child module?

Reviewed for accuracy · Report an issue
Question 2 of 19

Your team has a reusable local module at ./modules/app-server that provisions a single application server. A colleague needs to deploy three identical instances of this server from the root configuration without copying the module block three times. Which approach correctly creates three instances of the module?

Reviewed for accuracy · Report an issue
Question 3 of 19

You are authoring a reusable module named 'web-server' that provisions EC2 instances. The module needs the calling configuration to supply an instance size, but you do not want to hard-code any default so that consumers are forced to make an explicit choice. Inside the module, how should you declare this input so that Terraform requires the caller to pass a value?

Reviewed for accuracy · Report an issue
Question 4 of 19

You are refactoring a large Terraform configuration and have extracted reusable networking logic into a subdirectory named 'modules/network' within your project repository. From the root configuration, you want to call this module without publishing it to any registry or Git host. Which source value should the module block use?

Reviewed for accuracy · Report an issue
Question 5 of 19

A developer is calling a reusable VPC module and wants to create three copies of it. They add `count = 3` to the module block, but they also expect the child module to automatically receive a variable named `count` that it can reference internally. When they run `terraform plan`, the child module cannot find any variable called `count`. What is the correct explanation of this behavior?

Reviewed for accuracy · Report an issue
Question 6 of 19

You maintain a reusable module named 'network' that provisions a VPC and subnets. In your root configuration, you write `subnet_id = module.network.private_subnet_id`, but `terraform plan` fails with an error saying the module has no output named 'private_subnet_id'. The subnet resource clearly exists inside the module's files. What is the correct fix?

Reviewed for accuracy · Report an issue
Question 7 of 19

A platform team maintains two modules: a 'network' module that provisions a VPC and subnets, and an 'app' module that deploys instances into an existing subnet. In the root configuration, both modules are called. The 'app' module has an input variable named 'subnet_id'. The 'network' module already declares an output named 'private_subnet_id'. How should the root module wire the network's subnet into the app module?

Reviewed for accuracy · Report an issue
Question 8 of 19

You have written a reusable module named "network" that creates a VPC. The module defines an output named "vpc_id". In the root configuration, you want to pass this VPC ID into a resource that creates a security group. Which expression correctly references the module's output?

Reviewed for accuracy · Report an issue
Question 9 of 19

You are authoring a reusable module named 'network' that provisions a VPC and subnets. The parent (root) configuration needs to reference the VPC ID created inside the module so it can pass that value to a separate 'compute' module. Inside the 'network' module, the VPC is defined as 'resource "aws_vpc" "main"'. What must you do so the root configuration can access the VPC ID?

Reviewed for accuracy · Report an issue
Question 10 of 19

A team maintains a reusable VPC module in ./modules/network. The module declares a variable named subnet_cidrs of type list(string) with no default. In the root module, an engineer writes a module block referencing this module but the plan fails with an error stating the required variable was not provided. Which change to the root module block correctly supplies the value?

Reviewed for accuracy · Report an issue
Question 11 of 19

You maintain a reusable networking module that must deploy resources into a secondary AWS region. In the root module you have configured a default AWS provider and an aliased provider named `aws.secondary`. You want the child module to use the aliased provider for all of its resources. What is the correct way to pass this provider configuration to the module?

Reviewed for accuracy · Report an issue
Question 12 of 19

Your team wants to consume the AWS VPC module published on the public Terraform Registry (terraform-aws-modules/vpc/aws) and pin it to version 5.1.2. Which module block correctly references the Registry module and constrains its version?

Reviewed for accuracy · Report an issue
Question 13 of 19

Your team stores a reusable networking module in a self-hosted GitLab instance that is not published to any Terraform Registry. You want a root configuration to consume this module directly over HTTPS from the Git repository. Which source value correctly references a generic Git repository over HTTPS?

Reviewed for accuracy · Report an issue
Question 14 of 19

Your team stores a reusable networking module in a private Git repository at github.com/acme/tf-modules in the subdirectory 'vpc'. You need to reference version tag 'v1.4.0' of that module from a root configuration. Which module block source value correctly pins to that tagged version and subdirectory?

Reviewed for accuracy · Report an issue
Question 15 of 19

A platform team publishes reusable Terraform modules as versioned .zip archives on an internal artifact server reachable at https://artifacts.example.com. A downstream team wants to consume a specific packaged version of the networking module without using Git or the public/private registry. Which module source configuration correctly references the archive?

Reviewed for accuracy · Report an issue
Question 16 of 19

Your team wants to consume a networking module published on the public Terraform Registry. A colleague asks you what the correct value of the module's `source` argument should look like when pulling directly from the public registry. Which format is correct?

Reviewed for accuracy · Report an issue
Question 17 of 19

Your team maintains a reusable networking module stored in a local directory at ../modules/vpc. You need to provision two separate VPCs (production and staging) in the same root configuration, each with different CIDR ranges passed as input variables. What is the correct approach?

Reviewed for accuracy · Report an issue
Question 18 of 19

A platform team is packaging a reusable networking module to publish on the public Terraform Registry. During their review, a colleague asks which files make up the minimum recommended standard module structure that the Registry expects for a root module. Which combination of files best represents the conventional standard module structure?

Reviewed for accuracy · Report an issue
Question 19 of 19

Your team consumes a module from the public Terraform Registry that follows semantic versioning. The current pinned version is 3.2.0. You want Terraform to automatically pick up bug-fix and minor feature releases within the 3.x line during future `terraform init -upgrade` runs, but you must avoid ever pulling in a 4.0.0 release that could introduce breaking changes. Which version constraint should you set in the module block?

Reviewed for accuracy · Report an issue

More Terraform Associate practice

Keep going with the other HashiCorp Certified: Terraform Associate (004) domains, or take a full timed mock exam.

← Back to Terraform Associate overview