Using the region passed as gh workflow input

This commit is contained in:
Jose Luis Carrillo Aguilar 2022-10-13 16:29:34 +02:00
Родитель df60e78fe6
Коммит b2ecf7b292
4 изменённых файлов: 17 добавлений и 4 удалений

4
.github/workflows/IaC-terraform-AKS.yml поставляемый
Просмотреть файл

@ -122,7 +122,7 @@ jobs:
else
./terraform init -upgrade
fi
eval ./terraform plan ${parameter_files} -var 'tags={repo_environment=\"$ENVIRONMENT\"}' -out tfdeployplan
eval ./terraform plan ${parameter_files} -var 'tags={repo_environment=\"$ENVIRONMENT\"}' -var 'regions=[\"${{ github.event.inputs.REGION\"]' -out tfdeployplan
- name: Deploy Standalone
if: ${{ github.event.inputs.DEPLOY == 'true' }}
@ -171,7 +171,7 @@ jobs:
parameter_files=$(find configuration -not -path "*launchpad*" | grep .tfvars | sed 's/.*/-var-file &/' | xargs)
echo "parameter_files: ${parameter_files}"
eval ./terraform plan ${parameter_files} -var 'tags={repo_environment=\"$ENVIRONMENT\"}' -destroy -out tfdestroyplan
eval ./terraform plan ${parameter_files} -var 'tags={repo_environment=\"$ENVIRONMENT\"}' -var 'regions=[\"${{ github.event.inputs.REGION\"]' -destroy -out tfdestroyplan
- name: Diagnostics purge
if: ${{ github.event.inputs.DESTROY == 'true' }}

7
IaC/terraform/locals.tf Normal file
Просмотреть файл

@ -0,0 +1,7 @@
locals {
global_settings = length(var.regions) == 0 ? var.global_settings : {
default_region = "region1"
regions = { for region in var.regions : "region${index(var.regions, region) + 1}" => region }
passthrough = true
}
}

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

@ -8,7 +8,7 @@ module "caf" {
providers = {
azurerm.vhub = azurerm.vhub
}
global_settings = merge((var.override_prefix == "" ? {} : { prefix = var.override_prefix }), var.global_settings)
global_settings = merge((var.override_prefix == "" ? {} : { prefix = var.override_prefix }), local.global_settings)
logged_user_objectId = var.logged_user_objectId
tags = var.tags
resource_groups = var.resource_groups

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

@ -6,11 +6,17 @@ variable "global_settings" {
random_length = 4
default_region = "region1"
regions = {
region1 = "southeastasia"
region1 = "eastus"
}
}
}
variable "regions" {
description = "global_settings Azure regions comma separated"
type = list(string)
default = []
}
variable "resource_groups" {
default = {}
}