From 71de488ac90edf3afbe2d29a27e11ff80321ef6d Mon Sep 17 00:00:00 2001 From: Jarrod Ribble Date: Wed, 29 Nov 2023 11:42:04 -0800 Subject: [PATCH] feat: Azure location override (#97) * Add a variable that allows creating resources in a different location than the resource group. * Change the variable name to azure_location for consistency. Add azure_location to the optional variable list. * Make terraform format check happy with spaces. --- README.md | 3 ++- main.tf | 16 ++++++++++------ variables.tf | 6 ++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e62da63..62764f9 100644 --- a/README.md +++ b/README.md @@ -171,4 +171,5 @@ One goal of this module is to minimize the number of customizations needed in or | [event\_handler\_image\_tag](#event\_handler\_image\_tag) | Event-Handler image tag to use from [GitHub Packages](https://github.com/liatrio/terraform-azure-github-runner/pkgs/container/github-webhook-runner-controller) | `string` | latest | | [runner\_controller\_image\_tag](#runner\_controller\_image\_tag) | Runner-Controller image tag to use from [GitHub Packages](https://github.com/liatrio/terraform-azure-github-runner/pkgs/container/github-webhook-runner-controller) | `string` | latest | | [github\_runner\_group](#github\_runner\_group) | Runner Group to register runners to | `string` | Default | -| [tags](#tags) | Map of tags that will be added to created resources | `map(string)` | {} | \ No newline at end of file +| [tags](#tags) | Map of tags that will be added to created resources | `map(string)` | {} | +| [azure_location](#azure_location) | Azure location in which to create resources | `string` | location of the resource group \ No newline at end of file diff --git a/main.tf b/main.tf index 27ea944..5fa18ad 100644 --- a/main.tf +++ b/main.tf @@ -6,11 +6,15 @@ data "azurerm_resource_group" "resource_group" { name = var.azure_resource_group_name } +locals { + location = var.azure_location == "" ? data.azurerm_resource_group.resource_group.location : var.azure_location +} + #tfsec:ignore:azure-keyvault-specify-network-acl #tfsec:ignore:azure-keyvault-no-purge resource "azurerm_key_vault" "github_runner_registration_keyvault" { name = "kv-gh-run-reg${local.name_suffix}" - location = data.azurerm_resource_group.resource_group.location + location = local.location resource_group_name = data.azurerm_resource_group.resource_group.name tenant_id = var.azure_tenant_id @@ -36,7 +40,7 @@ resource "azurerm_key_vault_access_policy" "app_secrets_key_vault_access_policy" } resource "azurerm_user_assigned_identity" "github_runner_shared_identity" { - location = data.azurerm_resource_group.resource_group.location + location = local.location resource_group_name = data.azurerm_resource_group.resource_group.name name = "msi-github-runner-shared-identity${local.name_suffix}" @@ -60,7 +64,7 @@ module "service_bus" { github_runner_identifier_label = var.github_runner_identifier_label name_suffix = local.name_suffix - azure_resource_group_location = data.azurerm_resource_group.resource_group.location + azure_resource_group_location = local.location azure_resource_group_name = data.azurerm_resource_group.resource_group.name tags = var.tags } @@ -74,7 +78,7 @@ module "app_config" { azure_registration_key_vault_name = azurerm_key_vault.github_runner_registration_keyvault.name azure_registration_key_vault_url = azurerm_key_vault.github_runner_registration_keyvault.vault_uri - azure_resource_group_location = data.azurerm_resource_group.resource_group.location + azure_resource_group_location = local.location azure_resource_group_name = data.azurerm_resource_group.resource_group.name azure_subnet_id = var.azure_subnet_id azure_subscription_id = var.azure_subscription_id @@ -115,7 +119,7 @@ module "github_webhook_event_handler_function_app" { app_configuration_endpoint = module.app_config.app_configuration_endpoint azure_app_configuration_object_id = module.app_config.azure_app_configuration_object_id azure_resource_group_name = data.azurerm_resource_group.resource_group.name - azure_resource_group_location = data.azurerm_resource_group.resource_group.location + azure_resource_group_location = local.location docker_registry_url = var.docker_registry_url event_handler_image_name = var.event_handler_image_name event_handler_image_tag = var.event_handler_image_tag @@ -136,7 +140,7 @@ module "github_runner_controller_web_app" { azure_resource_group_name = data.azurerm_resource_group.resource_group.name azure_resource_group_id = data.azurerm_resource_group.resource_group.id - location = data.azurerm_resource_group.resource_group.location + location = local.location web_app_os_type = var.web_app_os_type web_app_sku_name = var.web_app_sku_name docker_registry_url = var.docker_registry_url diff --git a/variables.tf b/variables.tf index b33573e..505bc10 100644 --- a/variables.tf +++ b/variables.tf @@ -173,3 +173,9 @@ variable "tags" { type = map(string) default = {} } + +variable "azure_location" { + description = "The location in which to create resources. Will default to the resource group's location." + type = string + default = "" +}