HomeToolsAbout

Block and Modules

Block

Every terraform has at least one module known as the root module.

Modules

Modules are containers for multiple resources that are used together.

Module consists of collection of .tf files kept in the same directory.

Modules are the main way to package and reuse resource configurations with Terraform.

The Terraform Registry hosts a broad collection of publicly available Terraform modules for configuring many kinds of common infrastructure.

source

source argument in a module block tells Terraform where to find the source code for the desired child module.

Calling Module

module "servers" { source = "./app-cluster" version = "0.0.5" servers = 5 }

Reference output values from modules

Since modules are encapsulated, you cannot access the attributes directly from calling it.

If a module exported an output value named instance_ids, that value can be accessed by module.servers.instance_ids

Exporting an output value using an output block:

output "instance_ip_addr" { value = aws_instance.server.private_ip }
resource "aws_elb" "example" { # ... instances = module.servers.instance_ids }
AboutContact