As someone that has to jump between a host of Terraform deployment environments having a standard template of files for each environment is a real time saver. Today I want to highlight a shell utility I have been using to help streamline this process:prm
prm allows you to useCRUD methodology for projects within your shell. Upon activation, each projects runs its associated start up script and upon deactivation, it can run scripts to clean up the environment.
These start and stop scripts can be used for changing directories, setting environment variables, cleanup, etc.
Example
One of the IBM Cloud Services I interact with the most isSchematics. Schematics is a hostedTerraform environment for defining and deploying Infrastructure as Code both within and outside of IBM Cloud.
Everytime I start a new Schematics project I need to do the following:
- Create a Directory structure in a specified location
- Copy a set of example Terraform files
- Initialize a new Git repository
- Open Visual Studio Code in the newly created project directory
prm allows me to do that with the following start up script:
# Command line arguments can be used, $3 would be the first argument after your project name.PROJECT_NAME="$3"TEMPLATE_DIR="${HOME}/Sync/Code/Terraform/templates/prm/schematics"TF_DIR="${HOME}/Sync/Code/Terraform"dt=$(date"+%Y.%m.%d")if[[!-d"${TF_DIR}/${PROJECT_NAME}"]];thenmkdir"${TF_DIR}/${PROJECT_NAME}"&&cd$_exportTF_PROJECT_DIR="${TF_DIR}/${PROJECT_NAME}"elseecho"Directory already exists, creating new one with date appended"mkdir"${TF_DIR}/${PROJECT_NAME}-${dt}"&&cd$_exportTF_PROJECT_DIR="${TF_DIR}/${PROJECT_NAME}-${dt}"ficp"${TEMPLATE_DIR}"/Terraform.gitignore"${TF_PROJECT_DIR}"/.gitignorecp"${TEMPLATE_DIR}/main.tf""${TF_PROJECT_DIR}/main.tf"cp"${TEMPLATE_DIR}/variables.tf""${TF_PROJECT_DIR}/variables.tf"cp"${TEMPLATE_DIR}/providers.tf""${TF_PROJECT_DIR}/providers.tf"cp"${TEMPLATE_DIR}/install.yml""${TF_PROJECT_DIR}/install.yml"cp"${TEMPLATE_DIR}/installer.sh""${TF_PROJECT_DIR}/installer.sh"cp"${TEMPLATE_DIR}/data.tf""${TF_PROJECT_DIR}/data.tf"git init code.
Invoking PRM
To start aprm Schematics project I simply runprm start schematics <name of project>
.
tycho ◲ prm start schematics testfordevtoStarting project schematicsInitialized empty Git repositoryin /Users/ryan/Sync/Code/Terraform/testfordevto/.git/~/Sync/Code/Terraform/testfordevto master*tycho ◲ ls-l-rw-r--r-- 1 ryan staff 68 Jul 14 10:40 data.tf-rw-r--r-- 1 ryan staff 2440 Jul 14 10:40 install.yml-rw-r--r-- 1 ryan staff 2259 Jul 14 10:40 installer.sh-rw-r--r-- 1 ryan staff 599 Jul 14 10:40 main.tf-rw-r--r-- 1 ryan staff 121 Jul 14 10:40 providers.tf-rw-r--r-- 1 ryan staff 1136 Jul 14 10:40 variables.tf
When runningprm stop schematics
prm invokes the following actions:
- Checks if latest code changes have been pushed to Source control and if not prompts the user to do so.
- Clears out any local
*.tfplan
or*.tfvars
files. - Prompts if any new TODO items need to be added to the README file.
- Changes directory back to $HOME
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse