Skip to content

Commit

Permalink
feat: Azure location override (#97)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jribble authored Nov 29, 2023
1 parent eb50504 commit 71de488
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@ One goal of this module is to minimize the number of customizations needed in or
| <a name="event_handler_image_tag"></a> [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 |
| <a name="runner_controller_image_tag"></a> [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 |
| <a name="github_runner_group"></a> [github\_runner\_group](#github\_runner\_group) | Runner Group to register runners to | `string` | Default |
| <a name="tags"></a> [tags](#tags) | Map of tags that will be added to created resources | `map(string)` | {} |
| <a name="tags"></a> [tags](#tags) | Map of tags that will be added to created resources | `map(string)` | {} |
| <a name="azure_location"></a> [azure_location](#azure_location) | Azure location in which to create resources | `string` | location of the resource group
16 changes: 10 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}"
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}

0 comments on commit 71de488

Please sign in to comment.