terraform-docs 幫你產生 Terraform Module variable / output 文件

2019-05-07 Terraform

最近挖到一個 terraform 的 module 小工具,很多 IaC 都會出類似的 Document 產生工具,而 Terraform 目前就屬「terraform-docs」還不錯用。

terraform-docs 是一個自動產生 Variable / Output 的資訊的工具,你可以透過 main.tf 的註解去定義想要的訊息。

安裝

terraform-docs 是用 Golang 開發,所以直接可以用 go get 的方式取得:

$ go get github.com/segmentio/terraform-docs

或是在 MacOS 用 Homebrew 安裝

$ brew install terraform-docs

只要你有寫 variable or output

variable "region" {
  description = "aws region"
  default     = ""
}

output "vpc_id" {
  description = "The ID of the VPC"
  value       = "${element(concat(aws_vpc.this.*.id, list("")), 0)}"
  • 產生 Markdown 格式的 “純文字描述” 文件
$ terraform-docs markdown document ./terraform-module
  • 產生 Markdown 格式的 “表格” 文件
$ terraform-docs markdown table ./terraform-module
  • 產生 Json 格式
$ terraform-docs json ./terraform-module

terraform-docs 也支援在 main.tf 用註解的方式寫 Document,常見的用法是直接用 Markdown 格式輸出,把 main.tf 的資訊和 output / variable 資訊輸出成 README.md

成品大概就會像 104corp/terraform-aws-aurora-serverless 這樣。

給 Mr. 沙先生一點建議

彙整

分類

展開全部 | 收合全部

License

訂閱 Mr. 沙先生 的文章

輸入你的 email 用於訂閱