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]

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) 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

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.2.0.tar.gz (9.2 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.2.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tflens-1.2.0.tar.gz
  • Upload date:
  • Size: 9.2 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.2.0.tar.gz
Algorithm Hash digest
SHA256 b0117cbc4dc51ca78f49dc0a7933c6c3f71e3806a0bca6af0a1429754aa914ce
MD5 23397d7c9a18f4bc604854389f79fd27
BLAKE2b-256 26ff6459a49f862aa269b56d856903ffbb321dbffa61ac7231183d2b54abbb03

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tflens-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ae98bd8eb0c4fc1dac05c272e92e408f8907a8ae944a29cc5ef9ecf51169db6
MD5 d70828f98df3c738c8670600d31ba731
BLAKE2b-256 610cf879cac95839c2ea29b67f4d436b2a8c108dd13ac2b305662d74c307ad51

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