Terraform-docs Page

terraform-docs


* Definition: terraform-docs is a tool that generates documentation for Terraform modules and configurations. It extracts information from Terraform configurations and outputs it in various formats, making it easier to understand and use the infrastructure code.
* Function: Automatically creates documentation from Terraform modules, providing details about inputs, outputs, providers, and resources, which helps in maintaining clear and up-to-date documentation for Terraform projects.
* Components:
* Terraform Configuration Files: The `.tf` files containing the infrastructure as code definitions.
* terraform-docs Binary: The executable tool that reads Terraform configurations and generates documentation.
* Features:
* Auto-Generated Documentation: Extracts and formats information from Terraform modules without manual intervention.
* Support for Multiple Formats: Outputs documentation in formats such as Markdown, JSON, YAML, HTML, and AsciiDoc.
* Customizable Output: Allows customization of the generated documentation to meet specific needs.
* Module-Level Documentation: Focuses on documenting individual modules, including their inputs, outputs, and dependencies.
* Usage: Useful for DevOps and infrastructure teams to keep Terraform module documentation up-to-date, improving the clarity and usability of infrastructure code.

Examples


* Installing terraform-docs:
```bash
go install github.com/terraform-docs/terraform-docs@latest
```

* Generating Markdown documentation for a Terraform module:
```bash
terraform-docs markdown ./
```

* Generating JSON documentation for a Terraform module:
```bash
terraform-docs json ./
```

* Sample command to generate documentation and save it to a file:
```bash
terraform-docs markdown ./ > README.md
```

* Example of generated Markdown documentation:
```markdown
## Providers

| Name | Version |
|------|---------|
| aws | >= 2.0 |

## Inputs

| Name | Description | Type | Default | Required |
|---------------|---------------------------------------|----------|---------|:--------:|
| instance_type | The type of instance to use | `string` | `t2.micro` | yes |
| ami_id | The AMI ID for the instance | `string` | n/a | yes |

## Outputs

| Name | Description |
|--------------|-------------------------|
| instance_id | The ID of the instance |
| instance_ip | The IP address of the instance |
```

Summary


* terraform-docs: A tool that generates documentation for Terraform modules by extracting information from configuration files. It supports multiple output formats, customizable documentation, and helps in maintaining clear, up-to-date documentation for Terraform projects, enhancing the usability and maintainability of infrastructure code.