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

Uploaded Source

Built Distribution

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

Uploaded Python 3

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