aztfmod / terraform-provider-azurecaf

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

How to regenerate random #185

Open sdahlbac opened 1 year ago

sdahlbac commented 1 year ago
    azurecaf = {
      source  = "aztfmod/azurecaf"
      version = "2.0.0-preview-3"
    }

I have e.g.

resource "azurecaf_name" "db" {
  name          = "fabric"
  prefixes      = [terraform.workspace]
  resource_type = "azurerm_postgresql_flexible_server"
  random_length = 5
}

Based on the documentation I thouht that not specifying a random_seed would use the timestamp as the seed, and thus would produce different random_string.

but no matter what I do I still get yodgp?

LaurentLesle commented 1 year ago

Testing with my latest version 1.x with the new data source (coming in the next release). Please confirm this is what you are expecting.

Same random_seed -> same suffix

data "azurecaf_name" "pfs" {
  name          = "fabric"
  resource_type = "azurerm_postgresql_flexible_server"
  prefixes      = ["apac"]
  random_seed   = 3
  random_length = 5
}

data "azurecaf_name" "vm" {
  name          = "fabric"
  resource_type = "azurerm_resource_group"
  prefixes      = ["apac"]
  random_seed   = 3
  random_length = 5
}

output "pfs" {
  value = data.azurecaf_name.pfs.result
}
output "vm" {
  value = data.azurecaf_name.vm.result
}
data.azurecaf_name.pfs: Reading...
data.azurecaf_name.vm: Reading...
data.azurecaf_name.pfs: Read complete after 0s [id=apac-psqlf-fabric-icvac]
data.azurecaf_name.vm: Read complete after 0s [id=apac-rg-fabric-icvac]

Changes to Outputs:
  + pfs = "apac-psqlf-fabric-icvac"
  + vm  = "apac-rg-fabric-icvac"

Different random_seed -> different suffixes

data "azurecaf_name" "pfs" {
  name          = "fabric"
  resource_type = "azurerm_postgresql_flexible_server"
  prefixes      = ["apac"]
#   random_seed   = 3
  random_length = 5
}

data "azurecaf_name" "vm" {
  name          = "fabric"
  resource_type = "azurerm_resource_group"
  prefixes      = ["apac"]
#   random_seed   = 3
  random_length = 5
}

output "pfs" {
  value = data.azurecaf_name.pfs.result
}
output "vm" {
  value = data.azurecaf_name.vm.result
}
data.azurecaf_name.vm: Reading...
data.azurecaf_name.pfs: Reading...
data.azurecaf_name.vm: Read complete after 0s [id=apac-rg-fabric-ewywm]
data.azurecaf_name.pfs: Read complete after 0s [id=apac-psqlf-fabric-rtfev]

Changes to Outputs:
  + pfs = "apac-psqlf-fabric-rtfev"
  + vm  = "apac-rg-fabric-ewywm"
sdahlbac commented 1 year ago

kinda, but what I was having issues with was the Different random_seed -> different suffixes

terraform apply (produced eg. yodgp) terraform destroy terraform apply (still produced yodgp)