Passing variables from catalog to Terraform script templates

I want to make use of inputs from the catalog to be consumed by my terraform scripts to provision infrastructure.I am using the <“customoptions.var”> to acheive this but i can only pass variables as strings into the terraform code.
1)Can we have an option to to have the variables passed as maps, lists or sets.
2)Can I pass all the input variables(TFvars) in a file to the terraform code.If so how can that be acheived.

Are you declaring the variable type in your TF code?

@abhinay-puppaa01 ,

In the catalog configuration json, for the TFVariable replacement, you can use something like this:

"<%= customOptions.fieldName.encodeAsJson().toString() %>"

^^^ This is case sensitive ^^^

You just need to ensure you are also properly declaring your TF var type in the Terraform code for it to be parsed correctly.

Yes I have variables defined in TF files as below which are added to spec template.
eg: variable “custom_prop” {
description = “custom_prop”
type = list(any)

variable “tags” {
description = “tags”
type = map(any)

Can you let me know how these variables can be get the from the UI catalog

When you create the catalog item through the configuration wizard, any Terraform variables that you have accounted for in a TFVars via cypher or a cloud profile should show up in wizard. You can fill those out with placeholder data to complete the wizard and you will be presented with the config map json.

Within this json is a block called “templateParameter”. You can attach your inputs at the bottom of the wizard and the overwrite the placeholder data with the desired input as shown in the screenshot.

using the encodeAsJson() function for your lists and maps should get you where you need to go.

@sjabro Thanks for the reply I tried to use the variables in suggested way
variable “tags” {
description = “tags”
type = map(string)
default = “<%= customOptions.tf_aws_tags.encodeAsJson().toString()%>”
}
Var passed:


Error Recieved.
image
Can you suggest on how this can be solved i tried using map,map(string),map(any) but receiving the same Error, thanks in advance for the support

@abhinay-puppaa01

I would remove the default line from the terraform code. Morpheus will try to parse that first to see if there is something that needs to be done with it.

Test by just commenting that out just ahving the overwrite in the catalog configuration.