Courseiva

CCNA Terraform Modules Questions

33 questions · Terraform Modules · All types, answers revealed

1
Multi-Selectmedium

Which THREE of the following are components of the 'source' string when using the Terraform Registry?

Select 3 answers
A.Git branch name.
B.Provider.
C.Operating system.
D.Module name.
E.Namespace.
AnswersB, D, E

The provider specifies the target cloud (e.g., aws).

Why this answer

The registry source string format is 'namespace/name/provider'.

2
MCQeasy

What is the recommended approach for managing a module that has grown too large?

A.Use 'terraform import' to split the resources.
B.Combine all files into a single 'main.tf'.
C.Rename the module to something more generic.
D.Break the module into smaller, focused sub-modules.
AnswerD

Modularization of the module itself is the correct design pattern.

Why this answer

Refactoring into smaller, single-purpose sub-modules improves maintainability and readability.

3
MCQeasy

Where do module outputs appear after a 'terraform apply'?

A.In a file named 'outputs.json'.
B.They are automatically emailed to the Terraform administrator.
C.In the CLI output and the state file.
D.In the '.terraform/modules' directory.
AnswerC

Outputs are part of the state and printed upon successful application.

Why this answer

Outputs are displayed in the CLI output and stored in the state file.

4
MCQeasy

Which argument in a module block allows you to provide a custom name to the module instance?

A.The label immediately following the 'module' keyword.
B.'name'
C.'instance_name'
D.'alias'
AnswerA

The identifier after 'module' serves as the instance name for referencing.

Why this answer

The module block itself uses the label to name the instance, but the 'source' argument defines the location.

5
Multi-Selectmedium

Which TWO of the following are true regarding variable validation in modules?

Select 2 answers
A.Validation blocks must return a boolean value.
B.Validation errors will only show during 'terraform apply'.
C.Validation blocks can read from other modules.
D.Variable names can be arbitrary but must be unique.
E.You can only validate string variables.
AnswersA, D

The condition must evaluate to true for the input to be valid.

Why this answer

Validation blocks and type constraints are the primary mechanisms for ensuring valid inputs.

6
MCQmedium

You are building a module that needs to be consumed by multiple teams. How should you structure your module to ensure that the root module can provide values for variable definitions without hardcoding them in the module itself?

A.Hardcode the values into the resource blocks directly.
B.Use terraform.tfvars files inside the module folder.
C.Define all values in a locals.tf file within the module.
D.Define variables in a variables.tf file within the module directory.
AnswerD

Variables defined in the module's variables.tf file can be populated by the root module.

Why this answer

Using input variables allows the module to be generic and reusable by accepting values defined in the calling configuration.

7
MCQeasy

Which directory structure is considered standard for a Terraform module?

A.A directory containing main.tf, variables.tf, and outputs.tf.
B.One single file named 'all.tf'.
C.A binary executable file that compiles the infrastructure.
D.A separate folder for every single resource.
AnswerA

This is the established convention for module organization.

Why this answer

A standard module should contain at least main.tf, variables.tf, and outputs.tf.

8
MCQmedium

When refactoring a large infrastructure configuration, you move a resource into a child module. How do you handle the existing state to prevent Terraform from destroying and recreating the resource?

A.Run 'terraform refresh' to automatically detect the move.
B.Use the 'terraform state mv' command to move the resource address.
C.Rename the resource in the configuration to match the old state.
D.Delete the state file and run 'terraform apply'.
AnswerB

This command updates the state file to reflect the new hierarchy without destroying infrastructure.

Why this answer

The 'terraform state mv' command is required to map the old address to the new module-relative address.

9
MCQeasy

What is the primary benefit of using a module registry compared to a local file path for module distribution?

A.It allows you to run Terraform commands faster.
B.It removes the need for input variables.
C.It automatically converts your code to a higher-level language.
D.It enables version control and easier sharing across the organization.
AnswerD

Registries facilitate versioned releases and standardized consumption patterns.

Why this answer

Registries provide versioning, documentation generation, and centralized discovery for teams.

10
Multi-Selecthard

Which THREE actions are best practices when publishing a module to a private registry?

Select 3 answers
A.Use Semantic Versioning (SemVer) for all releases.
B.Include a 'examples/' directory to show usage.
C.Keep all files in the root folder, including tests.
D.Include a README.md file in the root of the module.
E.Prefix the repository name with 'terraform-provider-'.
AnswersA, B, D

SemVer allows consumers to pin to safe versions.

Why this answer

Best practices include versioning, documentation, and specific naming conventions.

11
Multi-Selectmedium

Which THREE of the following are valid sources for a Terraform module?

Select 3 answers
A.The Terraform Registry.
B.A local directory path.
C.A directly linked SQL database.
D.A raw HTTP file download link.
E.A public or private Git repository.
AnswersA, B, E

The Registry is the primary source for published modules.

Why this answer

Terraform supports modules from local paths, the Terraform Registry, and version control providers like Git.

12
Multi-Selectmedium

Which THREE tasks are performed by 'terraform init -upgrade'?

Select 3 answers
A.Migrating the state file to a new format.
B.Upgrading provider binaries.
C.Automatically fixing HCL syntax errors in modules.
D.Updating the local module cache.
E.Regenerating the dependency lock file (.terraform.lock.hcl).
AnswersB, D, E

It fetches the latest provider versions.

Why this answer

The '-upgrade' flag forces the re-download of modules and providers to the latest versions within constraints.

13
MCQeasy

What is the purpose of the 'terraform init' command when working with modules?

A.It compiles the modules into machine code.
B.It pushes your local modules to the registry.
C.It downloads and installs the modules specified in the configuration.
D.It updates the state file to match the modules.
AnswerC

Module initialization is a core function of the init command.

Why this answer

'terraform init' downloads and installs the modules specified in the configuration into the '.terraform/modules' directory.

14
Multi-Selecthard

Which THREE of these are benefits of using modules in Terraform?

Select 3 answers
A.Increasing the execution speed of API calls.
B.Automatically preventing all resource drift.
C.Enforcing standardized configurations across teams.
D.Reducing code duplication across environments.
E.Encapsulating complexity into simple interfaces.
AnswersC, D, E

Modules ensure consistent resource setup.

Why this answer

Modules improve code reuse, organization, and standardization.

15
Multi-Selecthard

Which THREE items should be included in a well-documented Terraform module?

Select 3 answers
A.A list of all possible provider configurations.
B.Clear documentation for each output.
C.A description for each input variable.
D.The raw state file of the module's resources.
E.An example of how to call the module.
AnswersB, C, E

Output documentation clarifies what data is exposed.

Why this answer

Documentation should cover how to use the module, its inputs, and its outputs.

16
MCQhard

If a module has a required variable but you do not provide it in the calling configuration, what happens?

A.Terraform uses 'null' for the value.
B.Terraform uses the variable value from the previous state.
C.Terraform fails with an error during the planning phase.
D.Terraform automatically sets the value to an empty string.
AnswerC

Missing required variables cause immediate validation errors.

Why this answer

Terraform will stop and prompt the user for the missing value during the plan or apply phase if it is not provided via command line or tfvars.

17
Multi-Selecthard

Which TWO of the following are valid ways to pass a provider configuration to a child module?

Select 2 answers
A.Defining the provider inside the module's 'main.tf'.
B.Using the 'providers' meta-argument inside the module block.
C.Passing the provider as a string input variable.
D.Using a global variable for provider credentials.
E.Inheritance from the root module's provider configuration.
AnswersB, E

Explicit mapping is needed for non-default provider instances.

Why this answer

Providers are either inherited from the root or passed explicitly using the 'providers' map in the module block.

18
MCQhard

If you have a module that creates an S3 bucket, and you want the bucket name to be prefixed by a value provided by the caller, how do you achieve this?

A.Use a local variable that reads from the provider config.
B.Use string interpolation in the bucket name attribute.
C.Define the bucket name in the root module and override the child resource.
D.Use the 'module_name' variable provided by Terraform.
AnswerB

Interpolating the input variable into the bucket name is the standard approach.

Why this answer

Concatenate the variable inside the resource block using string interpolation.

19
MCQmedium

Your team requires a custom module to be versioned strictly to prevent breaking changes during deployments. What is the recommended way to reference a module from a private Git repository?

A.Use the 'ref' parameter in the source URL string.
B.Set the 'version' block inside the module definition.
C.Copy the module code locally every time a new version is released.
D.Use the 'module_version' argument in the module block.
AnswerA

The 'ref' query parameter in the source URL specifies the version, tag, or branch.

Why this answer

Using the 'version' argument in the source block allows pinning to specific tags or branches, ensuring stability.

20
MCQhard

How can you protect a module's inputs from receiving incorrect types of data?

A.Use the 'provider' block to enforce input types.
B.Use a 'validation' block with a condition inside the variable declaration.
C.Write a custom bash script to check the inputs.
D.Terraform automatically validates all inputs as strings.
AnswerB

Validation blocks provide a way to enforce custom business logic on inputs.

Why this answer

Defining the 'type' constraint in the variable block ensures Terraform validates the input before applying changes.

21
MCQhard

You need to output a complex object from a child module to be used by the root module. What is the best practice for defining the output?

A.Assign the output to a global variable in the root module.
B.Use a data source to read the child module's internal state.
C.Define an output block in the child module and reference it in the root module using the module prefix.
D.Write the output to a local file inside the module and read it in the root.
AnswerC

This is the standard pattern for passing information from a module back to its caller.

Why this answer

Using explicit output blocks in the child module makes the data available for access via 'module.<module_name>.<output_name>'.

22
MCQmedium

You need to share a module across your entire organization. Which registry type should you use?

A.The public Terraform Registry.
B.A shared network drive.
C.An S3 bucket with public read access.
D.A private module registry in Terraform Cloud or Enterprise.
AnswerD

Private registries are designed for secure, internal module distribution.

Why this answer

Terraform Cloud or Terraform Enterprise private module registries are the standard for internal organization-wide sharing.

