Reusable scripts and tools for working with Terraform across multiple projects.
This repo contains utilities that make working with Terraform easier in projects with standardised directory structure. The main tool is a Terraform wrapper script that:
- Works from any directory in your project (defaults to
infrastructure/terraform) - Automatically detects your Terraform configuration location
- Sources environment variables for authentication from an environment variable file (defaults to
.env) - Auto-initializes when necessary
Run the install script to add the tools to your $PATH:
chmod +x install.sh
./install.shThis will:
- Make the script(s) executable
- Add the bin directory to your PATH by modifying your shell configuration file (~/.bashrc or ~/.zshrc)
- Tell you how to update your current shell session
If you prefer more control over the installation:
-
Make the scripts executable:
chmod +x bin/* -
Either:
- Add the bin directory to your PATH:
export PATH="/path/to/terraform-tools/bin:$PATH"
- Create symlinks to your personal bin directory:
ln -s /path/to/terraform-tools/bin/tf ~/bin/tf
- Add the bin directory to your PATH:
The main tool is a (simple) Terraform wrapper that finds your Terraform configuration and runs commands in the correct context:
# Initialize Terraform
tf init
# Create a plan
tf plan
# Apply changes
tf apply
# Any other Terraform command
tf <command> [arguments]- Dynamic project detection: Works from any directory in your project
- Project root is determined by reversing the directory tree until the infrastructure directory is found.
- Auto-initialization: Automatically runs
terraform initwhen needed - Environment variables: Sources
.envfile from project root if available- This helps with current Azure provider requirement to supply Tenant and Subscription IDs outside of the Az CLI tool
- Argument passing: Forwards all additional arguments to Terraform
By default, the tool expects your Terraform configuration to be in an infrastructure/terraform directory within your project:
your-project/
├── infrastructure/
│ └── terraform/
│ ├── main.tf
│ └── ...
└── ...
If you want to customize the tools, you can modify:
- The subdirectory name in the
tfscript (update theTF_SUBDIRvariable) - The environment variables file (update the
DOTENVvariable) - The shell configuration file in the
install.shscript
Contributions are welcome! Please feel free to submit a Pull Request.