these are the pre-commit hooks used for this repo:
- Down At The Bottom Of The Mole HoleTerraform module template
- Terraform
This is a repository template to be used for all of Down At The Bottom Of The Mole Hole's Terraform modules.
(Back to the Table of Contents)
- cspell
- GitVersion
- Infracost
- Markdown
- Mermaid
- Pre-Commit
- pre-commit-terraform
- prettier
- Terraform
- Terraform-docs
- Terrascan
- tflint
- tfsec
- tfupdate
(Back to the Table of Contents)
The below documentation was generated via Terraform docs using pre-commit
(Back to the Table of Contents)
Name | Version |
---|---|
terraform | 1.7.5 |
aws | 5.42.0 |
azuread | 2.47.0 |
azuredevops | 1.0.1 |
azurerm | 3.97.1 |
mongodbatlas | 1.15.2 |
random | 3.6.0 |
time | 0.11.1 |
(Back to the Table of Contents)
To consume this module add the following to your module.tf:
module "Module_Name" {
source = "github.com/DownAtTheBottomOfTheMoleHole/Module_Name.git"
# Required variables
application_name =
application_shortname =
azdo_pat =
azdo_project_name =
azdo_repo_name =
cag_division =
environment_tag =
resource_group_name =
# Optional variables
aws_access_key = ""
aws_profile = ""
aws_resource_location = "eu-west-1"
aws_secret_key = ""
azdo_orgurl = null
azrm_client_id = null
azrm_client_secret = null
azrm_keyvault_whitelist = []
azrm_resource_location = "northeurope"
azrm_storage_whitelist = []
azrm_subscription_id = null
azrm_tenant_id = null
default_tags = {}
time_secret_expiry = 100
time_spn_expiry = 100
}
##### Put your example Terraform code in this file and it will be displayed in the read me. ######
(Back to the Table of Contents)
Name | Type |
---|---|
random_password.aws_pass | resource |
random_password.azure_pass | resource |
time_offset.secret_expiry | resource |
time_offset.spn_password_expiry | resource |
azuread_client_config.bootstrap | data source |
azuread_group.bootstrap | data source |
azuredevops_project.bcaapp | data source |
azuredevops_project.bootstrap | data source |
azurerm_client_config.bootstrap | data source |
azurerm_subscription.bcaapp | data source |
azurerm_subscription.bootstrap | data source |
(Back to the Table of Contents)
Name | Description | Type | Default | Required |
---|---|---|---|---|
application_name | Project/application name | string |
n/a | yes |
application_shortname | short version of project/application name | string |
n/a | yes |
azdo_pat | Azure Devops Personal Access token (can be set to system.accesstoken) | string |
n/a | yes |
azdo_project_name | azure devops project name | string |
n/a | yes |
azdo_repo_name | The name of the Azure Devops Git Repository your code resides in | string |
n/a | yes |
cag_division | Division of CAG 3 character abbreviation e.hg. BCA, MMG | string |
n/a | yes |
environment_tag | Environment tag e.g. dev, test, systest, UAT, Prod | string |
n/a | yes |
resource_group_name | Specifies the name of the existing resource group to be used for the service plan | string |
n/a | yes |
aws_access_key | AWS access key | string |
"" |
no |
aws_profile | AWS profile | string |
"" |
no |
aws_resource_location | Resource location. Must be a valid AWS region | string |
"eu-west-1" |
no |
aws_secret_key | AWS secret key | string |
"" |
no |
azdo_orgurl | short version of project/application name | string |
null |
no |
azrm_client_id | Service principal id - cannot be null if working with azure | string |
null |
no |
azrm_client_secret | Service principal password - cannot be null if working with azure | string |
null |
no |
azrm_keyvault_whitelist | List of IP addresses and CIDR blocks for Key Vault whitelist to be combined with the defaults in main.tf | list(string) |
[] |
no |
azrm_resource_location | Resource group location. Must be a valid azure region | string |
"northeurope" |
no |
azrm_storage_whitelist | List of IP addresses and CIDR blocks for storage account whitelist to be combined with the defaults in main.tf | list(string) |
[] |
no |
azrm_subscription_id | Azure subscription id - cannot be null if working with azure | string |
null |
no |
azrm_tenant_id | Azure tenant id. cannot be null if working with Azure | string |
null |
no |
default_tags | Default map of tags to be applied to all resources generated by this module. | map(string) |
{} |
no |
time_secret_expiry | Number of years from now when keyvault secrets should expire | number |
100 |
no |
time_spn_expiry | Number of years from now when service principal password should expire | number |
100 |
no |
(Back to the Table of Contents)
Name | Description | Value | Sensitive |
---|---|---|---|
application_name | The project/application name for this repository | "application_name" |
no |
application_shortname | The shortened project/application name for this repository | "application_shortname" |
no |
aws_access_key | The AWS Access Key | <sensitive> |
yes |
aws_profile | The AWS profile used | "aws_profile" |
no |
aws_resource_location | The AWS region used for the resources | "eu-west-1" |
no |
azdo_orgurl | The Azure DevOps URL used for this run | "https://dev.azure.com/bcagroup" |
no |
azdo_pat | The Azure DevOps Personal Access Token (PAT) used for this run | <sensitive> |
yes |
azrm_client_id | The ID of the service principal used for this run | "azrm_client_id" |
no |
azrm_resource_location | The location of resources being worked on with this run | "northeurope" |
no |
azure_subscription_display_name | The current subscription name | "subscription_display_name" |
no |
azure_subscription_id | The current subscription id | "subscription_id" |
no |
azuredevops_project_name | The current Azure DevOps name | "project_name" |
no |
environment | The environment being worked on with this run | "dev" |
no |
tags | The tags applied to resources as part of this run | { |
no |
tenant_id | The azure tenant id of resources being worked on with this run | "tenant_id" |
no |
(Back to the Table of Contents)
Name | Source | Version |
---|---|---|
azrm_naming | Azure/naming/azurerm | 0.4.1 |
(Back to the Table of Contents)
This project uses terraform-docs to automatically generate tfvar files per environment that will allow you to have per environment values as well as common values.
the common values will reside in:
for the terraform directory (the terraform directory the pipelines refer to): .\environment\default.tfvars
Environment specific variables then reside in an environment specific folder under the terraform directory e.g. .\environment\dev\variables.tfvars
to generate these files do the following
- Navigate to your terraform directory using command prompt or powershell
- To generate environment specific variables run
terraform-docs tfvars hcl . --output-file .\environment\poc\variables.tfvars --output-mode inject --read-comments --description --header-from ./terraform-docs/tf_header.txt --footer-from ./terraform-docs/tf_footer.txt
replacing the environment foldername as appropriate - To generate the common variables file run
terraform-docs tfvars hcl . --output-file .\environment\default.tfvars --output-mode inject --read-comments --description --header-from ./terraform-docs/tf_header.txt --footer-from ./terraform-docs/tf_footer.txt
Terraform version and terraform provider versions have been set using tfupdate. In order to update the installed providers to the latest versions please first install tfupdate using the below instructions and then run the following commands from the root of the repo in a powershell session. Please only run the commands for the providers/modules you are using.
the tfupdate repo can be found here
either download the tarball and add tfupdate.exe to your PATH or do the following:
- Ensure you have Go installed
- Clone the repository locally
git clone https://github.com/minamijoyo/tfupdate.git
- build the source code with
go build
- Add the complied binaries to your PATH
tfupdate terraform . --version ">=$(tfupdate release latest hashicorp/terraform)" --recursive
please also add the terraform version to the terraform_installer_version
variable in build/pipelines/iac_templates/variables.yml
tfupdate module Azure/naming/azurerm . --version ">=$(tfupdate release latest Azure/naming/azurerm --source-type tfregistryModule)" --recursive
tfupdate provider aws . --version ">=$(tfupdate release latest hashicorp/aws --source-type tfregistryProvider)" --recursive
tfupdate provider azuread . --version ">=$(tfupdate release latest hashicorp/azuread --source-type tfregistryProvider)" --recursive
tfupdate provider azuredevops . --version ">=$(tfupdate release latest microsoft/azuredevops --source-type tfregistryProvider)" --recursive
tfupdate provider azurerm . --version ">=$(tfupdate release latest hashicorp/azurerm --source-type tfregistryProvider)" --recursive
tfupdate provider random . --version ">=$(tfupdate release latest hashicorp/random --source-type tfregistryProvider)" --recursive
tfupdate provider time . --version ">=$(tfupdate release latest hashicorp/time --source-type tfregistryProvider)" --recursive
(Back to the Table of Contents)
Below are instructions on how to using the terraform module template to create a new module or to apply to a pre-existing module.
-
browse to RolfMoleman organisation on github and create a new repository
-
Choose the Repository template as RolfMoleman/terraform_module_template
-
Leave the owner as RolfMoleman
-
Give the repository a name following the naming convention of
terraform-<provider name>-<resource name replacing spaces with ->
Note: this will be the name of the module -
Give the repository a meaningful concise description
-
Leave the repository visibility as private
-
clone your newly created repository using
git clone https://github.com/DownAtTheBottomOfTheMoleHole/Module_Name.git
-
Create your readme:
-
In your vscode terminal do the following:
-
Rename-Item -Path ".\README.md" -NewName "README.OLD"
-
Rename-Item -Path ".\BLANK_README.md" -NewName "README.md"
-
-
In the new README.md do the following:
-
Find & replace (CTRL+SHIFT+H in vs code)
Module_Name
with your module name. Note: Please use snake_case e.g. azurerm_awesome_module -
Find and replace (CTRL+SHIFT+H in vs code)
Your_Email_Address
with your email address e.g.carl.dawson@bca.com
-
Find and replace (CTRL+SHIFT+H in vs code)
Your_Team
with the name of your team -
Find and replace (CTRL+SHIFT+H in vs code)
Team_Email_List
with a comma separated list of your team member's email addresses -
Find and replace (CTRL+SHIFT+H in vs code)
Team_Email_Address
with your team's email address if you have one, else remove it. -
Find and replace (CTRL+SHIFT+H in vs code)
Module_Title
with a sensible name e.g.Down At The Bottom Of The Mole Hole Terraform module template
-
Find and replace (CTRL+SHIFT+H in vs code)
Module_Description
with some details about what the module is and what it is for -
Find and replace (CTRL+SHIFT+H in vs code)
Your_Name
with your name e.g.Carl Dawson
-
-
Update the roadmap so other staff can see your progress
-
Start creating/editing your terraform files - Note: use tflint to help you remove unneeded variables, outputs, resources & locals. This will also help ensure you have good descriptions, sensitive flags set etc. use validation on input variables where possible.
-
Generate your default_values.json this is a json file that populates your values in your documentation with actual values. You can either do this manually or by running
terraform output --json > default_values.json
once you have done a successful plan and apply. -
Use terraform-docs to generate your documentation.
-
README.md
either run:
terraform-docs markdown table . --config '.config\.readme-terraform-docs.yml'
or:
pre-commit run terraform-docs-go
-
TERRAFORM.md
either run:
terraform-docs markdown table . --config '.config\.terraform-terraform-docs.yml'
or:
pre-commit run terraform-docs-go
-
-
Create a really useful module!
-
Tag your finished code using [GitVersion] - powershell one liner to do so:
$gitversion = (gitversion |ConvertFrom-Json);git tag $GitVersion.SemVer -m 'My awesome release';git push --tags
-
Push your finished code up to github Note: dont forget to push your tags as well with
git push --tags
-
The rest of CAG can consume your module π
(Back to the Table of Contents)
-
Clone the terraform module template using
git clone https://github.com/DownAtTheBottomOfTheMoleHole/terraform_module_template.git
-
rename your existing README.md using
Rename-Item -Path ".\README.md" -NewName "README.OLD"
-
copy the following basic directories from the template to the root of your repo
- .assets
- .config
- .github
- .infracost
- .pre-commit_logs - you may need to create this
- scripts
- terraform-docs
-
copy the following files from the template to the root of your repo
- LICENSE
- .gitignore - replace your own or merge them.
- .tflint.hcl
- BLANK_README.md - we will rename this later to become your new readme
- CODE_OF_CONDUCT.md
- TERRAFORM.md
- .prettierignore
- .pre-commit-config.yml
-
merge the .tf files from the template with your own to achieve the following structure
- main.tf - contains the core resources and locals use tflint to help you remove unneeded resources and locals.
- data.tf - contains any data sources your module requires use tflint to help you remove unneeded data sources.
- modules.tf - contains any external modules you may be calling. use tflint to help you remove unneeded modules.
- outputs.tf - contains all your module outputs. use tflint to help you remove unneeded outputs.
- variables.tf - contains your input variables. Please ensure you use our standard inputs to ensure consistency. use tflint to help you remove unneeded variables.
- versions.tf - contains the required versions for terraform and required providers. you must use the latest possible versions. You must be No more than 3 minor versions out of date.
-
update the
./terraform-docs/default_values.json
this must match the your terraform outputs in json format. this is a json file that populates your values in your documentation with actual values. You can either do this manually or by runningterraform output --json > default_values.json
once you have done a successful plan and apply. -
create your readme from BLANK_README.md
-
Find & replace (CTRL+SHIFT+H in vs code)
Module_Name
with your module name. Note: Please use snake_case e.g. azurerm_awesome_module -
Find and replace (CTRL+SHIFT+H in vs code)
Your_Email_Address
with your email address e.g.carl.dawson@bca.com
-
Find and replace (CTRL+SHIFT+H in vs code)
Your_Team
with the name of your team -
Find and replace (CTRL+SHIFT+H in vs code)
Team_Email_List
with a comma separated list of your team member's email addresses -
Find and replace (CTRL+SHIFT+H in vs code)
Team_Email_Address
with your team's email address if you have one, else remove it. -
Find and replace (CTRL+SHIFT+H in vs code)
Module_Title
with a sensible name e.g.Down At The Bottom Of The Mole Hole Terraform module template
-
Find and replace (CTRL+SHIFT+H in vs code)
Module_Description
with some details about what the module is and what it is for -
Find and replace (CTRL+SHIFT+H in vs code)
Your_Name
with your name e.g.Carl Dawson
-
Update the roadmap so other staff can see your progress
-
rename BLANK_README.md to README.md using:
Rename-Item -Path ".\BLANK_README.md" -NewName "README.md"
-
-
Use terraform-docs to generate your documentation.
-
README.md
either run:
terraform-docs markdown table . --config '.config\.readme-terraform-docs.yml'
or:
pre-commit run terraform-docs-go
-
TERRAFORM.md
either run:
terraform-docs markdown table . --config '.config\.terraform-terraform-docs.yml'
or:
pre-commit run terraform-docs-go
-
-
Create a really useful module!
-
Tag your finished code using [GitVersion] - powershell one liner to do so:
$gitversion = (gitversion |ConvertFrom-Json);git tag $GitVersion.SemVer -m 'My awesome release';git push --tags
-
Push your finished code back to your source control Note: dont forget to push your tags as well with
git push --tags
-
Anyone can consume your module π
(Back to the Table of Contents)
- Basic template
- Finish readme guide
- Refine BLANK_README.md
- Terraform-docs config per output markdown file π§°
- Basic GitHub actions
- GitHub Issue Templates π§°
- GitHub Pull Request Template π§°
- Automated releases on push/merge/rebase to main πΎ π§° πΆπ₯©
- Consolidate workflows
- Auto add issues to Platform & Automation backlog πΎ π§° πΆπ₯©
- Megalinter automatic fixes via pull request π§° πΆπ₯©
- Dependabot automated dependency management π§° πΆπ₯©
- Renovate automated dependency management π§° πΆπ₯©
- Automated issue assignment to the Platform and Automation team π§° πΆπ₯©
- Add instructions on how to backfit the template π§° πΆπ₯©
See the issues for a full list of proposed features (and known issues).
(Back to the Table of Contents)
Everyone is encouraged to contribute Contributions are what make the open source community such a great way to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please create a branch and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
- Clone the Repo (
git clone https://github.com/DownAtTheBottomOfTheMoleHole/terraform_module_template
) - Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
NOTE: This repo has tagged releases where the version is generated by gitversion. You can increment the release version by adding to your commit message as follows:
Adding +semver: breaking or +semver: major will cause the major version to be increased, +semver: feature or +semver: minor will bump minor and +semver: patch or +semver: fix will bump the patch. source
(Back to the Table of Contents)
To work with this repo we recommend you install the tools that are included in the prerequisites. However, you may work on the repo in the browser if you prefer.
To replicate the setup used to initially create this repository you will need
-
Clone the Repo
git clone https://github.com/DownAtTheBottomOfTheMoleHole/terraform_module_template.git
-
Install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
-
Install Node
choco install nodejs
-
Install Terraform
choco install terraform
-
Install TFlint
choco install tflint
Also download the tflint plugins from github such as tflint-ruleset-azurerm and tflint-ruleset-aws put these in your
.tflint.d/plugins
directory at the root of your user directory -
Install terraform-docs
choco install terraform-docs
-
Install Python
choco install python
-
Install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py
-
Install pre-commit
pip install pre-commit
-
Install vscode
choco install vscode
-
Install tfupdate
Download the latest compiled binaries from here then put it in your executable path.
(Back to the Table of Contents)
for more information about the license please see LICENSE.md
(Back to the Table of Contents)
RolfMoleman - @RolfMoleman
Module Link: https://github.com/DownAtTheBottomOfTheMoleHole/terraform_module_template
(Back to the Table of Contents)