TF-004 · domain
Interact with Terraform modules
This domain covers how Terraform modules package and reuse configuration: defining input variables with types and validation, exposing outputs, wiring child modules into a root module, and managing module and provider version constraints. Questions present short scenarios about validation failures, sensitive values, refactoring monoliths, and resolving provider version conflicts, so you must reason about module behavior rather than recall syntax alone.
Focused practice
Practice Interact with Terraform modules questions
Scored sessions drawing only from this domain — pick a length below.
Start 20-question practice test →What this domain covers
What to know about Interact with Terraform modules
Be able to write a module with typed, validated input variables and outputs, then call it from a root module with correct arguments and version constraints. The critical skill is predicting failures: validation errors block the run, and sensitive values are redacted in output but remain in state.
Declaring module input variables with type constraints and validation blocks that reject out-of-range values
Passing values between root and child modules via module arguments and module output blocks
Marking variables and outputs sensitive so Terraform redacts values in plan and apply output
Pinning module sources and provider requirements, and resolving version constraint conflicts
Watch out for
Common Interact with Terraform modules exam traps
- ▸Assuming a failed variable validation only warns; it actually errors the plan or apply when the value violates the condition
- ▸Believing sensitive = true encrypts state; it only redacts CLI output, and values still land in state
- ▸Forgetting that refactoring into modules changes resource addresses, so state must be moved or resources recreated
Question index
All Interact with Terraform modules questions (46)
Click any question to see the full explanation, or start a practice session above.
You have two modules that create resources in different providers. Module A creates a VPC in AWS, Module B creates a Kubernetes cluster that requires the VPC ID. You want to ensure Module B runs after Module A but avoid hardcoding the VPC ID. Which approach is most appropriate?
Hard2You have a list of VPC configurations and want to create multiple VPCs using a single module block with for_each. Which statement is true?
Medium3An organization stores their Terraform modules in a private Git repository. They need to reference a module that resides in a subdirectory called 'modules/rds' within the repository 'infra-modules' on the main branch. Which source argument should be used?
Hard4A consultant is writing a reusable module that provisions an AWS VPC. Callers are complaining that they cannot tell which inputs are required and which have defaults, and the module's README is frequently out of date. Which practice most directly improves the module's self-documenting interface without adding external tooling?
Medium5A large organization uses Terraform to manage infrastructure across multiple AWS accounts. They have a shared module for VPC stored in a private Git repository (git::https://github.com/org/terraform-aws-vpc.git?ref=v1.0.0). After updating the module source to ref=v1.2.0, they run terraform init and then terraform plan. The plan still shows the old module's resources and behavior. They confirm the new tag exists and the module code has changed. The root module source line is correct. What is the most likely cause?
Hard6Which TWO module source types support version constraints in Terraform?
Medium7A DevOps team manages Terraform configurations for a multi-environment infrastructure (dev, staging, prod). They maintain a central repository of reusable modules stored in a Git repository. Developers often update modules in the master branch to add features or fix bugs. Recently, after a developer updated the 'vpc' module in the master branch, the staging environment's infrastructure was destroyed and recreated during a terraform apply, causing an outage. The team needs to prevent such unintended changes across environments. They currently reference modules using the source argument with a git URL pointing to the master branch: source = "git::https://github.com/org/terraform-modules//vpc?ref=master". The team is looking for a solution that allows controlled updates and ensures each environment uses a fixed version of a module until explicitly upgraded.
Hard8A module block references a module with version constraint '>= 2.0, < 3.0'. An older version 1.5 is already cached from a previous init. The team wants to ensure they use a newer version. After running terraform init -upgrade, what happens?
Hard9A team renamed a module from 'module.network' to 'module.vpc' in their configuration. They run 'terraform plan' and see that Terraform wants to destroy the old network resources and create new ones. They want to preserve the existing resources without downtime. What should they do?
Hard10A developer runs `terraform plan` and receives the error: "Error: Unsupported argument; An argument named 'enable_vpn_gateway' is not expected here." What is the most likely cause?
Hard11A developer creates a module in a subdirectory of their Terraform configuration and wants to reference it from the root module. The directory structure is: /terraform-project/modules/networking. Which source argument should they use in the module block?
Medium12A developer creates a directory structure with a module located at './modules/networking'. The root configuration references it with source = './modules/networking'. What is the behavior when running terraform init from the root directory?
Medium13A Terraform module defines an output 'instance_ips'. In the root module, how should this value be referenced?
Easy14A team is using a private module registry from a third-party vendor. When running terraform init, they receive an error: 'Error downloading module: could not download module... server responded with 401 Unauthorized'. What is the most likely cause?
Medium15What is the correct way to resolve this provider version conflict?
Hard16A developer wants to create multiple instances of a module that provisions a single EC2 instance. They want to create 3 EC2 instances. Which approach is most efficient and concise?
Easy17After adding a new module sourced from a Git repository with a specific tag, terraform init reports that the module is being downloaded. What is the best practice to ensure the team uses the same version of this module consistently?
Easy18Which TWO statements are correct when refactoring a monolithic Terraform configuration into modules?
Medium19A module defines an input variable with 'sensitive = true'. The root module tries to use that variable in an output block. What happens when running 'terraform apply'?
Hard20A root module uses a module that creates an AWS EC2 instance. The module outputs the instance ID. The root module then uses this output in a null_resource provisioner. After modifying the module, terraform plan shows that the EC2 instance will be destroyed and recreated. What is the impact on the null_resource?
Medium21A module 'web_app' defines an input variable 'instance_count' with type = number and a validation block ensuring it is between 1 and 10. What happens if a user sets instance_count = 0?
Easy22Refer to the exhibit. The configuration fails with an error indicating that the module does not support the 'enable_vpn_gateway' argument. What is the most likely cause?
Easy23Which version of the module was downloaded and why?
Easy24After applying a module that creates a VPC, a user wants to use the VPC ID in another resource within the root configuration. How should they reference the output from the module?
Easy25Which TWO of the following are valid ways to reference a module from the Terraform Registry?
Easy26Which TWO statements about Terraform modules are correct?
Easy27A team is using a module from the Terraform Registry and wants to ensure they always get the latest patch version of the 3.2.x series. Which version constraint should they use?
Easy28A developer creates a module that provisions an AWS EC2 instance and an S3 bucket. The module outputs the instance ID and bucket ARN. When using this module, the root configuration references module.my_module.instance_id and module.my_module.bucket_arn. After running terraform apply, they notice that the bucket ARN is empty. What is the most likely cause?
Hard29Based on the error, what is the most likely reason the 'acl' argument is not expected?
Easy30After running `terraform plan`, the user receives an error: `Error: Missing required variable`. The variable 'vpc_cidr' is provided. What is the most likely cause?
Medium31An engineer is refactoring a monolithic Terraform configuration into reusable modules. One module outputs a list of subnet IDs. Another module needs to use these subnet IDs to create resources. What is the best way to pass this data between modules?
Medium32A developer creates a module in a subdirectory called 'networking' relative to the root module. How should the module source be specified in the root module?
Medium33Match each Terraform function to its category.
Medium34A team is using a module from the Terraform Registry. When they run 'terraform init', they receive an error stating that the module source cannot be downloaded. The module source is correct. What is the most likely cause?
Medium35An organization uses Terraform modules to provision multiple environments. They have a module 'vpc' that uses a for_each argument in the root module to create VPCs per environment. Each VPC requires a unique CIDR block passed via variable. What is the best practice to pass different CIDRs per instance?
Hard36A module outputs a map of security group IDs keyed by name. In the root module, a resource needs to reference the security group ID for the name 'web-sg'. How should the root configuration access this value?
Medium37Which four of the following statements about interacting with Terraform modules are correct? (Choose four.)
Medium38Which TWO module source types are supported by Terraform natively?
Easy39In the configuration, what is the likely result of the resource block 'aws_flow_log'?
Hard40A module requires a specific provider configuration with aliases. The root module has two provider configurations: provider 'aws' (default) and provider 'aws' with alias = 'uswest'. The module uses the us-west alias. How should the module block be configured to ensure the correct provider is used?
Hard41Drag and drop the steps to manage Terraform state locking with a backend in the correct order.
Medium42A team is using a module from the Terraform Registry. They want to ensure that changes to the module's source version are tested in a non-production environment before being applied to production. Which approach best supports this workflow?
Medium43A team wants to use a networking module from the public Terraform Registry. They need to ensure they always get the latest patch version within the 1.2.x series. Which version constraint should they use in the module block?
Easy44Which THREE files are considered part of the standard module structure?
Hard45Which TWO are benefits of using Terraform modules?
Easy46You are a DevOps engineer at a company that manages infrastructure for multiple environments (dev, staging, prod) using Terraform. The team has created a reusable module for deploying an AWS ECS Fargate service. The module accepts variables for environment name, container image tag, and desired count. The module is stored in a private Git repository. The root configurations for each environment are stored in separate directories, each with its own backend configuration. Recently, a developer added a new feature to the module that requires a new variable 'enable_xray' (boolean, default false). After updating the module source to point to the new commit, the developer runs 'terraform init' and 'terraform plan' in the dev environment. The plan shows that the ECS service will be updated, but the output does not show any changes related to X-Ray. The developer expected that setting 'enable_xray = true' in the dev root module would enable X-Ray tracing. However, the plan shows no changes to the task definition. What is the most likely cause?
HardOther domains
All TF-004 exam domains
Frequently asked questions
- What does the Interact with Terraform modules domain cover on the TF-004 exam?
- Be able to write a module with typed, validated input variables and outputs, then call it from a root module with correct arguments and version constraints. The critical skill is predicting failures: validation errors block the run, and sensitive values are redacted in output but remain in state.
- How many questions are in this domain?
- This page lists all 46 Interact with Terraform modules questions in the TF-004 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
- What is the best way to practise this domain?
- Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
- Can I practise only Interact with Terraform modules questions?
- Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.