Skip to content

Commit f681727

Browse files
committed
fix name logic
1 parent 79c7559 commit f681727

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

_locals.tf

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@ locals {
1414
is_linux = lower(var.vm.os_type) == "linux"
1515
is_windows = lower(var.vm.os_type) == "windows"
1616

17-
vm_type_prefix = local.is_linux ? "lnx" : "win"
18-
# We use var.name as workload and var.vm.name_suffix as the suffix (usually 001)
19-
vm_name_raw = "vm-${local.vm_type_prefix}-${local.prefix}-${try(var.vm.name_suffix, "001")}"
20-
vm_name = coalesce(try(var.vm.name, null), substr(replace(lower(local.vm_name_raw), "/[^0-9a-z-]/", ""), 0, 64))
17+
# Resource names: use var.name directly as the full name
18+
vm_name = var.name
2119

22-
# Windows has 15 char limit; Linux is flexible, but keep consistent.
23-
# Truncate to 15 and trim trailing dashes to avoid Azure validation errors.
20+
# Windows has 15 char limit; Linux is flexible.
2421
computer_name = coalesce(try(var.vm.computer_name, null), trim(substr(local.vm_name, 0, 15), "-"))
2522

26-
nic_name = "nic-${local.vm_type_prefix}-${local.prefix}-${try(var.vm.name_suffix, "001")}"
27-
pip_name = "pip-${local.vm_type_prefix}-${local.prefix}-${try(var.vm.name_suffix, "001")}"
23+
nic_name = "nic-${local.vm_name}"
24+
pip_name = "pip-${local.vm_name}"
2825

2926
os_disk_name = coalesce(
3027
try(var.vm.os_disk.name, null),
31-
"osdisk-${local.vm_type_prefix}-${local.prefix}-${try(var.vm.name_suffix, "001")}"
28+
"osdisk-${local.vm_name}"
3229
)
3330

3431
identity_type = try(var.vm.identity.type, "SystemAssigned")

_variables.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ variable "vm" {
4848
os_type = string # linux | windows
4949

5050
name = optional(string)
51-
name_suffix = optional(string, "001")
5251

5352
size = string
5453
admin_username = string

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "azurerm_managed_disk" "data" {
3636
for_each = local.data_disks_map
3737

3838
# Default name logic if each.value.name is null
39-
name = coalesce(each.value.name, "disk-${local.vm_type_prefix}-${local.prefix}-lun${each.value.lun}-${try(var.vm.name_suffix, "001")}")
39+
name = coalesce(each.value.name, "disk-${local.vm_name}-lun${each.value.lun}")
4040
location = local.rg_loc
4141
resource_group_name = local.rg_name
4242

0 commit comments

Comments
 (0)