Variables passed to terraform are not always substituted

I have this piece of code (taken from the examples basically):

locals {
  default_tags = {
    provisionedby      = "<%=username%>"
    environment        = "<%=customOptions.environment%>"
    ManagementTool     = "Terraform"
    ManagementPlatform = "Morpheus"
  }
}

Nothing gets substituted on the plan stage and later, VM gets created with tags that literally have <%=username%> as value

At same time this piece of code:

variable "prefix" {
  description = "The prefix which should be used for all resources in this example"
  default     = "<%=instance.hostname%>"
}

variable "location" {
  description = "The Azure Location (Region) in which all resources in this example should be created."
  default     = "<%=customOptions.location%>"
}

works fine, variables are substituted correctly.

Using Morpheus 6.0.1

I believe I’ve only seen username utilized for naming policies (could work elsewhere situationally). Have you tried the following variables?

  1. <%=instance.createdByUsername%>
  2. <%=user.username%>

Still same problem, plan I get:

      + tags                          = {
          + "ManagementPlatform" = "Morpheus"
          + "ManagementTool"     = "Terraform"
          + "environment"        = "<%=customOptions.environment%>"
          + "owner"              = "<%=user.username%>"
          + "provisionedby"      = "<%=instance.createdByUsername%>"
        }

code I have (in git repo):

locals {
  default_tags = {
    owner = "<%=user.username%>"
    provisionedby      = "<%=instance.createdByUsername%>"
    environment        = "<%=customOptions.environment%>"
    ManagementTool     = "Terraform"
    ManagementPlatform = "Morpheus"
  }
}

How are you deploying this currently? Is this a Terraform App Blueprint? Terraform Spec Instance? Or a Morpheus App Blueprint with 1 or more Terraform Spec Instances select? (Confusing I know :slight_smile: )

It’s instance from spec template

I did some testing in 6.1.2 and it seems to be working for me. Not sure if this is an issue with 6.0.1 or something else. I did look through the release notes and not finding anything that looks related to this. Unfortunately i don’t have a 6.0.1 running to quickly test against.

Using your locals example below both the user variable examples produce the desired results.

locals {
default_tags = {
owner = “<%=instance.createdByUsername%>”
provisionedby = “<%=username%>”
#environment = “<%=customOptions.environment%>”
ManagementTool = “Terraform”
ManagementPlatform = “Morpheus”
}
}

My tags definition on the resource using these tags looks like this.

tags = merge(
local.default_tags,
{
mytest = var.mytest
},
)

The above worked using both the user variables. Here is the output from the Instance provision plan
image

Thanks for trying! We’ll update and see if this fixed it.

Updated to 6.2.0
Problem remains unfortunately

I wanted to capture screenshot of terraform plan, but now instance creation is completely broken. I’m getting this error:

Error! prepare instance error: Cannot get property 'output' on null object

It worked once after upgrade.

I created support case 71527