# 12. Modules

### Introduction

* Modules are containers for multiple resources that are used together. A module consists of a collection of .tf and/or .tf.json files kept together in a directory
* Modules are main way to package and reuse resource configurations with terraform
* Input variables are passed in via module block

***

### Types

#### 1. Root Module

Default module containing all .tf files in main working directory

#### 2. Child Module

A sepearte external module referred to from a .tf file

***

### Module Sources

#### Local paths

```hcl
module "web-app" {
  source = "../web-app"
}
```

#### Terraform Registry

```hcl
module "web-app" {
  source = "hashicorp/consul/aws"
  version = "0.1.0"
}
```

#### Github

* via HTTPS
* via SSH
* Generic i.e `source = "git::ssh//username@example.com/storage.git"`

#### Others

* Bitbucket
* Generic Git
* HTTP URLs
* S3 buckets

***

### Good Module Characteristics

* Raise abstraction level from base resource types
* Group resources in a logical fashion
* Exposes input variables to allow necessary customization + composition
* Provide useful defaults
* Returns outputs to make further integrations possible

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.nomanaziz.me/devops/infrastructure-as-a-code-iac/terraform/12.-modules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
