Remote Modules

Learn what remote modules are and how you can work with them in your Terraform project.

Remote modules

Modules are great for enabling you to reuse configuration blocks across a project. What if you want to build up a library of modules and share them across your company or with your friends, though? Terraform has answered that question with remote modules. A remote module is a module hosted externally to the local file system. Terraform supports many different remote module sources such as GitHub, BitBucket, and S3.

Project example

We are going to use GitHub to host the sqs-with-backoff module that we declared and then reference in our local project:

provider "aws" {
    region = "us-east-2"
}

module "work_queue" {
    source = "github.com/kevholditch/sqs-with-backoff"
    queue_name = "work-queue"
}

output "work_queue" {
    value = module.work_queue.queue
}

output "work_queue_dead_letter_queue" {
    value = module.work_queue.dead_letter_queue
}
Remote module Terraform project example

You will notice that this code is almost the same as the code we wrote earlier when using the sqs-with-backoff module. The only difference is that we are setting the source of the module to github.com/kevholditch/sqs-with-backoff ...