TFx CLI
tfx is a standalone CLI for Terraform Cloud and Terraform Enterprise.
The initial focus of tfx was to execute the API-Driven workflow for a Workspace but has grown to manage multiple aspects of the platform.
Note: This CLI is still under active development, subject to change, and is not officially supported by HashiCorp.
Documentation
Questions about a Command? Check out the docs
Why does this CLI exist?
As a consumer of Terraform Cloud or Terraform Enterprise 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 a delivery pipeline, but could also be administrative tasks that are done from a local machine. The goal of this tool is to allow users to interact with the platform easily without having to create a lot of hard to maintain code.
Common API-Driven Workflow Challenges:
The initial use case for tfx was to bridge the gap from the CLI-Workflow and the API-Driven Workflow.
- The CLI-Driven workflow presents several challenges when creating more advanced pipelines for 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 airgapped 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.
Installation
Binaries are created as part of release, check out the Release Page for the latest release.
MacOs Installation
version="0.0.3-dev"
curl -L -o tfx "https://github.com/straubt1/tfx/releases/download/${version}/tfx_darwin_amd64"
chmod +x tfx
Linux Installation
version="0.0.3-dev"
curl -L -o tfx "https://github.com/straubt1/tfx/releases/download/${version}/tfx_linux_amd64"
chmod +x tfx
Windows Installation
version="0.0.3-dev"
curl -L -o tfx.exe "https://github.com/straubt1/tfx/releases/download/${version}/tfx_windows_amd64"
Go Installation
From Go version 1.18, the following is supported. @latest
can be @$VERSION
go install github.com/straubt1/tfx@latest
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. Can also be set with the environment variable TFE_HOSTNAME. (default "app.terraform.io")
--tfeOrganization string The name of the TFx Organization. Can also be set with the environment variable TFE_ORGANIZATION.
--tfeToken string The API token used to authenticate to TFx. Can also be set with the environment variable TFE_TOKEN.
Flags can also be created in a configuration file with the file name ".tfx.hcl". Flags can also be set via environment values by using a key that is capitalized version of the flag.
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 Terraform Cloud)
tfeOrganization = "my-awesome-org"
tfeToken = "<Generated from Terraform Enterprise or Terraform Cloud>"
You can also specify this file via the --config
flag.
Contributing
Thank you for your interest in contributing!
Contributing guide coming soon
References
https://github.com/hashicorp/go-tfe