aztfmod / terraform-provider-azurecaf

Terraform provider for the Terraform platform engineering for Azure
173 stars 92 forks source link

Windows VMSS Computer Prefix Exceed character limit #93

Closed jorseng closed 3 years ago

jorseng commented 3 years ago

image

I hit the above character limit error when defining computer_prefix for azurerm_windows_virtual_machine_scale_set in the module.

The following is the azurecaf_name code used.

resource "azurecaf_name" "windows_computer_name_prefix" {
  for_each = local.os_type == "windows" ? var.settings.vmss_settings : {}

  name          = try(each.value.computer_name, each.value.name)
  resource_type = "azurerm_virtual_machine_scale_set"
  prefixes      = var.global_settings.prefixes
  random_length = var.global_settings.random_length
  clean_input   = true
  passthrough   = var.global_settings.passthrough
  use_slug      = var.global_settings.use_slug
}

and here is the segment of the code which is raising the error

resource "azurerm_windows_virtual_machine_scale_set" "vmss" {
  for_each = local.os_type == "windows" ? var.settings.vmss_settings : {}

  name                = azurecaf_name.windows[each.key].result
  location            = var.location
  resource_group_name = var.resource_group_name
  sku                 = each.value.sku
  instances           = each.value.instances
  admin_username      = try(each.value.admin_username_key, null) == null ? each.value.admin_username : local.admin_username
  admin_password      = try(each.value.admin_password_key, null) == null ? random_password.admin[local.os_type].result : local.admin_password
  tags                = merge(local.tags, try(each.value.tags, null))

  #TODO: Standardize the prefix length?
  computer_name_prefix            = azurecaf_name.windows_computer_name_prefix[each.key].result
  eviction_policy                 = try(each.value.eviction_policy, null)
  max_bid_price                   = try(each.value.max_bid_price, null)
  priority                        = try(each.value.priority, null)
  provision_vm_agent              = try(each.value.provision_vm_agent, true)
  zones                           = try(each.value.zones, null)
  custom_data                     = try(each.value.custom_data, null) == null ? null : filebase64(format("%s/%s", path.cwd, each.value.custom_data))
  proximity_placement_group_id    = try(var.proximity_placement_groups[var.client_config.landingzone_key][each.value.proximity_placement_group_key].id, var.proximity_placement_groups[each.value.proximity_placement_groups].id, null)
  }
Nepomuceno commented 3 years ago

Can you post the actual value that it is in your state file for windows_computer_name_prefix this will make easier for me to debug and check the problem You can use the state show command to capture the state file values https://www.terraform.io/docs/cli/commands/state/show.html

jorseng commented 3 years ago

Hi @Nepomuceno , requested value as below:

"module": "module.example.module.virtual_machine_scale_sets[\"vmss2\"]",
      "mode": "managed",
      "type": "azurecaf_name",
      "name": "windows_computer_name_prefix",
      "provider": "provider[\"registry.terraform.io/aztfmod/azurecaf\"]",
      "instances": [
        {
          "index_key": "windows",
          "schema_version": 3,
          "attributes": {
            "clean_input": true,
            "id": "dmpwvrkrldsdbida",
            "name": "win",
            "passthrough": false,
            "prefixes": [
              "test"
            ],
            "random_length": 0,
            "random_seed": null,
            "resource_type": "azurerm_virtual_machine_scale_set",
            "resource_types": null,
            "result": "test-vmss-win",
            "results": {},
            "separator": "-",
            "suffixes": null,
            "use_slug": true
          },