Skip to content

Read config from relative path, absolute, or $HOME #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2021

Conversation

khos2ow
Copy link
Member

@khos2ow khos2ow commented Apr 30, 2021

Description of your changes

Configuration can be loaded with -c, --config string which accepts
both relative and absolute paths.

$ pwd
/path/to/parent/folder
$ tree
.
├── module-a
│   └── main.tf
├── module-b
│   └── main.tf
├── ...
└── .terraform-docs.yml

# executing from parent
$ terraform-docs -c .terraform-docs.yml module-a/

# executing from child
$ cd module-a/
$ terraform-docs -c ../.terraform-docs.yml .

# or an absolute path
$ terraform-docs -c /path/to/parent/folder/.terraform-docs.yml .

The order for looking for config file is:

  1. root of module directory
  2. current directory
  3. $HOME/.tfdocs.d/

if .terraform-docs.yml is found in any of the folders above, that will
take precedence and will override the other ones. Note that values passed
directly as CLI flags will override all of the above.

Fixes #445

I have:

How has this code been tested

Manually built and tested for various scenarios:

  • config exists with default name
  • config exists without default name and explicitly set with --config
  • set config with --config with relative path (e.g. ../path/to/.terraform-docs.yml)
  • set config with --config with absolute path (e.g. /absolute/path/to/.terraform-docs.yml)
  • create config file in 1) module directory and 2) its parent and 3) $HOME/.tfdocs.d/ and make sure they will override one another

Configuration can be loaded with `-c, --config string` which accepts
both relative and absolute paths.

    $ pwd
    /path/to/parent/folder

    $ tree
    .
    ├── module-a
    │   └── main.tf
    ├── module-b
    │   └── main.tf
    ├── ...
    └── .terraform-docs.yml

    # executing from parent
    $ terraform-docs -c .terraform-docs.yml module-a/

    # executing from child
    $ cd module-a/
    $ terraform-docs -c ../.terraform-docs.yml .

    # or an absolute path
    $ terraform-docs -c /path/to/parent/folder/.terraform-docs.yml .

The order for looking for config file is:

1. root of module directory
2. current directory
3. `$HOME/.tfdocs.d/`

if `.terraform-docs.yml` is found in any of the folders above, that will
take precedence and will override the other ones. Note that values passed
directly as CLI flags will override all of the above.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
@khos2ow khos2ow merged commit 4103e59 into terraform-docs:master Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--config option is always relative to the target path, not $PWD.
1 participant