Courseiva

TF-004 · topic practice

Interact with Terraform modules practice questions

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.

Courseiva uses original exam-style practice questions designed for learning and revision. The goal is to understand the concepts, recognise exam patterns, and improve through explanations — not memorise copied exam dumps.

Editorial oversight:Johnson Ajibi· MSc IT Security, IEEE Senior Member
20 questionsDomain: Interact with Terraform modules

What the exam tests

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

Practice set

Interact with Terraform modules questions

20 questions · select your answer, then reveal the explanation

A team is using a module from the public Terraform Registry. They want to ensure that the module is pinned to a specific version to avoid unexpected changes. Which approach should they use?

Which TWO statements about Terraform module sources are correct? (Select TWO.)

Which THREE practices are recommended when using Terraform modules? (Select THREE.)

The above configuration references a module from the Terraform Registry. After running 'terraform init', the user runs 'terraform plan' and gets an error: 'Error: Unsupported argument' for 'version'. What is the most likely cause?

Exhibit

Refer to the exhibit.

```hcl
module "vpc" {
  source = "terraform-aws-modules/vpc/aws"
  version = "3.19.0"
  name = "my-vpc"
  cidr = "10.0.0.0/16"
  azs  = ["us-east-1a", "us-east-1b"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]
}

output "vpc_id" {
  value = module.vpc.vpc_id
}
```

After running 'terraform apply', the user sees that the 'aws_s3_bucket_object' is created successfully, but the bucket name is not as expected. What is the most likely reason?

Exhibit

Refer to the exhibit.

```hcl
module "bucket" {
  source = "./modules/s3-bucket"
  bucket_name = "my-app-data"
}

resource "aws_s3_bucket_object" "config" {
  bucket = module.bucket.bucket_name
  key    = "config.json"
  source = "config.json"
}
```

The module at './modules/s3-bucket' contains:

```hcl
variable "bucket_name" {}
resource "aws_s3_bucket" "this" {
  bucket = var.bucket_name
}
output "bucket_name" {
  value = aws_s3_bucket.this.id
}
```

Which TWO statements about Terraform module structure and best practices are correct? (Choose two.)

Question 7hardmultiple choice
Read the full DNS explanation →

You are managing a Terraform configuration that uses a public module from the registry to deploy an AWS VPC. The module is defined with a version constraint of '~> 3.0'. After running 'terraform init', you run 'terraform plan' and notice that the plan output indicates the module will be updated from version 3.18.0 to 3.20.1. However, you are concerned because the module's changelog shows that version 3.19.0 introduced a breaking change: it removed the 'enable_dns_hostnames' variable and replaced it with 'enable_dns_support'. Your configuration currently uses the 'enable_dns_hostnames' variable. You want to avoid any breaking changes in the production environment while still receiving non-breaking updates. What should you do?

Which TWO options are valid ways to reference a Terraform module from a registry?

Your company manages infrastructure for multiple environments (dev, staging, prod) using Terraform. You have a shared networking module stored in a private Git repository. The module is used by several root configurations. The current workflow requires developers to manually update the module version in each root module's source attribute when a new version is tagged. This has led to configuration drift and occasional use of incompatible module versions. You want to implement a more reliable approach that ensures all environments use the same consistent version of the module, while still allowing controlled upgrades. Which approach best addresses this concern?

Which three of the following describe correct practices or behaviors when interacting with Terraform modules? (Choose three.)

Which THREE of the following are valid ways to reference a module output value within the same Terraform configuration?

Given the plan output, how is the module 'instances' configured in the root module?

Exhibit

Refer to the exhibit.

```
Terraform will perform the following actions:

  # module.instances["web"].aws_instance.this will be created
  + resource "aws_instance" "this" {
      + ami                          = "ami-123456"
      + instance_type                = "t2.micro"
      + subnet_id                    = (known after apply)
      ...
    }

  # module.instances["app"].aws_instance.this will be created
  + resource "aws_instance" "this" {
      + ami                          = "ami-789012"
      + instance_type                = "t2.small"
      + subnet_id                    = (known after apply)
      ...
    }

Plan: 2 to add, 0 to change, 0 to destroy.
```

Which of the following files is NOT required in a Terraform module?

Which module source type does NOT support version constraints?

You are developing a module. Which TWO actions are recommended best practices?

Which THREE statements about module configuration are correct?

A company uses a Terraform module from the registry for AWS VPC (source = "terraform-aws-modules/vpc/aws", version = "3.0.0"). They updated the module version to "3.1.0" and ran terraform plan. To their surprise, the plan shows that all VPC resources will be replaced (destroyed and recreated) instead of updated in place. They did not change any input variables. The module's release notes mention only bug fixes and minor improvements. What is most likely causing the full resource replacement?

A team has a root module that calls a local module using count to conditionally create an AWS RDS instance based on a boolean variable `rds_enabled`. The root module sets `rds_enabled` to the value of a data source that checks if a tag exists on an S3 bucket. The relevant code is: `count = var.rds_enabled ? 1 : 0`. When they run terraform plan, they receive the error: "Error: Invalid count argument: The count value is not yet known". The S3 bucket already exists. What is the underlying issue?

Your team is developing a custom module for creating EC2 instances with attached EBS volumes. The module variables are: instance_type (default "t2.micro"), ami (required), volume_size (default 8), volume_type (default "gp2"). Another team uses this module to create a web server. In their root module, they call the module without any explicit instance_type override, but they do set other variables. After applying, the web server is created with instance_type "t2.nano" instead of the expected "t2.micro". They confirm that the module still has the default "t2.micro". What is the most likely explanation?

What is the most likely cause of this error?

Exhibit

Refer to the exhibit.

```hcl	erraform {
  required_version = ">= 1.0"
}

module "network" {
  source = "./modules/networking"
  vpc_id = "vpc-12345"
}
```

Output from `terraform plan`:
```
Error: Module not found

The module at "./modules/networking" could not be found.
```

Free account

Track your progress over time

Create a free account to save your results and see which topics improve across sessions.

Focused Interact with Terraform modules sessions

Start a Interact with Terraform modules only practice session

Every question in these sessions is drawn from the Interact with Terraform modules domain — nothing else.

Related practice questions

Related TF-004 topic practice pages

Move into related areas when this topic feels solid.

Frequently asked questions

What does the TF-004 exam test 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.
How should I use these practice questions?
Select your answer before revealing the explanation. Then read why each option is right or wrong — this active recall approach builds retention far faster than re-reading notes.
Can I practise just Interact with Terraform modules questions in a focused session?
Yes — the session launcher on this page draws every question from the Interact with Terraform modules domain. Use a 10-question session first to gauge your baseline, then move to 20 or 30 once the weak spots are clear.
Where can I practise other TF-004 topics?
Use the topic links above to move to related areas, or go back to the TF-004 question bank to see all topics.
Are these real exam questions or dumps?
These are original practice questions written to test the same concepts the TF-004 exam covers. They are not copied from any real exam or dump site.