23
MCQmedium

You have a nested module structure. How can you pass a variable from the root module through an intermediate module to a leaf module?

A.Define the variable only in the leaf module and refer to root by index.
B.You must define the variable in the intermediate module and pass it to the leaf module.
C.You can use the 'global_vars' block in the root.
D.The intermediate module automatically inherits all root variables.
AnswerB

Explicit declaration and assignment are required at every level of the hierarchy.

Why this answer

Each intermediate module must define a variable and then pass it down using the 'source' or 'module' call block.

24
MCQhard

You are designing a module that should conditionally create resources based on a boolean input. What feature should you use?

A.Define multiple resources and use 'depends_on' to link them.
B.Use the 'count' meta-argument with a ternary expression.
C.Use an 'if' block around the resource definition.
D.Use the 'module' meta-argument inside the resource.
AnswerB

Setting 'count = var.enabled ? 1 : 0' is the standard pattern for conditional resource creation.

Why this answer

The 'count' meta-argument is commonly used to toggle resource creation based on a boolean value.

25
MCQmedium

You are using a module that depends on a specific provider version. Where should this constraint be defined?

A.In the 'required_providers' block within the module's 'terraform' block.
B.In the 'provider' block of the calling root module.
C.In the root module only.
D.In a shell environment variable.
AnswerA

This guarantees that the module's requirements are met during execution.

Why this answer

The 'required_providers' block within the 'terraform' block of the module is the correct location to pin versions.

26
MCQmedium

You want to use a module that is hosted in a private GitHub repository. Which authentication method should Terraform use to access it?

A.Use the same credentials that 'git clone' would use for that repository.
B.The module must be public for Terraform to access it.
C.Terraform requires a special 'git_token' variable in the module block.
D.Embed your GitHub password in the source URL.
AnswerA

Terraform leverages the underlying git command, so existing authenticated git configurations work.

Why this answer

Terraform uses the credentials configured in the local environment (e.g., ~/.git-credentials or SSH keys) to authenticate with private repositories.

27
Multi-Selecteasy

Which TWO of the following are true about the '.terraform' directory?

Select 2 answers
A.It contains the module source code downloaded from registries.
B.It should be committed to version control.
C.It contains the permanent state file.
D.It is created by 'terraform init'.
E.It is where custom provider binaries are compiled.
AnswersA, D

Downloaded modules are stored here.

Why this answer

The '.terraform' directory is used locally by Terraform to store module files and provider plugins.

28
MCQhard

When should you use the 'for_each' meta-argument within a module?

A.To iterate over a list of variables inside a resource block.
B.To replace the 'count' meta-argument when you only need one instance.
C.To instantiate multiple copies of a module based on a map or set.
D.To speed up the execution of the provider.
AnswerC

'for_each' is specifically designed for creating multiple module instances.

Why this answer

'for_each' is used to create multiple instances of a module based on a map or set of strings.

29
MCQeasy

What command do you run to view the documentation for a module that has been published to a registry?

A.'terraform view-module'
B.'terraform show'
C.Check the registry website for the module page.
D.'terraform doc <module>'
AnswerC

Registry documentation is provided via the web interface.

Why this answer

The registry automatically renders documentation in the UI; no CLI command is required to 'view' the documentation directly.

30
Multi-Selectmedium

Which TWO meta-arguments can be used within a module block?

Select 2 answers
A.'count'
B.'provisioner'
C.'for_each'
D.'depends_on'
E.'lifecycle'
AnswersA, C

'count' is a valid meta-argument for modules.

Why this answer

'count' and 'for_each' are the two meta-arguments available for module blocks.

31
MCQhard

Why would you use a 'locals' block within a module instead of passing everything through variables?

A.To reduce repetition and perform transformations on inputs.
B.To allow the user to override internal values easily.
C.To bypass input validation.
D.To store state data securely.
AnswerA

Locals clean up repetitive code and keep the module interface simple.

Why this answer

'locals' are ideal for transforming inputs, combining data, or creating complex naming conventions that the user shouldn't have to define.

32
MCQmedium

What is the impact of using 'sensitive = true' in a module output?

A.It disables the ability to use that output in other modules.
B.It encrypts the data in the state file.
C.It automatically rotates the sensitive credentials.
D.It prevents the value from being printed in the CLI output.
AnswerD

This is the main purpose of the 'sensitive' flag.

Why this answer

It marks the output as sensitive, preventing it from being printed to the console during 'terraform apply' or 'plan'.

33
MCQmedium

When a module is updated, how do you ensure that all environments using this module get the update?

A.The module updates automatically on every 'apply'.
B.Run 'terraform init -upgrade' to fetch the latest version allowed by the constraints.
C.Delete the state file and re-run apply.
D.Restart the Terraform CLI process.
AnswerB

The '-upgrade' flag is required to override the existing locked version.

Why this answer

You must update the version constraint (if pinned) and run 'terraform init -upgrade' to fetch the new version.

Ready to test yourself?

Try a timed practice session using only Terraform Modules questions.