0
0
Terraformcloud~30 mins

Module sources (local, registry, git) in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Terraform Module Sources: Local, Registry, and Git
📖 Scenario: You are managing infrastructure with Terraform. You want to reuse code by using modules from different sources: a local folder, the Terraform Registry, and a Git repository.
🎯 Goal: Build a Terraform configuration that uses three modules: one from a local path, one from the Terraform Registry, and one from a Git repository. This will help you organize and reuse your infrastructure code efficiently.
📋 What You'll Learn
Create a Terraform configuration file named main.tf.
Add a module named local_module sourced from a local folder ./modules/local_module.
Add a module named registry_module sourced from the Terraform Registry terraform-aws-modules/vpc/aws with version 3.14.2.
Add a module named git_module sourced from a Git repository https://github.com/hashicorp/example.git using the main branch.
💡 Why This Matters
🌍 Real World
Terraform modules help organize and reuse infrastructure code efficiently across projects and teams. Using different module sources allows flexibility in managing infrastructure components.
💼 Career
Understanding how to use modules from local paths, registries, and Git repositories is essential for infrastructure engineers and DevOps professionals working with Terraform.
Progress0 / 4 steps
1
Create the initial Terraform configuration with a local module source
Create a file named main.tf and add a module block named local_module with the source set to ./modules/local_module.
Terraform
Need a hint?

Use the module block with the exact name local_module and set source to ./modules/local_module.

2
Add a module from the Terraform Registry
In main.tf, add a module block named registry_module with the source set to terraform-aws-modules/vpc/aws and version set to 3.14.2.
Terraform
Need a hint?

Use the exact module name registry_module, set source to the registry path, and specify version as 3.14.2.

3
Add a module sourced from a Git repository
In main.tf, add a module block named git_module with the source set to git::https://github.com/hashicorp/example.git?ref=main.
Terraform
Need a hint?

Use the exact module name git_module and set source to the Git URL with git:: prefix and ?ref=main to specify the branch.

4
Complete the Terraform configuration with required Terraform block
Add a terraform block at the top of main.tf specifying required_version as >= 1.0.0 and a required_providers block with aws provider source hashicorp/aws and version ~> 4.0.
Terraform
Need a hint?

Start your file with a terraform block specifying the required Terraform version and the AWS provider source and version.