- Provision an AWS VPC using the community module
terraform-aws-modules/vpc/aws. - Export the VPC ID from that module to the root module.
- Pass the VPC ID into a security group module (
terraform-aws-modules/security-group/aws) so the security group is created in the same VPC. - Do all of this without writing any low-level
aws_*resource blocks in the root module.
| File | Purpose |
|---|---|
main.tf | Module blocks that call registry modules (VPC, security group) |
variables.tf | Root-module variable declarations and defaults |
providers.tf | Provider configuration (AWS provider, required provider constraints) |
outputs.tf | Root-module outputs that expose child-module outputs |

Browse the Terraform Registry
The Terraform Registry hosts both providers and modules. Modules are reusable collections of Terraform configuration (typicallymain.tf, variables.tf, and outputs.tf) published by the community or organizations. Search the Registry for provider-specific modules (AWS, Azure, GCP, etc.) and review each module’s README to find inputs, outputs, and usage examples.
Below is an example page showing many AWS community modules (EKS, Lambda, KMS, and more).

terraform-aws-modules/vpc/aws. It exposes many optional inputs and useful outputs.
Inspect the VPC module README, inputs, and outputs
Registry modules usually document their inputs (variables) and outputs clearly in the README. Many inputs are optional and provide sensible defaults — you only need to override the values you want to change.
Define variables (variables.tf)
Createvariables.tf and declare the root-module variables you’ll pass into the VPC module. In this example we provide a CIDR block and a VPC name, both with defaults.
10.0.0.0/16; changing cidr_block to 192.168.0.0/16 demonstrates overriding a module default.
For more inputs including tags, route tables, and subnet options see the module inputs:

Add the VPC module (main.tf)
Add a module block inmain.tf that references the Registry source and wires the root variables into the module inputs:
Provider configuration (providers.tf)
Declare the required provider constraint and configure the AWS provider. Credentials are supplied via environment variables or other supported credential providers.Ensure your AWS credentials are available before running Terraform commands. You can export
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and optionally AWS_SESSION_TOKEN, or use the AWS CLI credential store.Initialize the working directory
Open a terminal, confirm your credentials, then run:.terraform/modules/vpc and installed the AWS provider plugin.
Run
terraform init after adding or changing module sources so Terraform can download required modules and providers.Plan and apply the VPC
Plan to preview the resources the module will create. Depending on inputs and defaults the VPC module may create a VPC, route tables, a default security group, network ACLs, and subnets.192.168.0.0/16 in this example): https://console.aws.amazon.com/vpc/home

Export the VPC ID from the module (outputs.tf)
To use the VPC ID elsewhere, expose the module output at the root level by adding an output:vpc_id) from the module page.

Use the VPC ID input for another module (security group)
Now consume that exported VPC ID in a security group module (terraform-aws-modules/security-group/aws). The security group module expects vpc_id among its inputs.
Append the following to main.tf:
egress_rules, egress_ipv6_cidr_blocks, ingress_rules, etc. We only pass the required vpc_id and a name in this example.

my-cool-security-group exists and is attached to the same VPC.
Export the security group ID (append to outputs.tf)
To expose the created security group ID from the module, add an output inoutputs.tf:
Quick command reference
| Command | Purpose |
|---|---|
terraform init | Download providers and modules referenced by your configuration |
terraform plan | Preview changes Terraform will make |
terraform apply | Apply the planned changes to create/update resources |
terraform state list | Inspect tracked resources in the state file |
Summary
- The Terraform Registry hosts thousands of reusable modules. Inspect module READMEs for inputs and outputs before consumption.
- Call child modules in the root module with
module "<name>" { source = "..." }and pass values via module inputs. - Modules can export outputs you reference as
module.<MODULE_NAME>.<output_name>; those values can be passed into other modules. - Always run
terraform initwhenever you add or change external module sources so Terraform downloads the modules and providers.
Links and references
- Terraform Registry — https://registry.terraform.io
- terraform-aws-modules/vpc/aws — https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/latest
- terraform-aws-modules/security-group/aws — https://registry.terraform.io/modules/terraform-aws-modules/security-group/aws/latest
- AWS provider documentation — https://registry.terraform.io/providers/hashicorp/aws/latest