`tfx` is a standalone CLI for Terraform Cloud and Terraform Enterprise.

Related tags

Command Line tfx
Overview

TFx CLI

tfx is a standalone CLI for Terraform Cloud and Terraform Enterprise.

The initial focus of tfx is to execute the API-Driven workflow for a Workspace, but will expand to other common workflows that, in the past, have required API wrappers.

Note: This CLI is still under active development, subject to change, and not officially supported by HashiCorp.

main Go Version

Why does this CLI exist?

As a consumer of TFC/TFE I want to leverage the full capabilities without having to write curl/python/(insert other) libraries to call the API. Often times these tasks are part of my pipeline, but could also be administrative tasks that are done from a local machine.

Common API-Driven Workflow Challenges:

  • The CLI-Driven workflow presents several gaps in creating more advanced pipelines a Workspace run, specifically the inability to insert a gate check between a plan and apply, (in other words you must run a terraform apply -auto-approve).
  • The CLI driven workflow requires a terraform init that forces a download of providers before a plan can be called remotely, these providers are never actually used on the local host and can be difficult to source in airgap environments.
  • Implementing an API-Driven workflow requires several API calls to perform a plan/apply.
  • It is unlikely that the full range of features will be built into Terraform.
  • Developing CI/CD specific plugins for even the most common tools is not feasible, and ignores the ability to run the commands locally.

Terminal Example Plan

Installation

Binaries are created as part of release, check out the Release Page for the latest release.

MacOs Installation

version="0.0.1-dev"
curl -L -o tfx "https://github.com/straubt1/tfx/releases/download/${version}/tfx_darwin_amd64"
chmod +x tfx

Linux Installation

version="0.0.1-dev"
curl -L -o tfx "https://github.com/straubt1/tfx/releases/download/${version}/tfx_linux_amd64"
chmod +x tfx

Windows Installation

version="0.0.1-dev"
curl -L -o tfx.exe "https://github.com/straubt1/tfx/releases/download/${version}/tfx_windows_amd64"

Usage

Each command has the ability to pass in parameters via flags, several are required for every command.

Example:

  --tfeHostname string       The hostname of TFE without the schema (defaults to TFE app.terraform.io). (default "app.terraform.io")
  --tfeOrganization string   The name of the TFx Organization.
  --tfeToken string          The API token used to authenticate to TFx.

Flags can also be created in a configuration file with the file name ".tfx.hcl". For convenience this file will automatically load if it is in the hosts home directory or current working directory.

Example: ./.tfx.hcl

tfeHostname     = "tfe.rocks" (omit to default to TFC)
tfeOrganization = "my-awesome-org"
tfeToken        = "<Generated from TFx>"

You can also specify this file via the --config flag.

Workspace Run Workflow

Create a Plan

# Create a speculative plan that can not be applied
tfx plan -w tfx-test -s

# Create a plan that can be applied
tfx plan -w tfx-test

# Create a Configuration Version based on terraform in the current directory
tfx cv create -w tfx-test

# Create a Configuration Version based on terraform in a supplied directory
tfx cv create -w tfx-test -d ./myterraformfolder/

# Create a plan based on a configuration version
tfx plan -w tfx-test -i cv-HKE8gevVtGBXapcq

Create an Apply

tfx apply -r <run-id>

Commands

tfx plan

Create a plan to execute on TFx.

tfx plan - Create a Workspace plan based on a current directory

tfx apply

Create an apply to execute on TFx.

tfx apply - Apply a Workspace plan based on a plan

tfx run

Managing Workspace Runs.

tfx run list - List all Runs for a supplied Workspace

tfx run create - Create a Run for a supplied Workspace

tfx run show - Show Run details for a supplied Run

tfx cv

Managing Workspace Configuration Versions.

tfx cv list - List all Configuration Versions for a supplied Workspace

tfx cv create - Create a Configuration Version for a supplied Workspace

tfx cv show - Show Configuration Version details for a supplied Configuration

tfx pmr

Managing Private Module Registry modules.

tfx pmr list - List all modules in the PMR

tfx pmr create - Create a module in the PMR

tfx pmr create version - Create a version of a module in the PMR

tfx pmr show - Show module details for a supplied module

tfx pmr show versions - Show modules versions for a supplied module

tfx pmr delete - Delete a module from the PMR

tfx pmr delete version - Delete a specific module version from the PMR

tfx pmr download - Download a specific module version of TF code

tfx state

Managing Workspace State Files (State Versions).

tfx state list - List all State Versions for a supplied Workspace

tfx state show - Show state details for a supplied State Version

