Azure DevOps Naming Module
November 30, 2024 · View on GitHub
these are the pre-commit hooks used for this repo:
Table of Contents
- Azure DevOps Naming Module
- Terraform
About The Project
A terraform module to enable consistent naming of Azure DevOps resources
(Back to the Table of Contents)
Built With
- cspell
- GitVersion
- Markdown
- Megalinter
- Pre-Commit
- pre-commit-terraform
- prettier
- Terraform
- Terraform-docs
- tflint
- tfupdate
(Back to the Table of Contents)
Terraform
The below documentation was generated via Terraform docs using pre-commit
(Back to the Table of Contents)
Requirements
| Name | Version |
|---|---|
| terraform | >= 1.10.0, <2.0.0 |
| random | >= 3.6.0, <4.0.0 |
(Back to the Table of Contents)
Consuming terraform-azuredevops-naming
To consume this module add the following to your module.tf:
module "azdo_naming" {
source = "DownAtTheBottomOfTheMoleHole/naming/azuredevops"
version = "~>2.2.0"
# Optional variables
environment_tags = [
"dev",
"uat",
"prd"
]
prefix = []
suffix = []
unique_include_numbers = true
unique_length = 4
unique_seed = ""
work_items = []
}
Creating a project
module "azdo_naming" {
source = "DownAtTheBottomOfTheMoleHole/naming/azuredevops"
version = ">= 6.0.0, <7.0.0"
# Optional variables
environment_tags = [
"dev",
"uat",
"prd"
]
prefix = ["dbmh"]
suffix = ["test"]
unique_include_numbers = true
unique_length = 4
unique_seed = ""
work_items = []
}
resource "azuredevops_project" "example_1" {
name = module.azdo_naming.project.name
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
description = "Managed by Terraform"
features = {
"testplans" = "disabled"
"artifacts" = "disabled"
}
}
Creating a unique branch name
this shows creating:
- a project
- git repository inside the project
- a feature branch based on the default branch with a unique name
module "azdo_naming" {
source = "DownAtTheBottomOfTheMoleHole/naming/azuredevops"
version = ">=6.0.0, <7.0.0"
# Optional variables
environment_tags = [
"dev",
"uat",
"prd"
]
prefix = ["dbmh"]
suffix = ["test"]
unique_include_numbers = true
unique_length = 4
unique_seed = ""
work_items = []
}
resource "azuredevops_project" "example_2" {
name = module.azdo_naming.project.name
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_git_repository" "example_2" {
project_id = azuredevops_project.example.id
name = module.azdo_naming.git_repository.name
initialization {
init_type = "Clean"
}
}
resource "azuredevops_git_repository_branch" "feature_branch" {
repository_id = azuredevops_git_repository.example.id
name = module.azdo_naming.git_repository_feature_branch_slash.name_unique
ref_branch = azuredevops_git_repository.example.default_branch
}
(Back to the Table of Contents)
Resources
| Name | Type |
|---|---|
| random_string.first_letter | resource |
| random_string.main | resource |
(Back to the Table of Contents)
Inputs
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| environment_tags | List of environment names in their shortened form. These will be translated to full names in the module. | list(string) | [ | no |
| prefix | Prefix to be used for naming resources. If used we suggest using a company abreviation e.g dbmh. | list(string) | [] | no |
| suffix | Suffix to be used for naming resources. It is recommended to use lowercase characters for consistency. | list(string) | [] | no |
| unique_include_numbers | Determines whether numbers should be included in the unique suffix generation. | bool | true | no |
| unique_length | Maximum length of the unique suffix to be added to resource names. | number | 4 | no |
| unique_seed | Custom seed value for generating unique random characters. | string | "" | no |
| work_items | List of Work Items or issue numbers to be used in branch name and environment name creation. For example, ['1234', '1235'] will create branch names like 'feature/1234-' and 'feature/1235-'. | list(string) | [] | no |
(Back to the Table of Contents)
Outputs
| Name | Description | Value | Sensitive |
|---|---|---|---|
| agent_pool | The agent pool used in Azure DevOps | { | ,",#,", "scope": "Organization", "slug": "agtpol" } |
| branch_policy_build_validation | The display name of the branch policy for build validation in Azure DevOps | { | #*}{,+=\\[\\]]*", "scope": "repository", "slug": "bpbv" } |
| build_definition | The build definition in Azure DevOps | { | ]*$", "scope": "Project", "slug": "blddef" } |
| build_folder | The folder containing the build files in Azure DevOps | { | ]*$", "scope": "Organization", "slug": "arpth" } |
| elastic_pool | The elastic pool used in Azure DevOps | { | ,",#,,", "scope": "Organization", "slug": "eapool" } |
| environment | The name of the environment in Azure DevOps | { | ]$", "scope": "Project", "slug": "envapp" }, "production": { "dashes": true, "max_length": 240, "min_length": 1, "name": "dbmh-production-apply-adonaming", "name_unique": "dbmh-production-apply-adonaming-h6lf", "regex": "^[^/\:?"\u003c\u003e |
| environment_apply | The name of the environment where apply operations are performed in Azure DevOps | { | ]$", "scope": "Project", "slug": "envapp" }, "production": { "dashes": true, "max_length": 240, "min_length": 1, "name": "dbmh-production-apply-adonaming", "name_unique": "dbmh-production-apply-adonaming-h6lf", "regex": "^[^/\:?"\u003c\u003e |
| environment_apply_basic | The basic name of the environment where apply operations are performed in Azure DevOps | { | ]$", "scope": "Project", "slug": "envappb" }, "production": { "dashes": true, "max_length": 240, "min_length": 1, "name": "production-apply", "name_unique": "production-apply-adonaming-h6lf", "regex": "^[^/\:?"\u003c\u003e |
| environment_basic | The basic name of the environment in Azure DevOps | { | ]$", "scope": "Project", "slug": "envbas" }, "production": { "dashes": true, "max_length": 240, "min_length": 1, "name": "production", "name_unique": "production-adonaming-h6lf", "regex": "^[^/\:?"\u003c\u003e |
| environment_plan | The name of the environment where plan operations are performed in Azure DevOps | { | ]$", "scope": "Project", "slug": "envpln" }, "production": { "dashes": true, "max_length": 240, "min_length": 1, "name": "dbmh-production-plan-adonaming", "name_unique": "dbmh-production-plan-adonaming-h6lf", "regex": "^[^/\:?"\u003c\u003e |
| environment_plan_basic | The basic name of the environment where plan operations are performed in Azure DevOps | { | ]$", "scope": "Project", "slug": "envplnb" }, "production": { "dashes": true, "max_length": 240, "min_length": 1, "name": "production-plan", "name_unique": "production-plan-adonaming-h6lf", "regex": "^[^/\:?"\u003c\u003e |
| environment_work_item | The name of the environment associated with work items in Azure DevOps | { | ]$", "scope": "Project", "slug": "envwi" }, "1235": { "dashes": true, "max_length": 240, "min_length": 1, "name": "dbmh-development-1235-adonaming", "name_unique": "dbmh-development-1235-adonaming-h6lf", "regex": "^[^/\:?"\u003c\u003e |
| environment_work_item_basic | The basic name of the environment associated with work items in Azure DevOps | { | ]$", "scope": "Project", "slug": "envwib" }, "1235": { "dashes": true, "max_length": 240, "min_length": 1, "name": "development-1235", "name_unique": "development-1235-adonaming-h6lf", "regex": "^[^/\:?"\u003c\u003e |
| git_repository | The Git repository in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "gitrepo" } |
| git_repository_branch | The branch of the Git repository in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Repository", "slug": "gitbranch" } |
| git_repository_bug_branch_dash | The bug branch of the Git repository in Azure DevOps, with dashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": false, "slug": "gitbugbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "bug-1235-dbmh-adonaming", "name_unique": "bug-1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_bug_branch_slash | The bug branch of the Git repository in Azure DevOps, with slashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": true, "slug": "gitbugbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "bug/1235-dbmh-adonaming", "name_unique": "bug/1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_dev_branch_dash | The development branch of the Git repository in Azure DevOps, with dashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": false, "slug": "gitdevbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "dev-1235-dbmh-adonaming", "name_unique": "dev-1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_dev_branch_slash | The development branch of the Git repository in Azure DevOps, with slashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": true, "slug": "gitdevbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "dev/1235-dbmh-adonaming", "name_unique": "dev/1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_development_branch_dash | The development branch of the Git repository in Azure DevOps, with dashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": false, "slug": "gitdevbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "development-1235-dbmh-adonaming", "name_unique": "development-1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_development_branch_slash | The development branch of the Git repository in Azure DevOps, formatted with slashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": true, "slug": "gitdevbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "development/1235-dbmh-adonaming", "name_unique": "development/1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_feature_branch_dash | The feature branch of the Git repository in Azure DevOps, formatted with dashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": false, "slug": "gitfetbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "feature-1235-dbmh-adonaming", "name_unique": "feature-1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_feature_branch_slash | The feature branch of the Git repository in Azure DevOps, formatted with slashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": true, "slug": "gitfetbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "feature/1235-dbmh-adonaming", "name_unique": "feature/1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_fix_branch_dash | The fix branch of the Git repository in Azure DevOps, formatted with dashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": false, "slug": "gitfixbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "fix-1235-dbmh-adonaming", "name_unique": "fix-1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_fix_branch_slash | The fix branch of the Git repository in Azure DevOps, formatted with slashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": true, "slug": "gitfixbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "fix/1235-dbmh-adonaming", "name_unique": "fix/1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_hotfix_branch_dash | The hotfix branch of the Git repository in Azure DevOps, formatted with dashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": false, "slug": "githotbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "hotfix-1235-dbmh-adonaming", "name_unique": "hotfix-1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_hotfix_branch_slash | The hotfix branch of the Git repository in Azure DevOps, formatted with slashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": true, "slug": "githotbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "hotfix/1235-dbmh-adonaming", "name_unique": "hotfix/1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_release_branch_dash | The release branch of the Git repository in Azure DevOps, formatted with dashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": false, "slug": "gitrelbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "release-1235-dbmh-adonaming", "name_unique": "release-1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| git_repository_release_branch_slash | The release branch of the Git repository in Azure DevOps, formatted with slashes | { | ~';.,\[\]{}()@#", "scope": "Repository", "slashes": true, "slug": "gitrelbr" }, "1235": { "dashes": true, "max_length": 255, "min_length": 1, "name": "release/1235-dbmh-adonaming", "name_unique": "release/1235-dbmh-adonaming-h6lf", "regex": "^[^/\:*?"\u003c\u003e |
| group | The group in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Organization", "slug": "grp" } |
| project | The project in Azure DevOps | { | ;#*{}+,=\\[\\]\\x00-\\x1F]*", "scope": "Organization", "slug": "prj" } |
| serviceendpoint_argocd | The ArgoCD service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "seargocd" } |
| serviceendpoint_artifactory | The Artifactory service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "seart" } |
| serviceendpoint_aws | The AWS service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "seaws" } |
| serviceendpoint_azurecr | The Azure Container Registry service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "seazcr" } |
| serviceendpoint_azuredevops | The Azure DevOps service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "seazdo" } |
| serviceendpoint_azurerm | The Azure Resource Manager service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "seazrm" } |
| serviceendpoint_bitbucket | The Bitbucket service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sebitb" } |
| serviceendpoint_dockerregistry | The Docker Registry service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sedr" } |
| serviceendpoint_externaltfs | The external TFS service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "setfs" } |
| serviceendpoint_gcp_terraform | The GCP Terraform service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "segcptf" } |
| serviceendpoint_generic | The generic service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "seg" } |
| serviceendpoint_generic_git | The generic Git service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "seggit" } |
| serviceendpoint_github | The GitHub service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "segh" } |
| serviceendpoint_github_enterprise | The GitHub Enterprise service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "segh" } |
| serviceendpoint_incomingwebhook | The incoming webhook service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "seiw" } |
| serviceendpoint_jenkins | The Jenkins service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sej" } |
| serviceendpoint_jfrog_artifactory_v2 | The JFrog Artifactory v2 service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sejfa" } |
| serviceendpoint_jfrog_distribution_v2 | The JFrog Distribution v2 service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sejfd" } |
| serviceendpoint_jfrog_platform_v2 | The JFrog Platform v2 service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sejfp" } |
| serviceendpoint_jfrog_xray_v2 | The JFrog Xray v2 service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sejx" } |
| serviceendpoint_kubernetes | The Kubernetes service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sek" } |
| serviceendpoint_maven | The Maven service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "semvn" } |
| serviceendpoint_nexus | The Nexus service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sen" } |
| serviceendpoint_npm | The NPM service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "senpm" } |
| serviceendpoint_nuget | The NuGet service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "senug" } |
| serviceendpoint_octopusdeploy | The Octopus Deploy service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "seod" } |
| serviceendpoint_runpipeline | The Run Pipeline service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "serp" } |
| serviceendpoint_servicefabric | The Service Fabric service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sesf" } |
| serviceendpoint_sonarcloud | The SonarCloud service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sesc" } |
| serviceendpoint_sonarqube | The SonarQube service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sesq" } |
| serviceendpoint_ssh | The SSH service endpoint in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "sessh" } |
| team | The team in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "adt" } |
| unique_seed | A custom value for generating random characters, used when a unique seed is not provided | "h6lft43juihfyd9pp0qi3hldl6evepm2su9aztf5mqnyuwzzx48lniw479adc" | no |
| validation | The validation rules that have been applied | { | ]$", "scope": "Project", "slug": "envwi" }, "1235": { "dashes": true, "max_length": 240, "min_length": 1, "name": "dbmh-development-1235-adonaming", "name_unique": "dbmh-development-1235-adonaming-h6lf", "regex": "^[^/\:?"\u003c\u003e |
| variable_group | The variable group in Azure DevOps | { | ~';.,\[\]{}()@#", "scope": "Project", "slug": "advg" } |
(Back to the Table of Contents)
Modules
No modules.
(Back to the Table of Contents)
Terraform versions
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.
Installing Tfupdate
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
Terraform version
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
Random version
tfupdate provider random . --version "~> $(tfupdate release latest hashicorp/random --source-type tfregistryProvider)" --recursive
(Back to the Table of Contents)
(Back to the Table of Contents)
Roadmap
- Support majority of Azure DevOps resources
- Test validation rules
- Include output examples in docs
- Different branch types to satisfy gitversion
- Additional examples in docs
- Feature 3
- Nested Feature
See the issues for a full list of proposed features (and known issues).
(Back to the Table of Contents)
Contributing
All are 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-azuredevops-naming) - 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.
Contributing Prerequisites
To replicate the setup used to initially create this repository you will need
-
Clone the Repo
git clone https://github.com/DownAtTheBottomOfTheMoleHole/terraform-azuredevops-naming.git -
Install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py -
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 Terraform
choco install terraform -
Install TFlint
choco install tflintAlso download the tflint plugins from github such as tflint-ruleset-azurerm and tflint-ruleset-aws put these in your
.tflint.d/pluginsdirectory at the root of your user directory -
Install terraform-docs
choco install terraform-docs -
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)
License
This module is licensed under the MIT license which can be found here: LICENSE.md
(Back to the Table of Contents)
Contact
Rolf Moleman - @RolfMoleman
Module Link: https://github.com/DownAtTheBottomOfTheMoleHole/terraform-azuredevops-naming
(Back to the Table of Contents)
