Skip to content

mijdavis2/tf-unused

Repository files navigation

tf-unused

release build pre-commit license downloads docker image

Find unused variables in terraform modules.

Forked from https://github.com/nvkv/tf-unused and migrated to docker_image based pre-commit hook.

Table of Contents generated with DocToc

Installation

  • Download binary for appropriate platform from releases page.
  • Put it somewhere in $PATH

Usage

tf-unused <path-to-tf-module>

When no path specified, tf-unused will check current directory instead. If there are unused variables, they will be printed out and process will return non-zero return code. Otherwise nothing will be printed and process will exit with 0.

Examples

% tf-unused tests/fixtures/has_unused/
In tests/fixtures/has_unused/vars.tf:
 * Unused definition legacy_switch_i_forgot_to_remove
 * Unused definition surprisingly_unimportant_variable

In tests/fixtures/has_unused/some.tfvars:
 * Unused value for some_random_variable

% echo $?
1
% tf-unused tests/fixtures/has_no_unused/

% echo $?
0

Using with pre-commit

Requires docker.

Add this to your .pre-commit-config.yaml:

- repo: https://github.com/mijdavis2/tf-unused
  sha: ''  # Use the sha / tag you want to point at
  hooks:
  - id: tf-unused