Skip to main content

HashiCorp Terraform Cloud API client

Project description

CircleCI

Noos Energy Terraform Client

A Python client wrapping up HashiCorp's Terraform Cloud API.

Installation

Package available from the PyPi repository:

$ pip install noos-tf

Usage as a library

Import the namespace within your project,

import os
import noos_tf

# Instantiate client
tf_client = noos_tf.TerraformClient()

# Authenticate client
tf_client.set_auth_header(token=os.getenv("TERRAFORM_TOKEN"))

Then query directly from the Terraform Cloud API ; as a example:

  • a workspace ID:
tf_client.get_workspace_id("myOrganisation", "myWorkspace")
  • the variable IDs from a given workspace:
tf_client.get_variable_ids("myOrganisation", "myWorkspace")

The library offers as well some helper functions for more involved workflows, such as:

  • updating a variable value:
noos_tf.update_workspace_variable(
    "myOrganisation",
    "myWorkspace",
    os.getenv("TERRAFORM_TOKEN"),
    "myVariable",
    "new_value",
)
  • running and applying a plan:
noos_tf.run_workspace_plan(
    "myOrganisation",
    "myWorkspace",
    os.getenv("TERRAFORM_TOKEN"),
    "Test run",
)

Usage as a command line tool

The above helper functions could be accessed directly from the command line.

$ noostf

Usage: noostf [--core-opts] <subcommand> [--subcommand-opts] ...

Subcommands:

  run      Run a plan in Terraform cloud.
  update   Update variable in Terraform cloud.

Development

On Mac OSX, make sure poetry has been installed and pre-configured,

$ brew install poetry

This project is shipped with a Makefile, which is ready to do basic common tasks.

$ make

help                           Display this auto-generated help message
update                         Lock and install build dependencies
clean                          Clean project from temp files / dirs
format                         Run auto-formatting linters
install                        Install build dependencies from lock file
lint                           Run python linters
test                           Run pytest with all tests
package                        Build project wheel distribution
release                        Publish wheel distribution to PyPi

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

noos_tf-0.0.9.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

noos_tf-0.0.9-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file noos_tf-0.0.9.tar.gz.

File metadata

  • Download URL: noos_tf-0.0.9.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.8 Linux/5.15.0-1057-aws

File hashes

Hashes for noos_tf-0.0.9.tar.gz
Algorithm Hash digest
SHA256 7d811e296b91243c1e4060d06e6b388275ee98da424fd741b6cf76b1a5b9deda
MD5 a03ee3ddec518111a2c63d20ca99c878
BLAKE2b-256 0df555bbe58469cd4d5cac2031d5d27b8d8742e7e33d527a588fbc3f9ab5ffb7

See more details on using hashes here.

File details

Details for the file noos_tf-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: noos_tf-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.8 Linux/5.15.0-1057-aws

File hashes

Hashes for noos_tf-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 41b6decd4a1418da4ff32a950f16045376e68732a478c71e6667f9bc1f3392fe
MD5 98b6614673be65b17708dc344ec1e061
BLAKE2b-256 117da4425a4388f272003e98285195050b14098d809fcd3e7878a531a3a16c3f

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