Skip to content

Instantly share code, notes, and snippets.

@v-bus
Created January 28, 2022 21:14
Show Gist options
  • Save v-bus/9c6f0bf2c7befb21ceae9a855e210609 to your computer and use it in GitHub Desktop.
Save v-bus/9c6f0bf2c7befb21ceae9a855e210609 to your computer and use it in GitHub Desktop.
How to generate terraform module
variable "module_dir" {
default = "module"
}
locals {
file_list = [
"provider.tf",
"main.tf",
"versions.tf",
"variables.tf",
"outputs.tf",
"README.md"
]
module_dir = "${path.root}/${var.module_dir}"
}
resource "local_file" "module" {
count = length(local.file_list)
filename = "${local.module_dir}/${local.file_list[count.index]}"
}

Generate Terraform Module

  1. install terraform
  2. copy gen_module.tf to your folder
  3. run terraform init there
  4. run terraform apply -auto-approve there
  5. make some changes
  6. install terraform-docs like brew install terraform-docs
  7. generate README.md file for fun terraform-docs markdown table --output-file README.md --output-mode inject /path/to/module

Have fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment