terraform-provider-azurecaf icon indicating copy to clipboard operation
terraform-provider-azurecaf copied to clipboard

r/azurecaf_name: random_length is not working as documented

Open t3mi opened this issue 3 years ago • 4 comments

To make random_length property to work, one should calculate the difference between max characters available for the resource and all other higher priority items like slug, name, prefixes, suffixes. random_length should be set to that diff number or less, otherwise - it will be ignored from the name at all which makes no sense.

terraform {
  required_providers {
    azurecaf = {
      source  = "aztfmod/azurecaf"
      version = "~> 1.0"
    }
  }
}

resource "azurecaf_name" "example" {
  name          = "00000"
  random_length = 50
  resource_type = "azurerm_storage_account"
}

output "test" {
  value = azurecaf_name.example.result
}

Expected: Value extended with random characters up to the max available count (24 for storage account).

st00000kwtfv13g90nvqwi29

Actual:

Outputs:

test = st00000

t3mi avatar Dec 23 '21 18:12 t3mi

Totally agree on this!

My use case is very similar, I'm doing:

resource "azurecaf_name" "key_vault" {
   name          = var.application_name
   resource_type = "azurerm_key_vault"
   suffixes      = ["dev"]
}

And if my application name is too big, instead of having:

kvabcdefghijklmnopqrsdev

(using the kv prefix and devsuffix)

I'm having:

kvdev

jdubois avatar Jan 19 '22 21:01 jdubois

@Nepomuceno any chance you can have a look on this one? :)

arnaudlh avatar Feb 14 '22 07:02 arnaudlh

This is related to #24 it is interesting to think about how this should actually work. Will put some options so you can have freedon to control how the truncate happens in these cases makes sense to change this the way that it is working it is not ideal but at the same time questions if the random lengh it is too long but the suffix it is not should I cutr the random and include as most of it as I can or should I cut it entirely and try to insert the postfix. Or shoudl I actually give an eerror when trying to generate a name that si bigger than the max name size.

Nepomuceno avatar May 03 '22 05:05 Nepomuceno

bump. any update on this @Nepomuceno?

prov-tommy-dunn avatar Jun 13 '23 20:06 prov-tommy-dunn