Skip to main content

A small client library for the Terraform Enterprise REST API.

Project description

Pyterprise

This is an object oriented client API for Terraform Enterprise written in Python. 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.

Happy Terraforming!

Installation:

This module can be installed via pip, this library is compatible with python3.7.

pip install --user pyterprise

Usage:

Note: Some examples are covered here, but more are covered in the /examples directory for more basic use-cases of this api.

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.
# If you are not self hosting, use the one provided by hashicorp.
client.init(token=tfe_token, url='https://example-host.com')

After instantiating your client you need to set an organization to access workspaces and more:

# Set the organization
org = client.set_organization(id='my-organization')

This organization object has access to workspace, ssh keys and other methods (Check source code/examples for more):

# Creating a workspace with VCS example:
vcs_options = {
    "identifier": "my-github-org/my-repo",
    "oauth-token-id": "ot-xxxxxxxxxxx",
    "branch": "master",
    "default-branch": False
}
org.create_workspace(name='test-delete-me2',
                     vcs_repo=vcs_options,
                     auto_apply=False,
                     queue_all_runs=False,
                     working_directory='/',
                     trigger_prefixes=['/'])

# Or Delete a workspace at the organization level by name.
org.delete_workspace(name='my-safe-to-delete-test-workspace')

Accessing workspaces through your organization client object:

# Get a single workspace client object, you can also list all workspace objects
workspace = org.get_workspace('test-workspace')

# Get a list of all workspace objects in an organization.
for workspace in org.list_workspaces():
    print(workspace)

# Print some workspace attributes. Additionally you can access all attributes 
# as a dictionary by printing  the 'workspace' object at top level.                     
print(workspace.name, workspace.id, workspace.created_at)

# Run Workspace, you can destroy by changing the destroy flag.
workspace.run(destroy_flag=False)

# Plan and Apply in workspace with log output
workspace.plan_apply(destroy_flag=False)

# Create a variable in a workspace
workspace.create_variable(key='foo', value='bar', sensitive=False, category='env')

# Print all variables for a workspace. 
# Variables objects also have functions for updating and deleting.
for variable in workspace.list_variables():
    print(variable)

# Print all runs, there are methods for canceling, applying 
# run and more in the returned run objects.
for run in workspace.list_runs():
    print(run)

Please consult module contents, examples or terraform enterprise api documentation for more api client usage. This API does not currently cover administrative functions and teams, help is wanted for expanding functionality. Thank you.

API Coverage/Helper Methods

Workspaces
  • Method Coverage Complete.
Runs
  • Method Coverage Complete
Plans
  • Method Coverage Complete
Organization
  • Method Coverage Complete
SSH-Keys
  • Method Coverage Complete
Variables
  • Method Coverage Complete

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

Uploaded Source

Built Distribution

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

pyterprise-0.0.12-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file pyterprise-0.0.12.tar.gz.

File metadata

  • Download URL: pyterprise-0.0.12.tar.gz
  • Upload date:
  • Size: 9.9 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.0.1 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

File hashes

Hashes for pyterprise-0.0.12.tar.gz
Algorithm Hash digest
SHA256 c779495255429498dfd60c208860265d2d9c54e2729b48a9dbc3b9351b81eee2
MD5 acb2cb8f317fe7e76f0d9aa3abbf3937
BLAKE2b-256 b5ddbda3672b303deea8ece9c1f8303a2ddfa88936363fb0028eda86cce15632

See more details on using hashes here.

File details

Details for the file pyterprise-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: pyterprise-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 11.4 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.0.1 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

File hashes

Hashes for pyterprise-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 50a45049e74306dc64616d4d0a9e5d55eeb8921eb2e322a133c3763e340440c2
MD5 c5adcb59dc32c65dba72d66b1e4ae22f
BLAKE2b-256 9ea07c0e3d8518c7cae97f9979fe72158ead781c887ee654d6ab2bda9aa09e2a

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