Terraform Modules

Learn to create different Terraform modules.


We’ve already made and used Terraform modules, but in this lesson, we’ll reference a module and combine it with another one.

Like libraries, we can reference them in other Terraform modules without necessarily being concerned with the other module’s implementation details.

Like functions, modules can have inputs and outputs. However, we don’t need to be concerned with their implementation details for this course.

We’ll create a module and then use it from another module to work through the basic library functionality. Understanding how Terraform modules work is vital in regular Terraform usage.

Create a module

We’ve created a directory in order to understand how to reference a module and named it ltthw_modules. Then we created hello_module and hello_module_consumer_1 directories with hello_module.tf and hello_module_consumer_1.tf files, respectively.

You may have noticed that we created an extra directory level. Instead of just creating a folder structure like ltthw_modules/hello_module.tf, we created ltthw_modules/hello_module/hello_module.tf.

We know we can create multiple modules in multiple subfolders within ltthw_modules. We’ve created the hello_module module, then we created a module that consumes the hello_module as a library module. The second module hello_module_consumer_1 will source the hello_module.

Reference a module

In this module we’ll learn how to reference a module. We’ve created another module called hello_module_consumer_1 that sources the hello_module and creates the local file specified in that module. Next, we are going to run this module up. Think about what you expect will happen when we run it.

Get hands-on with 1200+ tech skills courses.