tfx state download - Download a specific State Version

tfx state create - Create a new State Version with a supplied state file

  • There is no way to delete State Versions
  • The LAST State Version to be created is the "current" state file that will be used by the Workspace
  • A Workspace must be locked to create new State Versions
  • The "serial" attribute must be incremented
  • The "lineage" attribute must be the same for any newly created State Version
  • The API does not return a state versions lineage, you must download the file and parse to get the lineage

tfx tfv

Managing Terraform Versions in a Terraform Enterprise install (TFE only).

tfx tfv list - List all Terraform Versions for a TFE install

tfx tfv show - Show version details for a supplied Terraform Version or Version Id

tfx tfv delete - Delete a version of a supplied Terraform Version or Version Id

tfx tfv create - Create a Terraform Version

tfx tfv create official - Create an official Terraform Version from releases.hashicorp.com

tfx tfv disable - Disable a Terraform Version(s), accepts comma separated list

tfx tfv disable all - Disable all Terraform Versions

tfx tfv enable - Enables a Terraform Version(s), accepts comma separated list

tfx tfv enable all - Enables all Terraform Versions

Potential Future Commands

Additional commands to implement.

Contributing

Thank you for your interest in contributing!

Contributing guide coming soon

References

https://github.com/hashicorp/go-tfe

https://github.com/spf13/cobra#installing

https://mholt.github.io/json-to-go/

