Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 25, 2024. It is now read-only.

Terraform Enterprise Python Client Library

License

NotificationsYou must be signed in to change notification settings

JFryy/terraform-enterprise-api-python-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DownloadsPyPI version

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 toterraform enterprise documentation, so please review the available methodsif you are uncertain on this library's usage.

Although this client library is maintained to a degree, I am not actively improving it. Please feel free to use this if it meets your needs, however if certain endpoints you need aren't covered here, or if upstream changes break any functionality, Iheavily suggest using the officially maintained go library fortfe by Hashicorp or an alternative python libraryterrasnek which is actively maintained to a higher standard of quality than I have the bandwith to provide.

Happy Terraforming!

Installation:

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

pip3 install --user pyterprise

Usage:

Note: Some examples are covered here, but more are covered in theexamples 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.

importpyterprisetfe_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 organizationorg=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 objectorg 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.forworkspaceinorg.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 outputworkspace.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 workspaceworkspace.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.forvariableinworkspace.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.forruninworkspace.list_runs(page=1,page_size=20):ifrun.status=='planned':run.apply(comment='Running latest plan.')

Please consult module contents,examplesorterraform enterprise api documentationfor 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

  • Method Coverage Complete.
  • Method Coverage Complete
  • Method Coverage Complete
  • Method Coverage Complete
  • Method Coverage Complete
  • Method Coverage Complete

About

Terraform Enterprise Python Client Library

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp