Coder Social home page Coder Social logo

skierkowski / terraform-enterprise-client Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 3.0 144 KB

Terraform Enterprise API Ruby Client and Command Line tool

License: Mozilla Public License 2.0

Ruby 100.00%
terraform hashicorp hashicorp-terraform terraform-enterprise ruby rubygem

terraform-enterprise-client's Introduction

Terraform Enterprise API Client

A simple Ruby API client library for the Terraform Enterprise API.

Gem Version Maintainability Test Coverage Inline docs

NOTE: The command line tool has moved to skierkowski/terraform-enterprise-cli.

Requirements

MRI Ruby 2.3 and newer are supported. Alternative interpreters compatible with 2.3+ should work as well.

This gem depends on these other gems for usage at runtime:

API Client

Usage

Basic Example

require 'terraform-enterprise-client'

token = ENV['TFE_TOKEN']
client = TerraformEnterprise::API::Client.new(token: token)

# Create a new organization
org = client.organizations.create(name:'my-org',email:'[email protected]')

# Create a new workspace in the new organization.
# Uses the same parameters as the following docs:
# https://www.terraform.io/docs/enterprise/api/workspaces.html
client.workspaces.create(name:'my-new-workspace', organization:'my-org')

# Delete the workspace
client.workspaces.delete(name:'my-new-workspace', organization: 'my-org')

# Delete the organization now that we are done
client.organizations.delete(name:'my-org')

Configuration

There are two main settings that can be modified on initialization:

  • :token (required) - which specifies the API key (formerly called ATLAS_TOKEN)
  • :host - a hostname other than the default (app.terraform.io) for usage with private installs

terraform-enterprise-client's People

Contributors

skierkowski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

terraform-enterprise-client's Issues

Document contribution / running locally

Document how devs can contribution and run the CLI locally.

Topics that need to be covered include:

  • Use bundle exec ./bin/tfe instead of just ./bin/tfe
  • Call out the design principle of the CLI:
    • Parameters for required and resource-specific attributes
    • Options for setting context (e.g. organization when creating workspaces)
    • Options for optional parameters

import-repo option should be import-legacy-environment

 tfe workspaces help create
Usage:
  tfe workspaces create <name>

Options:
  [--terraform-version=TERRAFORM_VERSION]            # Version of Terraform to use for this workspace.
  [--working-directory=WORKING_DIRECTORY]            # Relative path that Terraform will execute within.
  [--oauth-token=OAUTH_TOKEN]                        # VCS Connection (OAuth Conection + Token) to use as identified; obtained from the oauth_tokens subcommand.
  [--branch=BRANCH]                                  # Repository branch that Terraform will execute from.
  [--ingress-submodules], [--no-ingress-submodules]  # Submodules should be fetched when cloning the VCS repository.
  [--repo=REPO]                                      # Reference to VCS repository in the format :org/:repo
  [--import-repo=IMPORT_REPO]                        #
  [--color], [--no-color]
                                                     # Default: true
  [--host=HOST]                                      # Hostname of private Terraform Enterprise
  [--token=TOKEN]                                    # Access token
  --organization=ORGANIZATION                        # Organization name

Add `variables load` subcommand

Currently loading the variables in a TFE workspace requires setting it through the UI or API one-by-one. While it does support loading of *.auto.tfvars, it would be ideal (per customer requests) to add support for setting all the values from a tfvars file.

example:
tfe variables load my-prod-workspace --tf-vars ./prod.tfvars --organization my-org

Add TFE_* env vars for default values

Problem: There are a lot of fields that are set as options on the command line but are likely to be reused frequently.

Solution: Provide environment variables to set default values for the options. So each option should first accept the field provided in the option and if one is not provided look up the TFE_ value from the environment variables.

Example: The --token option is used to set the token, but you can also set it using TERRAFORM_ENTERPRISE_TOKEN.

Add `plan` and `apply` subcommands

Background: Terraform Enterprise (Atlas) Legacy had integration with terraform open source for the command terraform push which packaged the local terraform configuration and pushed it to a workspace. Terraform Enterprise (Legacy and new) also both support integration for terraform plan and terraform apply but the configuration runs locally in the local context and only uploads the state after it is complete (without locking).

Goal: The goal of this feature is to provide the same user experience as terraform plan and terraform apply but the configuration gets executed in TFE not locally and also pushes the local configuration if provided.

Design: TBD

CLI: Improve output formatting

Problems:

  • Table of data shows a detailed list (YAML) and it is too much data
  • Requires string parsing to get individual values (e.g. id on create)

Changes:

  • Lists should be returned as tables by default
  • Add --details option to show ALL of the data
  • By default only the attributes of the body will be shown
  • Add support to #render to exclude parts of what gets rendered (e.g. workspaces shouldn't show the permissions attribute), so the render method should accept exclude: [:permissions]
  • (#2) add a --value option to display only the id value (or other field)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.