Skip to main content
Welcome — this hands-on guide shows how to consume modules from the Terraform Registry to provision a VPC and a security group, and how to pass outputs from one module into another. No slides — just the minimal files and commands you’ll need. Create these files in an empty directory (open in VS Code or your editor of choice):
  • main.tf
  • variables.tf
  • providers.tf (or include provider config in main.tf)
  • outputs.tf (create when prompted below)
What you’ll do:
  • Find and inspect a VPC module on the Registry.
  • Add variables and call the VPC module.
  • Initialize, plan, and apply to create the VPC.
  • Export the VPC ID via an output.
  • Consume that output in another module (security group).
  • Export the security group ID.

Browsing modules on the Terraform Registry

Head to the Terraform Registry and search for modules for your provider. Reusing community or vendor modules speeds up provisioning and reduces boilerplate.
A browser screenshot of the Terraform Registry showing a list of modules (e.g., terraform-aws-modules/iam, cloudposse/label, terraform-aws-modules/vpc) with provider filters in a left sidebar. The page has a purple header with search and navigation controls.
Choose the AWS VPC module terraform-aws-modules/vpc/aws. The Registry README includes usage examples; a minimal module block looks like:
Read the module README to learn available inputs and outputs. The VPC module exposes many optional inputs (for example cidr and name) and useful outputs like vpc_id.

See the module source code

If you want to inspect implementation details, the Registry usually links to the module’s source repository (commonly GitHub). Look for main.tf, variables.tf, and outputs.tf to understand the variables and outputs the module exposes.
A screenshot of a GitHub repository page for the terraform-aws-modules/terraform-aws-vpc project, showing a file list with variables.tf highlighted. The lower part shows the README header "AWS VPC Terraform module" and some repository metadata on the right.

Define variables and call the VPC module

Create variables.tf to hold configurable values for the VPC name and CIDR. Note the corrected CIDR default below:
Add a provider and module block to main.tf. This example pins the aws provider and passes the variables into the VPC module:

Initialize, plan, and apply

Set your AWS credentials via environment variables or your preferred method, then run:
Terraform will download the module and providers. Example (abridged):
Plan and apply:
Confirm the apply by typing yes when prompted. Example outputs:
Then:
Quick reference — common Terraform commands

Verify state and the created VPC

List resources managed by Terraform:
Example output:
In the AWS console (here us-east-1) you should see the VPC with the CIDR you supplied (192.168.0.0/16).

Add an output to expose the VPC ID

Create or update outputs.tf to export the VPC ID from your root module:
Run terraform apply again — this typically reports no resource changes and adds the output:
Inspect module outputs on the Registry — the VPC module documents outputs like vpc_id that are intended for consumption by other modules or the root module.
Screenshot of a Terraform Registry page listing outputs for the terraform-aws-vpc module, showing output names like vpc_id, vpc_instance_tenancy, vpc_ipv6_cidr_block, vpc_main_route_table_id, and descriptions for each. The vpc_id entry is highlighted on the left.

Consume the VPC output in another module (security group)

Now consume module.vpc.vpc_id as input to a security group module. Add a module block (choose an identifier-safe name like security_group) to main.tf:
Important: when you add or change module sources, re-run terraform init so Terraform can download any new modules.
Any time you add or change module sources, rerun terraform init so Terraform can install the newly referenced modules locally.
If you run terraform plan before terraform init after adding a module, you’ll see:
Run:
Expected confirmation:
You can now verify in the AWS console that the security group my-cool-security-group exists and is associated with the VPC created earlier.
A screenshot of the AWS VPC Security Groups page showing a list of security groups, with "my-cool-security-group" selected. The lower pane shows details (ID, name, description and VPC association), and browser tabs referencing Terraform modules are visible at the top.
Also confirm your VPC details in the console:
A screenshot of the AWS VPC console showing a VPC named "my-terraform-vpc" (VPC ID vpc-0c11fbe634c8a9edf) in state "Available" with IPv4 CIDR 192.168.0.0/16. The details pane shows DNS resolution enabled, Block Public Access off, and links to the route table and DHCP option set.

Output the security group ID

To expose the security group ID from the root module, add this to outputs.tf:
Run terraform apply once more (no infra changes expected) to add the output. Example final outputs:

Summary and best practices

  • The Terraform Registry is a primary source for reusable modules — search by provider and use well-reviewed modules.
  • Always inspect a module’s README and source to learn variable names, defaults, and available outputs.
  • Pass values from the root module into child modules with variables; get values back through module outputs.
  • Re-run terraform init whenever you add or modify module sources so Terraform can download them.
  • Pin provider and module versions to achieve reproducible configurations.
Links and references Go explore the Registry and compose modules together to accelerate infrastructure provisioning. Let module authors handle resource complexity while you focus on infrastructure design.

Watch Video

Practice Lab