terraform-workspace-clone
NPM package to clone or duplicate extsting terraform workspace.
</br>
Getting started
terraform-workspace-clone is a command-line module to clone terraform workspace.
π Homepage
Install
npm install -g terraform-workspace-clone
Usage
terraform-workspace-clone
needs few details before cloning the workspace. Input can be provided using cli prompts or can pass pre-filled json file as command-line argument.
Cli prompts:
Run below command in cli.
terraform-workspace-clone
Can also use tf-ws-clone
, It is a shorthand command.
Example:
β TF domain name? https://app.terraform.io // Terraform domain, can be cloud or enterprise
β Source workspace ID? ws-9xZ3c3iabcdefgh // Workspace id which you need to clone
β New workspace name? 00-test-1 // New workspace name
β Destination TF organization name? abc_org // TF org name in which new workspace will be created.
β (Optional) OAuth Token id from destinaton organization? // Required if want to clone VCS config. Refer 2nd screenshot.
β User api token **************** // User api token. Screenshot 1. For more details go to `API Token` section of https://www.terraform.io/cloud-docs/users-teams-organizations/users.
β Do you want to clone with values? no / yes // Yes, if want to clone variables with values.
NOTE: User should have permission to access source and destination org.
-
To generate user api token, </br> go to User Settings -> Tokens -> click on βCreate an API tokenβ button -> Create API token -> Copy token -> Done. </br>
-
To fetch VCS OAuth token ID, Select TF destination organization and go to Settings -> Providers -> Copy OAuth client id. Destination organization should be able to access VCS repo configured in source workspace. If VCS provider not configured then click on Settings -> Providers -> Add VCS provider.
Config file:
Input can be passed using pre-filled json file. JSON file should have below info:
{
"baseUrl": "https://app.terraform.io",
"sourceWorkspaceId": "ws-9xZ3c3iabcdefgh",
"newWorkspaceName": "00-test-1",
"destinationOrgName": "abc_org",
"destinationOrgVcsOauthTokenId": "",
"userApiToken": "Zxcvbnm..............sjhsmD",
"isCloneValue": true or false
}
and then pass this file as a input.
tf-ws-clone --config=<path to json file>/<filename>.json
This template can be generated using cli command. It will create a config template file with all the required keys tf_ws_clone_config.json
at same path from where tf-ws-clone
command is executed.
tf-ws-clone initconfig
Example:
tf-ws-clone --config=./tf_ws_clone_config.json
Running on-demand using npx:
Using npx
you can run the script on-demand:
npx terraform-workspace-clone
npx terraform-workspace-clone --config=./tf_ws_clone_config.json
Run tests
npm run test
New planned features
- Clone across multiple domains.
- Allow config file path also for the required details.
Author
π€ Sachin rajput.sachingla@gmail.com
- Github: @Sachin1678
π€ Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Show your support
Give a βοΈ if this project helped you!
π License
Copyright Β© 2022 Sachin rajput.sachingla@gmail.com.
This project is MIT licensed.