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.5

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
  -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 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.3.0.tar.gz (10.0 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.3.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tflens-1.3.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for tflens-1.3.0.tar.gz
Algorithm Hash digest
SHA256 a985110f2dbdd5a27171de16734e1c109419e632e1daf8915ad963dacd999efb
MD5 3e09b2ffea07c351f6f255320c5fd2cb
BLAKE2b-256 bce26396cc78f26a8bd57fa4b0e49b9b04fe16fb8870b47a07f669c519abd184

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tflens-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for tflens-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b16c7c6062b9c1090688cd07b8c1866a088eba007f02e4355722412889abf103
MD5 693ed1935a197abf7a0ba8459ea2ad04
BLAKE2b-256 566c56c92bdc1feb59b411da55694ab4633e93065a70c33950dd551d5319e745

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