Skip to main content

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. Install it with pip for python3.

pip3 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. From the client base-level you can also create/destroy/list organizations:

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

# Base level Methods:
#organizations = client.list_organizations()
#client.destroy_organization(name='my-safe-to-delete-org')
#client.create_organization(name='test', email='test@test.com')

This organization object org has access to workspaces, 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')

You can access workspace objects through your organization client object, which gives you access to runs, plans, statefiles, ssh-key additions and variables.

# Get a single workspace client object, 
# you can also list or search all workspace objects using the corresponding methods.
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)

# Update workspace, arguments identical to create function. Omit arguments to not alter.
workspace.update(auto_apply=True)

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


# Apply latest unconfirmed plan in workspace. You can additionally print all attributes by print object at top level.
# or use other runs methods i.e. cancel, discard and get plan output etc.
for run in workspace.list_runs(page=1, page_size=20):
    if run.status == 'planned':
        run.apply(comment='Running latest plan.')

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

Metadata

Release files for pyterprise 0.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyterprise 0.0.15
File Size Uploaded Provenance Actions
pyterprise-0.0.15.tar.gz 10.7 kB Without provenance Details for pyterprise-0.0.15.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyterprise 0.0.15
File Interpreter ABI Platform Actions
pyterprise-0.0.15-py3-none-any.whl Python 3 none any Details for pyterprise-0.0.15-py3-none-any.whl

Total release size: 22.6 kB

Release files / pyterprise-0.0.15.tar.gz

Download URL pyterprise-0.0.15.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cc789a8920a12cc5f4970f57dc50aacec1c8246da099b55c9e3dbed3d5760fc7
BLAKE2b-256 checksum
How to use checksums
42442d2930d7c99b1c7418449ab49fbcf9e18adb232681de800280dcab4c7da6
Upload date
Uploaded using Trusted Publishing?
What is 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.3

Release files / pyterprise-0.0.15-py3-none-any.whl

Download URL pyterprise-0.0.15-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51dad547c177e57b86f12b18b48f0ec295c1d03065f8fff31e8a909f4cf56a66
BLAKE2b-256 checksum
How to use checksums
c346997a54e165f7f31e69f7069031acbb590273f7a2a9ed105cb2eea5d7b539
Upload date
Uploaded using Trusted Publishing?
What is 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.3

Security for pyterprise 0.0.15

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page