본문으로 바로가기

Terraform의 리소스를 간단하게 README.md로 출력해주는 도구가 있다.

설치 (mac)

brew install terraform-docs
or
brew install terraform-docs/tap/terraform-docs

사용법

terraform-docs markdown table \\
  --output-file README.md \\
  --output-mode inject ./

위 명령어를 입력하면 현재 디렉터리에 존재하는 Terraform 리소스를 README.md 파일로 떨궈준다.

hook을 이용하여 파이프라인과 통합시키기

1. pre-commit 설치

  • 소스코드에 commit 작업 전 hooking을 통해 특정 과정을 자동화 시켜주는 툴임.
brew install pre-commit

2. .pre-commit-config.yaml 작성

repos:
  - repo: https://github.com/terraform-docs/terraform-docs
    rev: "v0.16.0"
    hooks:
      - id: terraform-docs-go
        args: ["markdown", "table", "--output-file", "README.md", "./mymodule/path"]

3. pre-commit 실행

pre-commit install pre-commit install-hooks

 

이 밖에도 설정파일을 만들어서 다양하게 커스터마이징이 가능하다.

자세한 정보는 https://github.com/terraform-docs/terraform-docs에서 확인하자.

 

Reference