1
1
# Prepare names that meet Azure Storage Account naming restrictions (only alphanum letters, max 24 length, Azure-wide unique)
2
2
# Each output name is concatenation of Resource Group name and Subscription ID, adjusted to naming restrictions
3
- # Maps each storage account name to a key-value pair indexed by sa0, sa1, etc
4
3
locals {
5
- _names = [for name in var . resource_group_names : " ${ name } ${ var . subscription_id } " ]
6
- _lowercase_names = [for name in local . _names : lower (name)]
7
- _alphanum_lowercase_names = [for name in local . _lowercase_names : join (" " , regexall (" [[:alnum:]]+" , name))]
8
- generated_storage_account_names = {
9
- for i , name in local . _alphanum_lowercase_names :
10
- " sa${i}" => substr (name, 0 , 24 ) # Use the index as a key for sa creation
11
- }
4
+ _names = [for name in var . resource_group_names : " ${ name } ${ var . subscription_id } " ]
5
+ _lowercase_names = [for name in local . _names : lower (name)]
6
+ _alphanum_lowercase_names = [for name in local . _lowercase_names : join (" " , regexall (" [[:alnum:]]+" , name))]
7
+ generated_storage_account_names = [for i , name in local . _alphanum_lowercase_names : substr (name, 0 , 24 )]
12
8
}
13
9
14
10
# Creates one storage account per nsg per resource group to store flow logs
@@ -18,7 +14,7 @@ resource "azurerm_storage_account" "logs_storage_account" {
18
14
for_each = { for nsg in local . flat_nsgs : nsg . key => nsg . value }
19
15
20
16
# generate storage account per nsg(s) in each rg
21
- name = local. generated_storage_account_names [" sa ${ each . key } " ]
17
+ name = local. generated_storage_account_names [lookup (local . flat_nsgs , each. key , 0 ) ]
22
18
resource_group_name = each. value . rg
23
19
location = var. location
24
20
account_tier = " Standard"
0 commit comments