Suppose you want to create a project called "my project" to provision infrastructure on Azure using Terraform. Instead of starting from scratch, copying files, and adjusting settings like subscription_id, location, and other important variables, use Cookiecutter to automate the entire process.
pip install cookiecutterOr, if you prefer, install with Homebrew:
brew install cookiecuttercookiecutter https://github.com/diegosrp/cookiecutter-tf-template.gitYou will be prompted for information such as:
project_nameminimum_terraform_versionmaximum_terraform_versionprovider_minimum_versionenvironmentsubscription_idlocation
These values will customize your new project.
Note:
project_nameis required and cannot be empty. It only allows letters, numbers, spaces, and hyphens (-).subscription_id;is optional. If provided, it must be a valid Azure Subscription GUID (format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
"project_name": MY project-AZure
"minimum_terraform_version": 1.12.0
"maximum_terraform_version": 2.0
"provider_minimum_version": 4.40
"environment": 2
"subscription_id":
"location": australiaeastcd {{ cookiecutter.repository_name }}/
lsYou will see files like:
.gitignore backend.tf data.tf locals.tf main.tf outputs.tf providers.tf README.md. terraform.tf terraform.tfvars variables.tf
This template was created to help you quickly start new Azure Terraform projects with standardized file structure, naming conventions. By using this template, you ensure:
- Consistent naming for files
- Predefined file organization for Terraform code
- Version and provider constraints already set
- A clear starting point for your team or organization
The template is designed to save you time and reduce errors by providing a solid, opinionated foundation for your infrastructure-as-code projects.
Happy automating!