Terraform module
A directory of Terraform files with inputs (variables) and outputs, which other configurations can call to reuse the same infrastructure design.
In more detail
Every configuration is a module; the one you run commands in is the root module, and the ones it calls are child modules. A module block names the source and passes values for the child's variables, and the caller reads results as module.<name>.<output>. A good module has a small interface and keeps provider details private.
Example
module "network" {
source = "./modules/network"
name = var.network_name
subnets = var.subnet_names
}Related terms
- root module — The configuration in the directory where you run Terraform commands, which may call other modules.
- child module — A module called from another module with a module block.
- module interface — The variables a module accepts and the outputs it publishes, which together are everything a caller may rely on.
- module source — The source argument of a module block, which says where to get the module: a local path such as ./modules/network, the registry, or a Git address.
- public module — A reusable module published to the Terraform Registry, called by an address such as terraform-aws-modules/vpc/aws.
Taught in
- Initialising The Working Directory — Infrastructure as Code with Terraform
- Why Modules: Composition Versus Monoliths — Infrastructure as Code with Terraform
- Writing A Custom Network Module — Infrastructure as Code with Terraform
- Calling Your Module And Passing Variables — Infrastructure as Code with Terraform
- The Terraform Registry And Public Modules — Infrastructure as Code with Terraform
- Versioning And Pinning Modules — Infrastructure as Code with Terraform
- The Plan That Wanted To Destroy Production — HashiCorp Terraform Associate (004) Exam Prep
- One Hour, No Weights Published — HashiCorp Terraform Associate (004) Exam Prep
- Infrastructure As Code, And One Workflow For Every Platform — HashiCorp Terraform Associate (004) Exam Prep
- Providers: How Terraform Reaches Every API — HashiCorp Terraform Associate (004) Exam Prep
- Versions, The Lock File And Provider Aliases — HashiCorp Terraform Associate (004) Exam Prep
- State: Terraform's Memory Of What It Built — HashiCorp Terraform Associate (004) Exam Prep
- Write, Plan, Apply, And What Init Prepares — HashiCorp Terraform Associate (004) Exam Prep
- Validate, Format, Destroy, And The Flags That Bend A Plan — HashiCorp Terraform Associate (004) Exam Prep