Skip to content

Commit 98be850

Browse files
committed
need to create 1 unique storage account per nsg per rg to store flow logs
1 parent 7dafd2a commit 98be850

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

cloud_Azure/terraform/module/network_watcher.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ locals {
5555

5656
# Turns on flow logs for all network security groups in requested resource groups
5757
resource "azurerm_network_watcher_flow_log" "kentik_network_flow_log" {
58-
for_each = { for i in local.flat_nsgs : i.key => i.value }
58+
for_each = { for nsg in local.flat_nsgs : nsg.key => nsg.value }
5959

6060
name = "${var.name}_flow_log_${each.value.name}"
6161
network_watcher_name = data.azurerm_network_watcher.network_watcher.name

cloud_Azure/terraform/module/storage_account.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ locals {
77
generated_storage_account_names = [for name in local._alphanum_lowercase_names : substr(name, 0, 24)]
88
}
99

10-
# Creates one storage account per resource group to store flow logs
11-
# StorageAccounts are mapped 1:1 to resource_group_names and this fact is used to get storage account id for given resource group name
10+
# Creates one storage account per nsg per resource group to store flow logs
11+
# StorageAccounts are mapped 1:1+:1 to nsg(s) and resource_group_names
12+
# Note that only one flow log can be associated with a storage account per region
1213
resource "azurerm_storage_account" "logs_storage_account" {
13-
for_each = { for s, rg in var.resource_group_names : rg => s }
14+
for_each = { for nsg in local.flat_nsgs : nsg.key => nsg.value }
1415

15-
# use either custom name if one is provided, or generate one
16-
name = length(var.storage_account_names) == length(var.resource_group_names) ? var.storage_account_names[each.value] : local.generated_storage_account_names[each.value]
17-
resource_group_name = each.key
16+
# generate storage account per nsg per rg
17+
name = local.generated_storage_account_names[each.value]
18+
resource_group_name = each.value.rg
1819
location = var.location
1920
account_tier = "Standard"
2021
account_replication_type = "GRS"

cloud_Azure/terraform/module/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ variable "flow_exporter_application_id" {
6363
type = string
6464
default = "a20ce222-63c0-46db-86d5-58551eeee89f"
6565
description = "Kentik NSG Flow Exporter application ID"
66-
}
66+
}

0 commit comments

Comments
 (0)