- Notifications
You must be signed in to change notification settings - Fork7
CLI for various operational tasks for Terraform Cloud / Enterprise such as cloning workspaces, migrating workspaces to a different organization, batch updating variables, etc.
License
silinternational/tfc-ops
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This application can be helpful in making copies/clones of a workspace and bringing its variables overto the new one. It can also be used for listing or updating workspace attributes and listing ormodifying variables in workspaces.
There are three ways to download/install this script:
- Download a pre-built binary for your operating system from theReleases page.
- If you're a Go developer and want to modify the source before running, clone this repo and run with
go run main.go ...
To provide access to HCP Terraform (Terraform Cloud) run theterraform login
command and follow the prompts. Thiswill store a short-lived token on your computer. tfc-ops uses this token to make API calls to HCP Terraform.
TFC_OPS_DEBUG
- Set totrue
to enable debug outputATLAS_TOKEN
- An HCP Terraform token can be set as an environment variable. Get this by going tohttps://app.terraform.io/app/settings/tokens and generating a new token. The recommended alternative is to usetheterraform login
command to request a short-lived token.ATLAS_TOKEN_DESTINATION
- Only necessary if cloning to a new organization in TF Cloud.
Examples.
Get help about the command.
$ tfc-ops workspaces clone -h
Clone just the workspace (no variables) to the same organization.
$ tfc-ops workspaces clone -o=my-org -s=source-workspace -n=new-workspace
Clone a workspace, its variables and its state to a different organization in TF Cloud.
Note: Sensitive variables will get a placeholder in the new workspace, the value ofwhich will need to be corrected manually. Also, the environment variables from the sourceworkspace will need to be moved in the destination workspace from the normal variables sectiondown to the environment variables section (e.g.CONFIRM_DESTROY
).
$ tfc-ops workspaces clone -c=true -t=true -o=org1 -p=org2 -d=true \$ -s=source-workspace -n=destination-workspace -v=org2-vcs-token
Examples.
Get help about the command.
$ tfc-ops workspaces list -h
List the workspaces with at least one of their attributes/pieces of data.
$ tfc-ops workspaces list -o=gtis -a=id,name,created-at,environment,working-directory,terraform-version,vcs-repo.identifier
$ tfc-ops -hPerform TF Cloud operations, e.g. clone a workspace or manage variables within a workspaceUsage: tfc-ops [command]Available Commands: help Help about any command variables Update or List variables varsets Commands for Variable Sets version Show tfc-ops version workspaces Clone, List, or Update workspacesFlags: -h, --help help for tfc-opsUse "tfc-ops [command] --help" for more information about a command.
$ tfc-ops workspacesTop level command for describing or updating workspaces or cloning a workspaceUsage: tfc-ops workspaces [command]Available Commands: clone Clone a Workspace list List Workspaces update Update WorkspacesFlags: -h, --help help for workspaces -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r")Use "tfc-ops workspaces [command] --help" for more information about a command.
$ tfc-ops workspaces clone -hClone a Terraform Cloud WorkspaceUsage: tfc-ops workspaces clone [flags]Flags: -t, --copyState optional (e.g. "-t=true") whether to copy the state of the Source Workspace (only possible if copying to a new account). -c, --copyVariables optional (e.g. "-c=true") whether to copy the values of the Source Workspace variables. -d, --differentDestinationAccount optional (e.g. "-d=true") whether to clone to a different TF account. -h, --help help for clone -p, --new-organization string Name of the Destination Organization in Terraform Cloud -v, --new-vcs-token-id string The new organization's VCS repo's oauth-token-id -n, --new-workspace string required - Name of the new Workspace in Terraform Cloud -s, --source-workspace string required - Name of the Source Workspace in Terraform CloudGlobal Flags: -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r")
$ tfc-ops workspaces consumers -hAdd to workspace remote state consumers. (Possible future capability: list, replace, delete)Usage: tfc-ops workspaces consumers [flags]Flags: --consumers string required - List of remote state consumer workspaces, comma-separated -h, --help help for consumers -w, --workspace string required - Partial workspace name to search across all workspacesGlobal Flags: -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r")
Any workspace attribute that can be read by the Terraform API can be retrievedby theworkspaces list
command. See theTerraform API Docsfor full details.
$ tfc-ops workspaces list -hLists the TF workspaces with (some of) their attributesUsage: tfc-ops workspaces list [flags]Flags: -a, --attributes string required - Workspace attributes to list, use Terraform Cloud API workspace attribute names -h, --help help for listGlobal Flags: -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r")
Any workspace attribute that can be updated by the Terraform API can be updatedby theworkspaces update
command. See theTerraform API Docsfor full details.
$ tfc-ops workspaces update -hUpdates an attribute of Terraform workspacesUsage: tfc-ops workspaces update [flags]Flags: -a, --attribute string required - Workspace attribute to update, use Terraform Cloud API workspace attribute names -h, --help help for update -v, --value string required - Value -w, --workspace string required - Partial workspace name to search across all workspacesGlobal Flags: -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r")
$ tfc-ops variablesTop level command to update or lists variables in all workspacesUsage: tfc-ops variables [command]Available Commands: add Add new variable (if not already present) delete Delete variable list Report on variables update Update/add a variable in a WorkspaceFlags: -h, --help help for variables -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r") -w, --workspace string Name of the Workspace in Terraform CloudUse "tfc-ops variables [command] --help" for more information about a command.
$ tfc-ops variables -hShow the values of variables with a key or value containing a certain stringUsage: tfc-ops variables list [flags]Flags: -h, --help help for list -k, --key_contains string required if value_contains is blank - string contained in the Terraform variable keys to report on -v, --value_contains string required if key_contains is blank - string contained in the Terraform variable values to report onGlobal Flags: -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r") -w, --workspace string Name of the Workspace in Terraform Cloud
$ tfc-ops variables update -hUpdate or add a variable in a Terraform Cloud Workspace based on a complete case-insensitive matchUsage: tfc-ops variables update [flags]Flags: -a, --add-key-if-not-found optional (e.g. "-a=true") whether to add a new variable if a matching key is not found. -h, --help help for update -n, --new-variable-value string required - The desired new value of the variable -v, --search-on-variable-value optional (e.g. "-v=true") whether to do the search based on the value of the variables. (Must be false if add-key-if-not-found is true -x, --sensitive-variable optional (e.g. "-x=true") make the variable sensitive. -s, --variable-search-string string required - The string to match in the current variables (either in the Key or Value - see other flags)Global Flags: -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r") -w, --workspace string Name of the Workspace in Terraform Cloud
Delete variable in matching workspace having the specified keyUsage: tfc-ops variables delete [flags]Flags: -h, --help help for delete -k, --key string required - Terraform variable key to delete, must match exactlyGlobal Flags: -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r") -w, --workspace string Name of the Workspace in Terraform Cloud
Add variable in matching workspace having the specified keyUsage: tfc-ops variables add [flags]Flags: -h, --help help for add -k, --key string required - Terraform variable key -v, --value string required - Terraform variable valueGlobal Flags: -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r") -w, --workspace string Name of the Workspace in Terraform Cloud
Apply an existing variable set to workspacesUsage: tfc-ops varsets apply [flags]Flags: -h, --help help for apply -s, --set string required - Terraform variable set to add -w, --workspace string Name of the Workspace in Terraform Cloud --workspace-filter string Partial workspace name to search across all workspacesGlobal Flags: -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r")
List variable sets applied to a workspaceUsage: tfc-ops varsets list [flags]Flags: -h, --help help for list -w, --workspace string Name of the Workspace in Terraform Cloud --workspace-filter string Partial workspace name to search across all workspacesGlobal Flags: -o, --organization string required - Name of Terraform Cloud Organization -r, --read-only-mode read-only mode (e.g. "-r")
tfc-ops is released under the Apache 2.0 license. SeeLICENSE
About
CLI for various operational tasks for Terraform Cloud / Enterprise such as cloning workspaces, migrating workspaces to a different organization, batch updating variables, etc.