Need help getting failing variable values for troubleshooting

I have a value containing the users first and lastname that passes into the terraform code and I have locals that performs some string manipulation to get first initial of first name and first four of last name:

resource "random_string" "random_id" {
  length  = 4
  lower   = true
  upper   = true
  numeric  = true
  special = false

locals {
  name_parts = split(var.full_name, " ")
  first_name = element(local.name_parts, 0)
  last_name = element(local.name_parts, 1)
  first_initial = lower(substr(local.first_name, 0, 1))
  last_four = lower(substr(local.last_name, 0, 4))
  short_name = join("", ["${local.first_initial}","${local.last_four}"])
  unique_identifier = "${local.short_name}-${}"

I verified from the error output that var.full_name contains a named like “John Wick” and that the random_string resource is generating an alphanumeric string, however when I try to provision a resource group in azure with code

resource "azurerm_resource_group" "rg" {
  name     = "tevm-${local.unique_identifier}-rg"
  location = var.region

I get the error

Error: "name" may only contain alphanumeric characters, dash, underscores, parentheses and periods 
  with azurerm_resource_group.rg, 
  on line 10, in resource "azurerm_resource_group" "rg": 
  10:   name     = "tevm-${local.unique_identifier}-rg" 

The goal is if a name like “John Wick” gets passed in, the unique_identifier produced is “jwick-Hs2d”, with the last bit being the alphanumeric identifier.

I tried making an output to debug the value but it just tells me the output would be available only after apply, which doesn’t help me when my apply is failing midway. The plan works successfully.

Any help would be much appreciated!

Hi @mrdelicate,

Your split arguments are reversed, so you are only operating on " " for the rest of the transformations.

To debug this, you can make a small config with only the random_string and values you referenced above, and just dump all the local values you need in an output object. This way there’s no azure resources to fail, and you can quickly iterate with only the test values.