Issues
  • Global configuration from environment variables

    Global configuration from environment variables

    Feature Request

    Currently tfx only supports CLI flags or an HCL file for setting global configuration values. It would be useful, especially in pipelines, to be able to inject these values at the environment level.

    I suggest TFE_TOKEN and TFE_HOSTNAME, which are inline with the tfe provider. TFE_ORGANIZATION seems like an obvious extension.

    enhancement 
    opened by grahame-murray-db 2
  • Feature request : Enable json output for valid structures

    Feature request : Enable json output for valid structures

    Expected Behaviour

    it would be nice to be able to run tfx with a -j, --json flag so that such output is created in a machine readable format i.e

    ❯ ./tfx workspace list --tfeToken $TFE_TOKEN --tfeOrganization $TFE_ORG
    Reading Workspaces for Organization: abc-hashi-training
    Reading Workspaces for Organization: abc-hashi-training with workspace search string: api
    ╭────────────────────┬─────────────────────┬─────────────────────┬─────────┬────────╮
    │ NAME               │ ID                  │ CURRENT RUN CREATED │ STATUS  │ LOCKED │
    ├────────────────────┼─────────────────────┼─────────────────────┼─────────┼────────┤
    │ test-api-workspace │ ws-rHrABtQnmNCMqBaT │ 2021-11-11 20:59:35 │ applied │ false  │
    ╰────────────────────┴─────────────────────┴─────────────────────┴─────────┴────────╯
    Workspaces Found: 1 with workspace search string: api
    
    

    would be output as json of the api raw output, this then lets you do chained queries and repeatable actions.

    opened by abuxton 1
  • Add Replicated and TFE airgap download capability

    Add Replicated and TFE airgap download capability

    Perform functionality similar to this gist: https://gist.github.com/straubt1/f7f5c48c85d444bccdfadce47919f916

    • Download Replicated Version
    • List Replicated Versions
    • Download TFE Airgap Version
    • List TFE Versions
    enhancement 
    opened by straubt1 1
  • Customizable Run Message

    Customizable Run Message

    Feature Request

    Allow a run message to be passed as an argument to tfx run create, and I suppose tfx plan create? Credit where credit is due, but TFx was here is not all that helpful 😉 Perhaps -m, --message string?

    enhancement 
    opened by grahame-murray-db 1
  • Get configuration from environment variables

    Get configuration from environment variables

    Feature Request

    Currently tfx only supports CLI flags or an HCL file. It would be useful, especially in pipeline environments, to be able to inject these values at the environment level.

    I suggest TFE_TOKEN and TFE_HOSTNAME, which are inline with the tfe provider.

    opened by grahame-murray-db 1
  • Refactor and JSON outputting

    Refactor and JSON outputting

    All commands will have this option in the future, but for now its just Variable, GPG, and Provider commands.

    Two options:

    $ tfx variable list -w tfx-test
    Using config file: /Users/tstraub/.tfx.hcl
    List Variables for Workspace: tfx-test
    ╭──────────────────────┬───────────┬────────────────┬───────────┬───────┬───────────┬─────────────────────────╮
    │ ID                   │ KEY       │ VALUE          │ SENSITIVE │ HCL   │ CATEGORY  │ DESCRIPTION             │
    ├──────────────────────┼───────────┼────────────────┼───────────┼───────┼───────────┼─────────────────────────┤
    │ var-Ntws2mA8CRCREzkP │ variable4 │ ./string.hcl   │ false     │ true  │ terraform │ I am a string in a file │
    │ var-6ZfJyC9KJG9c1WbE │ variable5 │ ./list.hcl     │ false     │ true  │ terraform │ I am a list in a file   │
    │ var-G8D6Ugrx8MwvTfcL │ variable6 │ ./map.hcl      │ false     │ true  │ terraform │ I am a map in a file    │
    │ var-7XYNuuo4tMjXeXG4 │ variable7 │ {              │ false     │ true  │ terraform │ I am a map in a file    │
    │                      │           │   "a" = "1",   │           │       │           │                         │
    │                      │           │   "b" = "zoo", │           │       │           │                         │
    │                      │           │   "c" = "42"   │           │       │           │                         │
    │                      │           │ }              │           │       │           │                         │
    │ var-MJaLJ7czxKuU48eu │ variable3 │ It is friday   │ false     │ false │ env       │ I am environmental      │
    ╰──────────────────────┴───────────┴────────────────┴───────────┴───────┴───────────┴─────────────────────────╯
    
    $ tfx variable list -w tfx-test --json | jq .
    [
      {
        "Category": "terraform",
        "Description": "I am a string in a file",
        "HCL": true,
        "Id": "var-Ntws2mA8CRCREzkP",
        "Key": "variable4",
        "Sensitive": false,
        "Value": "./string.hcl"
      },
      {
        "Category": "terraform",
        "Description": "I am a list in a file",
        "HCL": true,
        "Id": "var-6ZfJyC9KJG9c1WbE",
        "Key": "variable5",
        "Sensitive": false,
        "Value": "./list.hcl"
      },
      {
        "Category": "terraform",
        "Description": "I am a map in a file",
        "HCL": true,
        "Id": "var-G8D6Ugrx8MwvTfcL",
        "Key": "variable6",
        "Sensitive": false,
        "Value": "./map.hcl"
      },
      {
        "Category": "terraform",
        "Description": "I am a map in a file",
        "HCL": true,
        "Id": "var-7XYNuuo4tMjXeXG4",
        "Key": "variable7",
        "Sensitive": false,
        "Value": "{\n  \"a\" = \"1\",\n  \"b\" = \"zoo\",\n  \"c\" = \"42\"\n}"
      },
      {
        "Category": "env",
        "Description": "I am environmental",
        "HCL": false,
        "Id": "var-MJaLJ7czxKuU48eu",
        "Key": "variable3",
        "Sensitive": false,
        "Value": "It is friday"
      }
    ]
    
    opened by straubt1 0
  • Removed Helper code, added several commands.

    Removed Helper code, added several commands.

    • Removed the helper code for PMR publishing, go-tfe now supports.
    • Added "tfx release" commands for TFE and Replicated release management/download/
    • Added "tfx registry provider" commands for managing Providers in the PMR
    • General refactoring started.
    opened by straubt1 0
  • Add Workspace locking/unlocking all

    Add Workspace locking/unlocking all

    Added

    • tfx workspace lock - Lock a given workspace by name, in a given organization
    • tfx workspace lock all - Lock all workspaces in a given organization
    • tfx workspace unlock - Unlock a given workspace by name, in a given organization
    • tfx workspace unlock all - Unlock all workspaces in a given organization

    Changed

    • tfx workspace commands now sort WS by name
    opened by straubt1 0
  • Workspace and Metrics command

    Workspace and Metrics command

    Fixes #7 and #8.

    • hostname, organization and token can now be set with the respective environment values to align with TFE Provider. (#7)
      • TFE_HOSTNAME
      • TFE_ORGANIZATION
      • TFE_TOKEN
    • Added "message" flag to tfx run and tfx plan commands. (#8)
    • tfx workspace commands
      • list - List all workspaces in an Organization (optional workspace name search string)
      • list all - List all workspaces in All Organizations the API token has access to (optional workspace name search string)
      • show - Show details of a workspace
    • tfx metrics command to pull details about TFx
      • Organization Count
      • Workspace Count
      • Run Count
      • Policy Check Count
      • Policies Pass/Fail Count
    opened by straubt1 0
  • Create state and tf versions commands

    Create state and tf versions commands

    Added

    • tfx plan export command to download sentinel mock data
    • tfx state commands
      • list
      • show
      • download
      • create
    • tfx tfv commands
      • list
      • show
      • create
      • create official
      • delete
      • disable
      • disable all
      • enable
      • enable all
    opened by straubt1 0
Releases(0.0.4-dev)
  • 0.0.4-dev(Jul 17, 2022)

    Major refactor began.

    Added

    New Commands:

    • tfx cv download - Download a Configuration Version and unpack onto disk.
    • tfx gpg list - List GPG Keys of an Organization
    • tfx gpg create - Create a GPG Key for an Organization
    • tfx gpg show - Show details of a GPG Key for an Organization
    • tfx gpg delete - Delete GPG Key for an Organization
    • tfx release tfe list - List available Terraform Enterprise releases
    • tfx release tfe show - Show details of a Terraform Enterprise release, including release notes
    • tfx release tfe download - Download a Terraform Enterprise airgap binary
    • tfx release replicated list - List available Replicated releases
    • tfx release replicated download - Download a Replicated release
    • tfx registry provider list - List Providers in the Registry
    • tfx registry provider version list - List Versions for a Provider in the Registry
    • tfx registry provider version platform list - List Platforms for a Provider Version in the Registry
    • tfx registry provider create - Create a Provider in the Registry
    • tfx registry provider show - Show details of a Provider in the Registry
    • tfx registry provider delete - Delete a Provider in the Registry
    • tfx registry provider version create - Create a Version for a Provider in the Registry
    • tfx registry provider version show - Show details a Version for a Provider in the Registry
    • tfx registry provider version delete - Delete a Version for a Provider in the Registry
    • tfx registry provider version platform create - Create a Platform Version for a Provider in the Registry
    • tfx registry provider version platform show - Show details of a Platform Version for a Provider in the Registry
    • tfx registry provider version platform delete - Delete a Platform Version for a Provider in the Registry
    • tfx variable list - List all workspace variables
    • tfx variable create - Create a workspace variable, optionally the value can read from a filename
    • tfx variable update - Update an existing workspace variable, optionally the value can read from a filename
    • tfx variable show - Show details of a workspace variable
    • tfx variable delete - Delete a workspace variable

    Changed

    • Upgraded to Go 1.18.4
    • PMR Module uploading - Removed helper code (shim) in favor of the now available the go-tfe functions
    • Lots of refactoring within some commands
    • Added optional --json flag framework to allow output to be in JSON for non-interactive use
    • Started the migrating to "github.com/fatih/color" from "github.com/logrusorgru/aurora" for text colors
    Source code(tar.gz)
    Source code(zip)
    tfx_darwin_amd64(17.61 MB)
    tfx_darwin_arm64(17.36 MB)
    tfx_linux_amd64(17.88 MB)
    tfx_windows_amd64(18.00 MB)
  • 0.0.3-dev(Jun 22, 2021)

  • 0.0.2-dev(Jun 21, 2021)

    • hostname, organization and token can now be set with the respective environment values to align with TFE Provider. (#7)
      • TFE_HOSTNAME
      • TFE_ORGANIZATION
      • TFE_TOKEN
    • Added "message" flag to tfx run and tfx plan commands. (#8)
    • tfx workspace commands
      • list - List all workspaces in an Organization (optional workspace name search string)
      • list all - List all workspaces in All Organizations the API token has access to (optional workspace name search string)
      • show - Show details of a workspace
    • tfx metrics command to pull details about TFx (this command is hidden)
      • Organization Count
      • Workspace Count
      • Run Count
      • Policy Check Count
      • Policies Pass/Fail Count
    • tfx metrics workspace command to get run metrics for all workspaces in a single organization (this command is hidden)
      • Can filter on start date
      • Output:
        • Workspace Name
        • Total Runs
        • Errored Runs
        • Discarded Runs
        • Cancelled Runs
    Source code(tar.gz)
    Source code(zip)
    tfx_darwin_amd64(11.76 MB)
    tfx_linux_amd64(11.95 MB)
    tfx_windows_amd64(12.21 MB)
  • 0.0.1-dev(May 23, 2021)

  • 0.0.0-dev(May 16, 2021)

Owner
Tom Straub
Tom Straub
Reads from existing Cloud Providers (reverse Terraform) and generates your infrastructure as code on Terraform configuration

TerraCognita Imports your current Cloud infrastructure to an Infrastructure As Code Terraform configuration (HCL) or/and to a Terraform State. At Cycl

Cycloid 1.2k Aug 12, 2022
Ghissue - This repo contains a github issue parser, that is useful for Enterprise Github accounts.

Ghissue - This repo contains a github issue parser, that is useful for Enterprise Github accounts. Sometimes is needed to parse the content of the issue for some data extraction or statistics purposes.

niloofargheibi 1 Feb 6, 2022
Go-wechat-robot-sender - Using command line to send msg to Wechat enterprise by Go

Go-wechat-robot-sender - Using command line to send msg to Wechat enterprise by Go

Jinxin 1 Jan 28, 2022
Rclone ("rsync for cloud storage") is a command line program to sync files and directories to and from different cloud storage providers.

Rclone ("rsync for cloud storage") is a command line program to sync files and directories to and from different cloud storage providers.

rclone 34k Aug 5, 2022
Rclone ("rsync for cloud storage") is a command-line program to sync files and directories to and from different cloud storage providers.

Website | Documentation | Download | Contributing | Changelog | Installation | Forum Rclone Rclone ("rsync for cloud storage") is a command-line progr

null 0 Nov 5, 2021
A component on PolarStack, a hybrid cloud Alibaba Cloud DBaaS product

What is PolarDB Stack Daemon? PolarDB Stack Daemon is a component on PolarStack, a hybrid cloud Alibaba Cloud DBaaS product, and is designed mainly fo

null 10 Nov 21, 2021
The Cloud Aviator: TUI client for cloud services (AWS, Vultr, Heroku, Render.com, ...)

=== T H E C L O U D A V I A T O R === ⠀⠀⠀⠀⠀⠀⠀⠀⢶⣦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

◤◢◤◢◤◢◤◢ 30 Aug 1, 2022
DBT Cloud Terraform Provider

terraform-provider-dbt-cloud Terraform Provider for DBT Cloud Primarily focused on managing jobs in DBT Cloud, given what is available via the API. Da

Gary James 29 Jul 13, 2022
CLI to support with downloading and compiling terraform providers for Mac with M1 chip

m1-terraform-provider-helper A CLI to help with managing the installation and compilation of terraform providers when running a new M1 Mac. Motivation

kreuzwerker GmbH 198 Aug 10, 2022
A CLI command to parse Terraform execution result and notify it to Backlog

tf2b Fork of mercari/tfnotify tf2b parses Terraform commands' execution result and applies it to an arbitrary template and then notifies it to Backlog

Yuichi Watanabe 1 Oct 15, 2021
CLI to migrate Terraform Configuration and State

tfmigrator CLI CLI to migrate Terraform Configuration and State. The migration feature is implemented with tfmigrator/tfmigrator, so please see the do

null 29 Jun 2, 2022
minectl 🗺 is a cli for creating Minecraft (java or bedrock) server on different cloud provider.

minectl ?? minectl️️ is a cli for creating Minecraft (java or bedrock) server on different cloud provider. It is a private side project of me, to lear

Engin Diri 85 Jul 29, 2022
painless task queue manager for shell commands with an intuitive cli interface (execute shell commands in distributed cloud-native queue manager).

EXEQ DOCS STILL IN PROGRESS. Execute shell commands in queues via cli or http interface. Features Simple intuitive tiny cli app. Modular queue backend

Mohammed Al Ashaal 12 Jan 29, 2022
A CLI tool for GCP Cloud Build Triggers

cbtctl A CLI tool for GCP Cloud Build Triggers Usage Run a build trigger with substitutions $ cbtctl run --project <GCP Project Name> --trigger <Trigg

Yuki Ito 1 Nov 9, 2021
A CLI tool which loads data from yaml files into the Google Cloud Spanner tables

splanter A CLI tool which loads data from yaml files into the Google Cloud Spanner tables (mainly for the development).

Yuki Ito 13 Aug 7, 2022
Coala-cli-tester: a tool for testing infrastructure of Keenetic Cloud

coala-cli-tester coala-cli-tester is a tool for testing infrastructure of Keenetic Cloud Build go build -ldflags="-s -w" -o ./coala-cli-tester ./*.go

Alexey Spiridonov 0 Dec 8, 2021
A CLI Tool to easily generate your Terraform configuration

Tf Tf is a command line tool to easily generate your Terraform configuration with an interactive prompt. Inspiration Boredom in Covid-19 Installation

Gowtham Munukutla 19 Jul 26, 2022
Go-file-downloader-ftctl - A file downloader cli built using golang. Makes use of cobra for building the cli and go concurrent feature to download files.

ftctl This is a file downloader cli written in Golang which uses the concurrent feature of go to download files. The cli is built using cobra. How to

Dipto Chakrabarty 2 Jan 2, 2022