Skip to main content

Documentation generator for Terraform modules

Project description

TF-Docs

tfdocs lets you generate README.md for Terraform modules based on variables.tf. Additionally, it can sort variable definitions.

Usage

tfdocs [flags] <variables.tf>

Flags:

-h, --help            Show this help message and exit
--name, -n            Specify a custom name for the module
--readme              Specify the name of the output file (default: README.md)
--variables           Specify the name of the file containing variables (default: variables.tf)
--source SOURCE       Specify a custom source for the module
--git-source          Only to be used together with --source to specify the source is a git repository. If true, sub directory and a place holder TAG will be appended to the source
-f                    Format and sort variables.tf file
--dry-run             Show the output without writing to the file
--version

Input file

Default: variables.tf

All the input variables of the module must be defined in a single file. By default tfdocs will look for a file named variables.tf in the current directory. Alternatively a custom file can be specified using the --variables flag.

Example

variables.tf

variable "my_string" {
  type = string
  description = "Description of the string"
  default = "default"
}

variable "my_list" {
  type = List(string)
  description = "Description of the list"
  default = ["default"]
}

Format variables.tf

You can use the -f flag to format the variables.tf file. This will sort the variables in alphabetical order.

Generated Readme file

Default: README.md

The module expects to have a README.md file in the current directory. If the file does not exist, tfdocs will create one. Alternatively, a custom file can be specified using the --readme flag.

Example

README.md

# My module

Insert a description of the module here.

<!-- TFDOCS START -->
module <my_module> {
source = "git@github.com:<your_name>/<your_repo>.git//<subfolder>?ref=<TAG>"
my_list = <LIST(STRING)>    # Description of the list
my_string = <STRING>        # Description of the string
}
<!-- TFDOCS END -->

Custom content

tfdocs replaces only the content between the markers below with variable definitions from variables.tf.

Markers: <!-- TFDOCS START --> and <!-- TFDOCS END -->

Module Source

Default: git-remote-origin//<subfolder>?ref=<TAG>

By default, if the module is in a Git repository, tfdocs will utilize the remote origin to generate the source URL (git://github.com/<your_name>/<your_repo>.git//<subfolder>?ref=<TAG>).

Otherwise, either the source URL can be specified using the --source flag or if not provided it will default to ./modules/{CURRENT_DIRECTORY}.

Annotations

Override variable type

Use #tfdocs: type=<TYPE> to override the variable type. This is useful when the type is not correctly inferred from the variable definition or when you want to customize it.

Example

variables.tf

variable "my_object" {
  #tfdocs: type = list(object)
  type = list(object({
    name = string
    size = number
    directory = string
  }))
  description = "Description of the string"
  default = "default"
}

Note: tfdocs overwrite an existing README.md file. It's always good to use --dry-run first.

Authors

tfdocs is created and maintained by ivlabs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfdocs-1.6.1.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tfdocs-1.6.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file tfdocs-1.6.1.tar.gz.

File metadata

  • Download URL: tfdocs-1.6.1.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for tfdocs-1.6.1.tar.gz
Algorithm Hash digest
SHA256 6398665ffb796094719c80f1c785e8521624329242e3c5fa2c7fc20689bc3521
MD5 15d4cfb2376ad2e68ccf874c23241f96
BLAKE2b-256 2d428dddd1bd5cbfcdc424a41deb3df54f41ffa5287d0ea8b265590818b842ee

See more details on using hashes here.

File details

Details for the file tfdocs-1.6.1-py3-none-any.whl.

File metadata

  • Download URL: tfdocs-1.6.1-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for tfdocs-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a61af91986eb3c503b29dc343cea742f1b25894f5c3af3d61e0bf2d4dc43ef30
MD5 96d3f5cc24364cecd4fbfed22ad8d7a2
BLAKE2b-256 43be60ff04c25796f9498d585274b4b47111ed8c8b9ec5906f7f44dac41a516f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page