In Terraform, dependency inversion helps create modules that are more reusable and less tightly coupled. Which statement best describes this benefit?
Think about how modules can be flexible and reusable without knowing internal details of other modules.
Dependency inversion means modules rely on abstractions (inputs/outputs) instead of concrete details. This makes modules reusable and easier to maintain.
Given two Terraform modules, network and app, the app module needs the subnet ID created by network. Which code snippet correctly applies dependency inversion?
module "network" { source = "./network" } module "app" { source = "./app" subnet_id = ??? }
Remember that modules expose outputs to share data.
The network module should expose the subnet ID as an output. The app module receives it via input variable. Using module.network.subnet_id correctly passes the value.
When Terraform modules directly reference each other's internal resources instead of using inputs and outputs, what security risk is most likely?
Think about what happens if one module changes internal resource names used by another module.
Without dependency inversion, modules tightly coupled to internal resources can cause accidental changes or deletions because ownership and boundaries are unclear.
When Terraform modules use dependency inversion properly, how does it affect the terraform plan and terraform apply commands?
Consider how Terraform uses inputs and outputs to build a dependency graph.
Proper dependency inversion with inputs and outputs allows Terraform to build an accurate dependency graph, ensuring resources are created or updated in the correct order.
You want to deploy the same infrastructure modules to multiple environments (dev, staging, prod) with different configurations. Which design best applies dependency inversion?
Think about how to reuse code and separate configuration from implementation.
Using input variables for environment-specific settings and outputs for sharing data follows dependency inversion. It keeps modules reusable and decoupled from environment details.