Skip to main content

Get Terraform Workspace and Run usage statistics.

Project description

Overview

A Python module to call the Terraform Cloud API and retrieve data for total and applied Runs of Workspaces.

Usage

Installation:

pip3 install terraform_usage
# or
python3 -m pip install terraform_usage

Usage instructions are in the script built-in help document. Run the following to see options and default parameters.

Bash:

python </oath/to>/terraform_usage -h

Python:

import terraform_usage as tfu
help(tfu)

Execution example:

python </path/to>/terraform_usage -o abdahmad -t $TFE_TOKEN -k "*abdahmad-*" -m advanced -f abdahmad.csv -s 2023-11-01 -e 2023-11-30

Run parameters:
Organization: abdahmad
Keyword: *abdahmad-*
Filename: abdahmad.csv
Start date: 2023-11-01
End date: 2023-11-30
Mode: advanced
API URL: https://app.terraform.io/api/v2
Page size: 50
Delay: 1.0
-------
Getting page 1 of Workspaces.
Found 3 Workspaces.
Getting Run data for Workspace ids-aws-abdahmad-dev.
Getting page 1 of Runs.
Getting Run data for Workspace ids-aws-abdahmad-prod.
Getting page 1 of Runs.
Getting Run data for Workspace ids-aws-abdahmad-test.
Getting page 1 of Runs.
Creating CSV file abdahmad.csv.
Writing data to abdahmad.csv.

Output in CSV file example:

workspace,all_runs,successful_applies,total_time
abdahmad-dev,4,0,53
abdahmad-prod,0,0,0
abdahmad-test,0,0,0

Execution Modes

  • basic
    • Function
      • Get total number of Runs and successful Applies for all time.

    • Available filters
      • Workspace name pattern

    • Pros and cons
      • Faster execution

      • Less details

  • advanced
    • Function
      • Get total number of Runs, successful Applies, and total Run time.

    • Available filters
      • Workspace name pattern

      • Start date

      • End date

    • Pros and cons
      • Potentially slower execution for a large number of Workspaces and Runs.

      • More details

Error Handling

  • Error: Skipping run due to missing attribute(s).
    • A Run is missing a timestamp for a status. Normally caused by Runs stuck in Pending state, which should be discarded if they aren’t meant to complete, successfully or otherwise.

  • Error: One or more Python exceptions.
    • Multiple possible causes. One of the most common is due to the script hitting the Terraform Cloud API rate limit (30 requests per second). There is a safeguard that slows down execution to avoid this.

API Documentation

https://developer.hashicorp.com/terraform/cloud-docs/api-docs

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

terraform_usage-2.1.6.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

terraform_usage-2.1.6-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file terraform_usage-2.1.6.tar.gz.

File metadata

  • Download URL: terraform_usage-2.1.6.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/6.2.0-1016-azure

File hashes

Hashes for terraform_usage-2.1.6.tar.gz
Algorithm Hash digest
SHA256 7c888cd709d73bf45652736e667ec721862a8dbf72b0fc16d0df99ab6d542ccb
MD5 7b79255962b9603fd3dc239afb32e5e8
BLAKE2b-256 f208bc0fb3df14e91753e2e5ad8c827cdb689a0eeba8201d22e0d710e3f9b662

See more details on using hashes here.

File details

Details for the file terraform_usage-2.1.6-py3-none-any.whl.

File metadata

  • Download URL: terraform_usage-2.1.6-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/6.2.0-1016-azure

File hashes

Hashes for terraform_usage-2.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b278ed66dfe16e1983633c914d9c52b811c8625d05c0b5720ad9c877a8e2727b
MD5 847a0d7016a012a390ba3ab8a30aed79
BLAKE2b-256 994a790578be0959ca6f5944b320d7a0562d9387e02d6e2a424cae5127afcc45

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page