Skip to main content

Terraform state viewer

Project description

Terraform lens

pre-commit unit-tests Pypi package coverage Supported versions check Quality Gate Status

Terraform lens is a CLI tool that enables developers have a summarized view of tfstate resources.

Description

It will produce a table with the resources in a given terraform tfstate with the following columns:

  • provider
  • type
  • mode
  • name
  • module

Example:

|   provider   |        type         |   mode  |           name                | module |
|--------------|---------------------|---------|-------------------------------|--------|
| provider.aws | aws_caller_identity |   data  |        current_user           |  test  |
| provider.aws |  aws_dynamodb_table | managed | dynamodb-terraform-state-lock |   -    |

Features

Currently, the tool supports read the tfstate file from a local file or a remote state stored in S3.

Regarding the produced output, there are three possibilities:

  • CLI output. This will show the table directly in the terminal.
  • Markdown file. This will creates a file .tflens/terraform.tfstate.json.md in the current directory with the table.
  • HTML file. It's also possible to create an html file .tflens/terraform.tfstate.json.html in the current directory with the table.

The tool has been tested with tfstate files for the following terraform versions:

  • 0.12.0 - 0.12.29
  • 0.13.0 - 0.13.7
  • 0.14.0 - 0.14.11
  • 0.15.0 - 0.14.5
  • 1.0.0

Install

As the content of this repo is a Pypi package, you can easily install it using pip:

pip install tflens

Usage

 tflens --help

usage: tflens [-h] [-f FILE_LOCATION] [-o OUTPUT] [-r REMOTE] [-m FILTER_MODULE] [-n FILTER_NAME] [-t FILTER_TYPE] [-p FILTER_PROVIDER] [-d FILTER_MODE] [-u HTTP_USER] [-w HTTP_PASSWORD] [-v]

Terraform lens is a CLI tool that enables developers have a summarized view of tfstate resources.

optional arguments:
  -h, --help            show this help message and exit
  -f FILE_LOCATION, --file-location FILE_LOCATION
        Defines the location (remote or local) of the tfstate file.
        Mandatory if remote tfstate is selected.
        If empty then use the current_folder/terraform.tfstate
  -o OUTPUT, --output OUTPUT
        Defines output type (markdown|html).
        If empty outputs in terminal
  -r REMOTE, --remote REMOTE
        Defines if remote (s3|http) or local tfstate file.
        If empty local is used.
        When remote is defined, you also need to specify --file-location with the tfstate location
        according to the following pattern: bucket-name/tfstate-key
  -s SHOW_COLUMNS, --show-columns SHOW_COLUMNS
        Comma separated string list with columns to show in output. Default list is: 'provider,type,mode,name,module'
  -m FILTER_MODULE, --filter-module FILTER_MODULE
        Applies a regular expression to the module field in order to filter the resources list to output
  -n FILTER_NAME, --filter-name FILTER_NAME
        Applies a regular expression to the name field in order to filter the resources list to output
  -t FILTER_TYPE, --filter-type FILTER_TYPE
        Applies a regular expression to the type field in order to filter the resources list to output
  -p FILTER_PROVIDER, --filter-provider FILTER_PROVIDER
        Applies a regular expression to the provider field in order to filter the resources list to output
  -d FILTER_MODE, --filter-mode FILTER_MODE
        Applies a regular expression to the mode field in order to filter the resources list to output
  -u HTTP_USER, --http-user HTTP_USER
        User for http remote backend basic auth
  -w HTTP_PASSWORD, --http-password HTTP_PASSWORD
        Password for http remote backend basic auth
  -v, --version
        Show program version

Examples

View table of resources for a tfstate located in the file system in the directory:

 tflens

|   provider   |        type         |   mode  |           name                | module |
|--------------|---------------------|---------|-------------------------------|--------|
| provider.aws | aws_caller_identity |   data  |        current_user           |  test  |
| provider.aws |  aws_dynamodb_table | managed | dynamodb-terraform-state-lock |   -    |

View table of resources for a tfstate located in the file system in the directory removing provider column:

 tflens --show-columns "type,mode,name,module"

|        type         |   mode  |           name                | module |
|---------------------|---------|-------------------------------|--------|
| aws_caller_identity |   data  |        current_user           |  test  |
|  aws_dynamodb_table | managed | dynamodb-terraform-state-lock |   -    |

This feature can be also used to change columns order:

 tflens --show-columns "module,name,type"

| module |           name                |        type         |
|--------|-------------------------------|---------------------|
|  test  |        current_user           | aws_caller_identity |
|   -    | dynamodb-terraform-state-lock |  aws_dynamodb_table |

View filtered table of resources for a tfstate located in the file system in the directory:

 tflens --filter-name "current"

|   provider   |        type         |   mode  |           name                | module |
|--------------|---------------------|---------|-------------------------------|--------|
| provider.aws | aws_caller_identity |   data  |        current_user           |  test  |

Or:

 tflens --filter-module "test"

|   provider   |        type         |   mode  |           name                | module |
|--------------|---------------------|---------|-------------------------------|--------|
| provider.aws | aws_caller_identity |   data  |        current_user           |  test  |

Or:

 tflens --filter-name "current" --filter-module "test"

|   provider   |        type         |   mode  |           name                | module |
|--------------|---------------------|---------|-------------------------------|--------|
| provider.aws | aws_caller_identity |   data  |        current_user           |  test  |

View table of resources for a tfstate located in the file system in the dev/terraform.tfstate.json path:

 tflens --file-location dev/terraform.tfstate.json

|   provider   |        type         |   mode  |           name                | module |
|--------------|---------------------|---------|-------------------------------|--------|
| provider.aws | aws_caller_identity |   data  |        current_user           |  test  |
| provider.aws |  aws_dynamodb_table | managed | dynamodb-terraform-state-lock |   -    |

Create markdown file with table of resources for a tfstate located in the file system in the directory:

 tflens --output markdown

View table of resources for a tfstate located in a S3 bucket called tflens-test-tfstate-bucket:

 tflens --file-location tflens-test-tfstate-bucket/common/terraform.tfstate --remote s3

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

tflens-1.5.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

tflens-1.5.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file tflens-1.5.0.tar.gz.

File metadata

  • Download URL: tflens-1.5.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for tflens-1.5.0.tar.gz
Algorithm Hash digest
SHA256 654b64f88171a7f27c1dcd5431fed479b8a3b93ee6f5f4cf0b2fdb8c33c349b0
MD5 77d7bdb54e9d3721f55c59b65c0420fa
BLAKE2b-256 41a42d7d7434d4847919f2369322f4e908e17e99d66121f9494d8d4feb8999cc

See more details on using hashes here.

File details

Details for the file tflens-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: tflens-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for tflens-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a3f74e0b7a4ada7e8865627e6232b36e80ce5c0fdbbbc5e2a7989de316a3507
MD5 9731b0a59dc5ed6a30fd3cefc0f3e43d
BLAKE2b-256 b745e03fbe43f5e37f417ea905599d68d5499c397a896193b9bc2ae5b4525191

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