Hello team,
I wan’t to use a ternary operator as described in Variables — Morpheus Docs documentation (morpheusdata.com) for me to choose wether or not to install the agent. My code in the json catalog is : is :
[...]
"config": {
"poolProviderType": null,
"isVpcSelectable": true,
"smbiosAssetTag": null,
"isEC2": false,
"resourcePoolId": "<%= customOptions.vmwareResourcePool %>",
"hostId": null,
"createUser": false,
"nestedVirtualization": null,
"vmwareFolderId": "<%= customOptions.vmwareFolder %>",
"noAgent": "${ instance.instanceContext.take(1) == 'i' ? 'true' : 'false' }"
}
[...]
But it doesn’t work (the resulting catalog is empty)
is it possible ? what is the right syntax ?
My second option would be the creation of a true/false option list with a translation script that “select” the right value itself by checking the envirronment, but i’d realy love not to have to add such an option list.
regards,
Matthieu
Hi Matthieu,
The correct format would be
"<%= if(instance.instanceContext.take(1) == 'i') {true} else {false} %>"
However, the instanceContext
variable is not evaluating for some reason which I will need to investigate.
This is how I made it work in my testing. I used an option list API type for Environments (Screen Shot on 2024-02-01 at 10-47-12 pm.png - Droplr) and created a Select List type input for it and then used this instead in my catalog config,
"<%= if(customOptions.morphenv.take(1) == 'i') {true} else {false} %>"
You will need to attach the input to the catalog and replace the "environment"
value with the customOption. This is what my config looks like and it works just fine.
...
"config": {
"createUser": true,
"isEC2": false,
"isVpcSelectable": true,
"smbiosAssetTag": null,
"nestedVirtualization": null,
"hostId": null,
"noAgent": "<%= if(customOptions.morphenv.take(1) == 'i') {true} else {false} %>",
"vmwareFolderId": "/",
"template": 539,
"expose": 8080,
"resourcePoolId": "pool-1611",
"poolProviderType": null,
"executeMode": "executeHost"
},
"environment": "<%=customOptions.morphenv%>",
...
Thanks
Deepti
Thank you for the tip. It works perfectly with an extra input.
regards,
Matthieu
1 Like