feat(tags): merge custom and default tags per environment

This commit is contained in:
Julie Ng 2022-05-01 15:35:32 +02:00
Родитель efda638343
Коммит e3a2c9557c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 0CBC37BD160B350D
6 изменённых файлов: 45 добавлений и 6 удалений

14
environments/README.md Normal file
Просмотреть файл

@ -0,0 +1,14 @@
# Environments Configuration (Optional)
Define specific variables per environment. Currently used for Azure Resource tags, e.g. `env=dev` vs `env=prod`.
These custom tags are merged into defaults defined in [`/variables.tf`](./../variables.tf)
### Usage example
These values need to be explicitly specified via `-var-file` flag, e.g.
```
terraform plan -var-file=environments/dev.tfvars -out plan.tfplan
terraform apply plan.tfplan
```

6
environments/dev.tfvars Normal file
Просмотреть файл

@ -0,0 +1,6 @@
custom_tags = {
demo-version = "v0.5.0"
env = "dev"
devops-org = "julie-msft"
github = "azure/devops-governance"
}

6
environments/prod.tfvars Normal file
Просмотреть файл

@ -0,0 +1,6 @@
custom_tags = {
demo-version = "v0.5.0"
env = "production"
devops-org = "julie-msft"
github = "azure/devops-governance"
}

Просмотреть файл

@ -16,6 +16,7 @@ locals {
suffix = random_string.suffix.result suffix = random_string.suffix.result
application_owners_ids = length(var.application_owners_ids) == 0 ? [data.azurerm_client_config.current.object_id] : var.application_owners_ids application_owners_ids = length(var.application_owners_ids) == 0 ? [data.azurerm_client_config.current.object_id] : var.application_owners_ids
superadmins_aad_object_id = var.superadmins_aad_object_id == "" ? data.azurerm_client_config.current.object_id : var.superadmins_aad_object_id # Default to current ARM client superadmins_aad_object_id = var.superadmins_aad_object_id == "" ? data.azurerm_client_config.current.object_id : var.superadmins_aad_object_id # Default to current ARM client
tags = merge(var.default_tags, var.custom_tags)
} }
# ================= # =================
@ -56,6 +57,7 @@ module "arm_environments" {
admins_group_id = azuread_group.groups["${each.value.team}_admins"].id admins_group_id = azuread_group.groups["${each.value.team}_admins"].id
superadmins_group_id = local.superadmins_aad_object_id superadmins_group_id = local.superadmins_aad_object_id
service_principal_id = module.service_principals["${each.value.team}_${each.value.env}"].principal_id service_principal_id = module.service_principals["${each.value.team}_${each.value.env}"].principal_id
tags = local.tags
} }
# ============== # ==============

Просмотреть файл

@ -49,12 +49,6 @@ variable "client_object_id" {
variable "tags" { variable "tags" {
description = "Tags to apply to Azure Resources" description = "Tags to apply to Azure Resources"
type = map(string) type = map(string)
default = {
demo = "governance"
devops = "true"
oss = "terraform"
public = "true"
}
} }
data "azurerm_client_config" "current" {} data "azurerm_client_config" "current" {}

Просмотреть файл

@ -26,3 +26,20 @@ variable "projects" {
variable "environments" { variable "environments" {
type = map(map(string)) type = map(map(string))
} }
variable "default_tags" {
description = "Tags to apply to Azure Resources"
type = map(string)
default = {
public = "true"
demo = "e2e-governance"
iac = "terraform"
ci = "azure-pipelines"
}
}
variable "custom_tags" {
description = "Extra Tags to apply to Azure Resources"
type = map(string)
default = {}
}