Difficulty: Beginner
Estimated Time: 30 minutes

Use Modules from the Registry

This Katacoda scenario is meant to serve as a companion piece for the Use Modules from the Registry Terraform Learn tutorial.

In this scenario, you will use modules from the Terraform Registry to provision an example environment on AWS. The concepts you use in this scenarios will apply to any modules from any source.

This environment has been pre-configured with the Terraform CLI and localstack, a mocking framework that mocks core AWS APIs locally. As a result, you do not need an AWS account to complete this scenario.


You've reached the end of the scenario!

If you'd like to learn more, try one of these resources on HashiCorp Learn:

Use Modules from the Registry

Step 1 of 4

Explore configuration

Open main.tf.

This configuration includes three blocks:

  • The provider "aws" block defines your defines your provider and region. It also includes additional settings that allow this scenario to use localstack to simulate infrastructure, instead of requiring you to have an AWS account. Refer to the code in the Learn tutorial to build real infrastructure, which will require you to authenticate with AWS.
  • The module "vpc" block defines a Virtual Private Cloud (VPC), which will provide networking services for the rest of your infrastructure.
  • The module "ec2_instances" block defines two EC2 instances within your VPC.

Use the Terraform Registry

Open the Terraform Registry page for the VPC module in a new browser tab or window.

Terraform Registry Details Page

It provides information about the module, as well as a link to the source repository. On the right side of the page, you will find a dropdown interface to select the module version, as well as instructions to use the module to provision infrastructure.

When calling a module, the source argument is required. In this example, Terraform will search for a module in the Terraform registry that matches the given string. You could also use a URL or local file path for the source of your modules. Refer to the Terraform documentation for a list of possible module sources.

The other argument shown here is the version. For supported sources, the version will let you define what version or versions of the module will be loaded. In this tutorial, you will specify an exact version number for the modules you use. You can read about more ways to specify versions in the module documentation.

Other arguments to module blocks are treated as input variables to the modules.