aztfmod / terraform-provider-azurecaf

Terraform provider for the Terraform platform engineering for Azure
172 stars 91 forks source link

r/azurecaf_name: random_length is not working as documented #144

Open t3mi opened 2 years ago

t3mi commented 2 years ago

To make _randomlength 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. _randomlength 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
jdubois commented 2 years ago

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
arnaudlh commented 2 years ago

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

Nepomuceno commented 2 years ago

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.

prov-tommy-dunn commented 1 year ago

bump. any update on this @Nepomuceno?