Skip to main content

A client for HashiCorp Terraform Cloud

Project description

Terraform Cloud Client

An API client for HashiCorp's Terraform Cloud

Installation

$ pip install terraform-cloud-client

This client is only tested on python 3.7

Usage as a library

Set up:

>>> import tfc
>>> client = tfc.TerraformClient("my_api_token", "my_organization", "my_workspace")

Get Terraform variables:

>>> variables = client.get_variables()
>>> variables
{
    'my_username': <TerraformVariable id='var-someid1', name='my_username', value='john_doe'>,
    'my_password': <TerraformVariable id='var-someid2', name='my_password', sensitive>,
}
>>> username_variable = variables['my_username']
>>> username_variable.id
'var-someid1'
>>> username_variable.name
'my_username'
>>> username_variable.value
'john_doe'

Change the value of a variable:

>>> client.update_variable(variable_id=username_variable.id, new_value='jane_doe')

Trigger a run:

>>> run = client.create_run('My message')
>>> run.id
'run-someid'
>>> run.url # Go here in a web browser to view the run
'https://app.terraform.io/app/my_organization/workspaces/my_workspace/runs/run-someid'

Usage as a command line tool

Installing this via pip also installs a tfc command line tool

$ tfc --help
usage: tfc [-h] [--message MESSAGE]
           organization workspace [name=value [name=value ...]]

Trigger a Terraform Cloud run

positional arguments:
  organization          The name of your organization in Terraform Cloud
  workspace             The name of your workspace in Terraform Cloud
  name=value            Set terraform variable NAME to VALUE before creating
                        the run

optional arguments:
  -h, --help            show this help message and exit
  --message MESSAGE, -m MESSAGE
                        The message to be associated with this run

Put your API token in the TERRAFORM_CLOUD_TOKEN environment variable

So for example:

$ tfc my_organization my_workspace foo=baz --message="Reticulating splines"
Updated 'foo' from 'bar' to 'baz'
Created run run-g6SmSsLVKg71yeNw - check status at: https://app.terraform.io/app/my_organization/workspaces/my_workspace/runs/run-g6SmSsLVKg71yeNw

The message argument can contain variables which are expanded at runtime. These follow the same formatting rules as Python's str.format(...). The variables which are currently defined are:

  • git_repository
  • git_branch
  • git_commit_subject
  • git_commit_author

So for example:

$ tfc my_organization my_workspace foo=baz --message="{git_commit_subject} (author: {git_commit_author}, branch: {git_branch}, repo: {git_repository})"

might create a run with the message:

My commit message (author: Joe Bloggs, branch: my-branch, repo: terraform-cloud-client)

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-cloud-client-0.0.3.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

terraform_cloud_client-0.0.3-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file terraform-cloud-client-0.0.3.tar.gz.

File metadata

  • Download URL: terraform-cloud-client-0.0.3.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for terraform-cloud-client-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c0094ba1befcb874a811a413359bacb01b227bc80169da59572e21298be9b835
MD5 0f2df2927628db95972ea0cec8c90f45
BLAKE2b-256 e4e825851569c58dc2e95d73b3c266e7e67a921e28a5e2d6a603a116c25b9474

See more details on using hashes here.

File details

Details for the file terraform_cloud_client-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: terraform_cloud_client-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for terraform_cloud_client-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ab171a2112e1be94bba36816a2be40e3c49246b05fe57b90f9c3974a8e76ddab
MD5 a0b36df0552db2f0dcbe5a396553597e
BLAKE2b-256 3cce32e8cc98e9f94531448ff6183bafa2d4ef887aa3b1afaf814fb64af6f3dc

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