Package: terrachicken
TerraChicken (Terra🐓)Terrachicken is aclitool for interacting with Terraform Cloud Workspaces. Terra🐓 allows users to create, list, and delete TFC Workspaces. Terra🐓 supports configuring VCS backed workspaces for Github and Gitlab (Future Version). Terra🐓 was developed to help solve the 🐓 and 🥚 problem with Terraform Cloud automation. Allowing developers and practitioners an easy way to create and destroy workspaces from the command line. Terra🐓 even generatesTerraform Backendconfigurations.This project was created to help solve problems but more so to learn Python and CLI developmentPrerequisitesPython 3.6+Terraform Cloud AccountHere- Free Account WorksGithub AccountInstallationTo install Terra🐓 you can pull the package down for PyPi with the pip using the command belowNoteTerra🐓 uses libraries that have a hard dependency onPython 3.6+. You will need to have that version or newerpip install terrachickenConfigurationTerraChicken only supports Environment Variables currently. Future versions will have built in functionality to support initial configuration.Environment VariablesEnvironment VariablesTFC_TOKEN- API Token generated from Terraform Cloud Settings.TFC_URL- Terraform Cloud URL (app.terraform.io) unless using Terraform EnterpriseTFC_ORG- Terraform Cloud Organiztion NameGIT_TOKEN- Github Developer Access Token (Repo CRUD Perms at minimum)To set an environment token use the followingexport TFC_URL='app.terraform.io'Hint:After you set your tokens. You can install the built inauto completionwith theterrachicken --install-completioncommand.Using Terra🐓Creating WorkspacesTerra🐓 supports creatingLocalandVCSor Version Control System (Github/Gitlab) workspaces.Local WorkspacesExample:terrachicken create workspace localYou will be prompted to enter anamefor your workspace. After a successful completion your new Workspace ID will be printed to the terminal.VCS Workspaceterrachicken create workspace vcsNote: The Github OAuth provider must be configured in Terraform Cloud prior to building VCS workspaces.Creating a VCS backed workspace requires you to either create a repo or link and existing repo to the workspace. The default is to create a Github Repo along side the workspace.Generating Terraform Block ConfigurationsExample:terrachicken create workspace vcs --name TerrachickenTest1 --generateExamplerendered_main.tf:terraform{cloud{organization="aBakersDozen"workspaces{name="TerrachickenTest1"}}}Bothcreate workspace localandcreate workspace vcssupport generating a Terraform Block configuration to be implemented inside of your Terraform code. To read more about the Terraform Block Syntax clickhere. Using the--generateor-goption at the end of the command will output arendered_main.tffile to your current working directory.The Terraform Block settings will differ based on your workspace type. If you are creating alocalworkspace. The configuration setsbackendwith your workspace name. If you are creating avcsworkspace the configuration sets thecloudblock. To use the VCS generated main.tf file, you will need to run theterraform logincommand if you want to execute cli commands for terraform. Clickhereto read aboutcloud blockandterraform login.Create Workspace VCS Options--name: Name of Workspace--generate: Generate Terraform Block Configuration--out: Exports TFC Configuration viapayload.json--tfversion: Set Terraform Version in Workspace--create_repo: Create Repo or nah--private: Set Github Repo to Private--public: Set Github Repo to PublicTO-DOterrachicken initcommand allows you to add your tokens.NoteIf you are using an Env Var labeledTFC_TOKEN,TFC_URLorGIT_TOKEN. Those ENV Vars will take priorityTO-DO: Add TC backstory
TO-DO: Add init configurations to set default OAuth Client
TO-DO: Add --repo flag to copy --name flag
TO-DO: Add Gitlab VCS Options
TO-DO: Remove the utils.bcolors class, sub for the rich library
TO-DO: Add option to delete workspace and repo at same time.
TO-DO: Add more options to the TF Workspace Configuration.