Skip to content

Commit cc476e9

Browse files
committed
modify azure sa name generation
1 parent 181ea21 commit cc476e9

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

cloud_Azure/terraform/module/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ NetworkWatcher is automatically created by Azure when VirtualNetwork is created
5050
| email | Kentik account email | `string` | none | yes |
5151
| token | Kentik account token | `string` | none | yes |
5252
| plan_id | Kentik billing plan ID | `string` | none | yes |
53-
| name | Cloudexport entry name in Kentik | `string` | none | yes |
53+
| name | Cloudexport entry name in Kentik will be appended with: resource_group_names and subscription_id to ensure uniqueness | `string` | none | yes |
5454
| enabled | Defines if cloud export to Kentik is enabled | `bool` | true | no |
5555
| description | Cloudexport entry description in Kentik | `string` | `Created using Terraform` | no |
5656
| resource_tag | Azure Tag value to apply to created resources | `string` | `flow_log_exporter` | no |
5757
| flow_exporter_application_id | Kentik VNet Flow Exporter application ID | `string` | `a20ce222-63c0-46db-86d5-58551eeee89f` | no |
58-
| storage_account_names | Names of Storage Accounts for storing flow logs. Names must meet Azure Storage Account naming restrictions.<br>The list should either contain 1 Storage Account name for each Resource Group, or be empty, in which case names will be generated automatically. | `list of strings` | `[]` | no |
58+
| storage_account_names | Names of Storage Accounts to be created for storing flow logs. Names must meet Azure Storage Account naming restrictions.<br>The list should either contain 1 Storage Account name for each Resource Group, or be empty, in which case names will be generated automatically. | `list of strings` | `[]` | no |
5959

6060

6161
## Outputs

cloud_Azure/terraform/module/storage_account.tf

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# Prepare names that meet Azure Storage Account naming restrictions (only alphanum letters, max 24 length, Azure-wide unique)
2-
# Each output name is concatenation of Resource Group name and Subscription ID, adjusted to naming restrictions
2+
resource "random_id" "storage_account_id" {
3+
byte_length = 6 # 6 bytes = 12 characters when base64 encoded
4+
}
5+
6+
# Each output name is concatenation of the exporter name and a random id, adjusted to naming restrictions
37
locals {
4-
_names = [for name in var.resource_group_names : "${name}${var.subscription_id}"]
8+
truncated_name = substr(var.name, 0, 12)
9+
_names = [for name in var.resource_group_names : "${truncated_name}${random_id.storage_account_id.hex}"]
510
_lowercase_names = [for name in local._names : lower(name)]
611
_alphanum_lowercase_names = [for name in local._lowercase_names : join("", regexall("[[:alnum:]]+", name))]
712
generated_storage_account_names = [for name in local._alphanum_lowercase_names : substr(name, 0, 24)]
813
}
914

15+
# Create a map of resource group names to storage account names
1016
locals {
11-
# Create a map of resource group names to storage account names
1217
resource_group_to_storage_account = {
1318
for rg in var.resource_group_names : rg => (
1419
length(var.storage_account_names) == length(var.resource_group_names) ?

0 commit comments

Comments
 (0)