|
2 | 2 | # Local declarations |
3 | 3 | #--------------------------- |
4 | 4 | locals { |
5 | | - frontend_port_name = "appgw-${var.app_gateway_name}-${data.azurerm_resource_group.rg.location}-feport" |
6 | | - frontend_ip_configuration_name = "appgw-${var.app_gateway_name}-${data.azurerm_resource_group.rg.location}-feip" |
7 | | - gateway_ip_configuration_name = "appgw-${var.app_gateway_name}-${data.azurerm_resource_group.rg.location}-gwipc" |
| 5 | + frontend_port_name = "appgw-${var.app_gateway_name}-${local.location}-feport" |
| 6 | + frontend_ip_configuration_name = "appgw-${var.app_gateway_name}-${local.location}-feip" |
| 7 | + gateway_ip_configuration_name = "appgw-${var.app_gateway_name}-${local.location}-gwipc" |
| 8 | + |
| 9 | + resource_group_name = element(coalescelist(data.azurerm_resource_group.rgrp.*.name, azurerm_resource_group.rg.*.name, [""]), 0) |
| 10 | + location = element(coalescelist(data.azurerm_resource_group.rgrp.*.location, azurerm_resource_group.rg.*.location, [""]), 0) |
8 | 11 | } |
9 | 12 |
|
10 | 13 | #---------------------------------------------------------- |
11 | 14 | # Resource Group, VNet, Subnet selection & Random Resources |
12 | 15 | #---------------------------------------------------------- |
13 | | -data "azurerm_resource_group" "rg" { |
14 | | - name = var.resource_group_name |
| 16 | +data "azurerm_resource_group" "rgrp" { |
| 17 | + count = var.create_resource_group == false ? 1 : 0 |
| 18 | + name = var.resource_group_name |
| 19 | +} |
| 20 | + |
| 21 | +resource "azurerm_resource_group" "rg" { |
| 22 | + count = var.create_resource_group ? 1 : 0 |
| 23 | + name = lower(var.resource_group_name) |
| 24 | + location = var.location |
| 25 | + tags = merge({ "ResourceName" = format("%s", var.resource_group_name) }, var.tags, ) |
15 | 26 | } |
16 | 27 |
|
17 | 28 | data "azurerm_virtual_network" "vnet" { |
18 | 29 | name = var.virtual_network_name |
19 | | - resource_group_name = data.azurerm_resource_group.rg.name |
| 30 | + resource_group_name = var.vnet_resource_group_name == null ? local.resource_group_name : var.vnet_resource_group_name |
20 | 31 | } |
21 | 32 |
|
22 | 33 | data "azurerm_subnet" "snet" { |
23 | 34 | name = var.subnet_name |
24 | 35 | virtual_network_name = data.azurerm_virtual_network.vnet.name |
25 | | - resource_group_name = data.azurerm_resource_group.rg.name |
| 36 | + resource_group_name = data.azurerm_virtual_network.vnet.resource_group_name |
26 | 37 | } |
27 | 38 |
|
28 | 39 | data "azurerm_log_analytics_workspace" "logws" { |
29 | 40 | count = var.log_analytics_workspace_name != null ? 1 : 0 |
30 | 41 | name = var.log_analytics_workspace_name |
31 | | - resource_group_name = data.azurerm_resource_group.rg.name |
| 42 | + resource_group_name = local.resource_group_name |
32 | 43 | } |
33 | 44 |
|
34 | 45 | data "azurerm_storage_account" "storeacc" { |
35 | 46 | count = var.storage_account_name != null ? 1 : 0 |
36 | 47 | name = var.storage_account_name |
37 | | - resource_group_name = data.azurerm_resource_group.rg.name |
| 48 | + resource_group_name = local.resource_group_name |
38 | 49 | } |
39 | 50 |
|
40 | 51 | #----------------------------------- |
41 | 52 | # Public IP for application gateway |
42 | 53 | #----------------------------------- |
43 | 54 | resource "azurerm_public_ip" "pip" { |
44 | | - name = lower("${var.app_gateway_name}-${data.azurerm_resource_group.rg.location}-gw-pip") |
45 | | - location = data.azurerm_resource_group.rg.location |
46 | | - resource_group_name = data.azurerm_resource_group.rg.name |
| 55 | + name = lower("${var.app_gateway_name}-${local.location}-gw-pip") |
| 56 | + location = local.location |
| 57 | + resource_group_name = local.resource_group_name |
47 | 58 | allocation_method = var.sku.tier == "Standard" ? "Dynamic" : "Static" |
48 | 59 | sku = var.sku.tier == "Standard" ? "Basic" : "Standard" |
49 | 60 | domain_name_label = var.domain_name_label |
50 | | - tags = merge({ "ResourceName" = lower("${var.app_gateway_name}-${data.azurerm_resource_group.rg.location}-gw-pip") }, var.tags, ) |
| 61 | + tags = merge({ "ResourceName" = lower("${var.app_gateway_name}-${local.location}-gw-pip") }, var.tags, ) |
51 | 62 | } |
52 | 63 |
|
53 | 64 | #---------------------------------------------- |
54 | 65 | # Application Gateway with all optional blocks |
55 | 66 | #---------------------------------------------- |
56 | 67 | resource "azurerm_application_gateway" "main" { |
57 | | - name = lower("appgw-${var.app_gateway_name}-${data.azurerm_resource_group.rg.location}") |
58 | | - resource_group_name = data.azurerm_resource_group.rg.name |
59 | | - location = data.azurerm_resource_group.rg.location |
| 68 | + name = lower("appgw-${var.app_gateway_name}-${local.location}") |
| 69 | + resource_group_name = local.resource_group_name |
| 70 | + location = local.location |
60 | 71 | enable_http2 = var.enable_http2 |
61 | 72 | zones = var.zones |
62 | 73 | firewall_policy_id = var.firewall_policy_id != null ? var.firewall_policy_id : null |
63 | | - tags = merge({ "ResourceName" = lower("appgw-${var.app_gateway_name}-${data.azurerm_resource_group.rg.location}") }, var.tags, ) |
| 74 | + tags = merge({ "ResourceName" = lower("appgw-${var.app_gateway_name}-${local.location}") }, var.tags, ) |
64 | 75 |
|
65 | 76 | sku { |
66 | 77 | name = var.sku.name |
|
0 commit comments