Skip to main content

A small client library for the Terraform Enterprise REST API.

Project description

Pyterprise

This is a very simple Python Client Library for Terraform Enterprise with helper functions to abstract usage of the HTTP API and handle errors in a normalized fashion. The methods included in this library generally map 1 to 1 in terms of function naming conventions to terraform enterprise documentation, so please review the available methods if you are uncertain on this library's usage.

Installation:

This module can be installed via pip3, this library is compatible and can used be with python2 but is not available through PyPa for 2.7 versions.

pip3 install --user pyterprise

Usage:

First import the module and authenticate using the init method, you can retrieve a token from the terraform enterprise UI.

import pyterprise


tfe_token = 'TOKENHERE'
client = pyterprise.Client()

# Supply your token as a parameter and the url for the terraform enterprise server.
client.init(token=tfe_token, url='https://example-host.com')

Once initialized, you should be able to run various methods for accessing the API, most of the methods are basic python implementations of http requests that will simply return the json response content as a string.

Examples:

# Get all most recent workspace statefiles to stdout.
workspaces = client.list_workspace_ids('awesome-organization')
for workspace in workspaces:
    print(client.get_workspace_current_statefile(workspace_id=workspace))

# Create a workspace.
client.create_workspace(organization='test-org', workspace_name='test-workspace')

# Update Workspace: Include any params to update, exclude any to not change.
update_params = {
    "name": "test-workspace",
    "terraform_version": "0.12.1",
    "working-directory": "test/awesome-directory",
    "vcs-repo": {
        "identifier": "github/Terraform-Testing",
        "branch": "test",
        "ingress-submodules": False,
        "oauth-token-id": "ot-XXXXXXXXX"
        }
    }
client.update_workspace(organization='test-org', update_params=update_params)


# Set a workspace environmental variable in a given workspace id.
client.create_workspace_variable('test-workspace', key='TF_LOG', value='DEBUG')

# Remove the created and modified workspace.
client.delete_workspace(organization='test-org', workspace_name='test-workspace')

Please consult module contents or terraform enterprise api documentation for available methods most should be covered within this module and should have near identical function names compared to the REST documentation.

API Coverage/Helper Methods

Workspaces
  • list workspaces
  • create workspace
  • delete workspace
  • list workspace ids
  • get workspace non confirmed runs
  • get workspace current statefile
  • show workspace
  • update workspace
Runs
  • apply terraform run
  • force execute run
  • run terraform workspace (destroy option included)
  • get workspace runs
  • discard run
  • cancel runs
Teams
  • show user
  • get teams
  • create team
  • show team information
  • delete team
Variables
  • create workspace variable
  • list variables
  • delete workspace variable
Other
  • get terraform plan
  • list organizations
  • show organization
  • update organization
  • destroy organization
  • create organization

Contributions

Contributions are extremely appreciated! Please feel free to do so to improve this client library. I created this library as at the time there was not a simple python library for performing basic administrative tasks in Terraform Enterprise.

Disclaimer: This Client Library is considered in an 'alpha' state at this time as unit-testing is yet to be implemented. Please use at your own risk

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

pyterprise-0.0.9.tar.gz (7.0 kB view hashes)

Uploaded Source

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