You have a Terraform root module that calls two child modules: network and compute. The compute module requires the VPC ID output from the network module. Which is the correct way to pass the VPC ID from network to compute?
module "network" { source = "./modules/network" } module "compute" { source = "./modules/compute" vpc_id = ??? }
Think about how Terraform modules expose outputs and how other modules can access them.
In Terraform, outputs from one module can be accessed using module.. Here, module.network.vpc_id correctly references the output from the network module.
You want to reuse a Terraform module stored in a GitHub repository. Which source value correctly references the module?
module "storage" { source = ??? version = "1.0.0" }
Terraform requires a specific syntax to fetch modules from Git repositories.
To use a module from a Git repository, the source must start with git:: followed by the repository URL. Option A is the correct syntax.
You have a root module that calls a child module which requires a sensitive API key. How should you pass this sensitive variable to avoid exposing it in Terraform state or logs?
module "service" { source = "./modules/service" api_key = ??? }
Consider how Terraform handles sensitive variables and best practices for secrets.
Passing sensitive data as input variables marked sensitive (like var.api_key) is best practice. Hardcoding secrets or using outputs can expose them. Locals do not protect sensitivity.
Given two modules, db and app, where app depends on the database endpoint output from db, what is the effect on resource creation order when you run terraform apply?
module "db" { source = "./modules/db" } module "app" { source = "./modules/app" db_endpoint = module.db.endpoint }
Think about how Terraform manages dependencies between modules using outputs and inputs.
Terraform automatically creates resources in dependency order. Since app uses an output from db, db resources are created first.
You are designing a Terraform infrastructure with multiple environments (dev, staging, prod). Which module composition pattern best supports reusability and environment-specific customization?
Consider how to avoid code duplication while allowing environment differences.
Using a single root module with environment variables passed to shared child modules promotes code reuse and easier maintenance. Other options cause duplication or inflexibility.