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 ]] | [[
```