From the course: Learning Terraform

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Using modules

Using modules

- [Instructor] Modules are a Terraform feature that lets you combine some of your code into a logical group that can be managed together. You can bundle together some logical block of code and pass in arguments that apply for that block. In that sense, you might think of modules as working like custom resources. All Terraform code actually has at least one module. That's the default module known as root. This is where we've been working and writing our code. Let's start by looking at the code for using a module. Imagine we've got a web app that needs a few things, maybe a DNS entry, an EC2 instance and an S3 bucket. It doesn't really matter for us what's inside the module right now. We just need to know how to talk to it. First, we'll need to tell Terraform where to find the module. In this case, it's a local directory. Then we're passing in two arguments, so there's a server name and a web AMI in our example. Pretty simple, right? Inside the module, it's also pretty simple to…

Contents