Storing modules remotely

We've stored the application module in the very same directory where our main Terraform template resides. It makes it impossible to reuse: if there is a new application in the company that requires the same infrastructure (meaning the same module), then we cannot easily use it.

Remember the source attribute of the module?

module "mighty_trousers" { 
  source = "./modules/application" 

Well, it turns out that it doesn't have to be a path to a local directory. In fact, there are multiple supported sources for modules:

  • GitHub
  • BitBucket
  • Generic Git and Mercurial repositories
  • HTTP URLs
  • S3 buckets

Storing modules in one of these destinations allows us to have a collection of reusable components. We can even version our modules, just like ...

Get Getting Started with Terraform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.