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.8.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: noos_tf-0.0.8.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1039-aws

File hashes

Hashes for noos_tf-0.0.8.tar.gz
Algorithm Hash digest
SHA256 238d6eb9faedbec98ee420af1f6bd3efeba508545855ee2bd80b3a7a8fc6dd09
MD5 9ba26e7d314d4c2add17acae32a1ac90
BLAKE2b-256 780ed3055eec1328fb197ca065c69dc12d3001712528b631c2882ccd9dba55aa

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for noos_tf-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 901cc2e5ae7a71a0807ebd87ff99cda6cc3b5aa20384f03bc414c872bc37caf9
MD5 48d0cb1d9a6f1680e98f69909e037b8f
BLAKE2b-256 dc92d477f013d7195794eb0d29a0ad5bf04c2dedfb438a880c11439f8c57b56c

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