Working with configuration elements in code
Sooner or later every script grows a line like var maxAgeDays = 7; or, worse, a password in quotes. The value is right today, on this Orchestrator. It’s wrong on the test server, it changes next quarter, and the password shouldn’t be in a script at all. A configuration element is where those values belong: a named set of typed variables, stored on the Orchestrator server, that any workflow, action, or policy can use.
In this recipe you create two configuration elements, one for general settings and one holding the account for vc01.vmw.lab. You bind a setting to a workflow variable without any code, read the account by name from a script, pass it to the PowerCLI action from recipe 4.5, and write the time of the last report back into the settings.
Getting ready
- The action
com.vcfguide.chapter4/getSnapshotReportfrom recipe 4.5, and the read-only vCenter account it uses,svc-vcfguide-ro@vsphere.local. - The workflow folder VCF Orchestrator Guide/Chapter 4.
- A login that can create configuration elements and workflows, such as Workflow designer or administrator.
How to do it
Create a settings element
- Go to Assets > Configurations. Create the folder VCF Orchestrator Guide, and inside it Chapter 4, then select Chapter 4 and click New Configuration.
- Enter the name
vcfguide-settingsand the descriptionGeneral settings for the Chapter 4 examples. - On the Variables tab, click New for each of these, and click Save after each one:
| Name | Type | Value |
|---|---|---|
snapshotMaxAgeDays |
number |
7 |
lastSnapshotReport |
Date |
(empty) |
verbose |
boolean |
false |
- Click Save to save the element.
Create an element for the vCenter account
- Inside Chapter 4, create the folder vCenters. In it, create a configuration element named
vc01, the short name of the vCenter it describes. The client refusesvc01.vmw.lab: Configuration name cannot contain special characters, and the dots count. - On its Variables tab, add
userof typestringwith the valuesvc-vcfguide-ro@vsphere.local, andpasswordof typeSecureStringwith the account’s password. Save the element.

Checked on 9.1.1: Assets > Configurations has a New Configuration button. An element’s folder is set on its General tab, in the Folder field with a Select folder button. The Variables tab has New, Delete, Copy and Paste, and one Save at the bottom saves the whole element. A SecureString shows as asterisks.
Bind a setting to a workflow variable
- Create the workflow Report old snapshots in the folder VCF Orchestrator Guide/Chapter 4. Give it one input,
vcenterNameof typestring, with the default valuevc01.vmw.lab, and one output,reportof typestring. - On the Variables tab, click New and add the variable
maxAgeDaysof typenumber. Instead of typing a value, turn on Bind to configuration. A Configuration field replaces the value: typevcfguideand pickvcfguide-settings: snapshotMaxAgeDays. The list only offers configuration variables of the same type as the workflow variable. Click Save in the dialog, then save the workflow.

Checked on 9.1.1: once saved, the Value column of the Variables tab shows the binding as a link, vcfguide-settings: snapshotMaxAgeDays, that opens the configuration element. A run reads the value when it starts.
Read values by name from a script
- A binding is fixed when you design the workflow. To choose the element while the workflow runs, as here, where the vCenter’s name picks the account, read it in a script. In Library > Actions, create the action
getConfigElementincom.vcfguide.chapter4, with the inputscategoryPathandelementNameof typestring, and the Return typeConfigurationElement:
// Returns the configuration element elementName in the folder categoryPath,// for example "VCF Orchestrator Guide/Chapter 4". Fails if it isn't there.var category = Server.getConfigurationElementCategoryWithPath(categoryPath);if (!category) { throw "getConfigElement: no configuration folder " + categoryPath;}var elements = category.configurationElements || [];for (var i = 0; i < elements.length; i++) { if (elements[i].name === elementName) { return elements[i]; }}throw "getConfigElement: no configuration element " + elementName + " in " + categoryPath;- Create the action
getConfigValue, with the inputscategoryPath,elementName, andkeyof typestring, and the Return typeAny:
// Returns the value of one variable of a configuration element.var element = System.getModule("com.vcfguide.chapter4").getConfigElement(categoryPath, elementName);var attribute = element.getAttributeWithKey(key);if (!attribute) { throw "getConfigValue: " + elementName + " has no variable " + key;}return attribute.value;Use the values in the workflow
- On the schema of Report old snapshots, add a scriptable task, Report snapshots. Bind its inputs to
vcenterNameandmaxAgeDays, and its outputreportto the workflow outputreport. Enter this script:
var chapter4 = System.getModule("com.vcfguide.chapter4");var settingsFolder = "VCF Orchestrator Guide/Chapter 4";var vcenterFolder = settingsFolder + "/vCenters";
// The vCenter's short name (vc01 for vc01.vmw.lab) picks the element that holds its account.// Element names can't contain dots, so the full host name can't be used.var elementName = vcenterName.split(".")[0];var user = chapter4.getConfigValue(vcenterFolder, elementName, "user");var password = chapter4.getConfigValue(vcenterFolder, elementName, "password");System.log("Reading snapshots on " + vcenterName + " as " + user);
var result = chapter4.getSnapshotReport(vcenterName, user, password, maxAgeDays);report = result.get("report");System.log(result.get("count") + " snapshots older than " + maxAgeDays + " days");
// Write the time of this report back into the settingsvar settings = chapter4.getConfigElement(settingsFolder, "vcfguide-settings");settings.setAttributeWithKey("lastSnapshotReport", new Date());- Save and run the workflow with the default
vcenterName. On the run’s Variables tab,maxAgeDaysis7, taken from the binding, andreportlists the old snapshots. The log names the user, never the password. - Open
vcfguide-settingsagain.lastSnapshotReportnow holds the time of the run. - Change
snapshotMaxAgeDaysto30, save, and run the workflow again. It now reports only snapshots older than 30 days, without any change to the workflow.

Checked on 9.1.1 in the lab: setAttributeWithKey on an existing variable saves the new value at once, with no separate save call, and lastSnapshotReport keeps the type Date. The password read with getAttributeWithKey is an attribute of type SecureString whose value is the plain text, and the PowerCLI action receives it as a plain string and connects with it.
How it works
A configuration element is a named list of typed variables, which the scripting API calls attributes, stored in Orchestrator’s database. Every workflow, action, and policy on the server can use it. Configuration elements sit in folders, which the API calls categories. A category’s path is its folder names joined with /, so the folder you created in step 5 is VCF Orchestrator Guide/Chapter 4/vCenters.
There are two ways to get at the values, and they suit different jobs:
- Binding, as in step 8, links a workflow variable to one variable of one element. You choose both when you design the workflow. The workflow shows the link, and when you put the workflow in a package, Orchestrator adds the configuration element automatically. Use it for settings that every run uses, such as
snapshotMaxAgeDays. - Scripting, as in steps 9 to 11, finds the element by its folder and name while the run is going.
Server.getConfigurationElementCategoryWithPathreturns the category, ornullif there’s none. ItsconfigurationElementsproperty lists the elements in it, or isnullwhen the folder is empty (checked on 9.1.1), which is why step 9 writescategory.configurationElements || []. An element’sgetAttributeWithKeyreturns the attribute, whosevalueholds the value. Use it when the run decides which element it needs, as with one element per vCenter. A package doesn’t know about elements that a script finds by name, so add them to the package yourself (Chapter 6).
setAttributeWithKey writes a value back. It changes the element on the server for everyone: the next run, and any run going on at the same time, sees the new value. It’s meant for occasional state, like the time of the last report, not for something many runs change at once.
When the variable doesn’t exist yet, setAttributeWithKey(key, value) creates it with a type guessed from the value, and a password becomes a plain string. Pass the type as a third argument to get it right: element.setAttributeWithKey("password", secret, "SecureString"). On 9.1.1, a password added without that third argument showed up in the client as a readable string.
SecureString. A SecureString value is stored encrypted and hidden in the client. Inside a script it’s an ordinary string, because the script needs the real value to use it. That’s why the script logs the user and never the password (recipe 4.6). Anyone who can run a script that reads the element can read the password, so protect the folder with permissions, and give the account no more rights in vCenter than the workflow needs.
Values belong to the server. When you import a package that contains a configuration element, you can choose whether to import its values as well. Import the element without the test server’s values into production, enter the production values once, and the workflows never need to change.
There's more
Keep the paths in one place. The folder names in step 11 are a contract between the workflow and whoever manages the elements. If you use them in many workflows, put them in one small action that returns the path, so that renaming a folder means changing one line.
One element per target. An element per vCenter, per NSX Manager, or per environment, with the same variable names in each, makes a script that works for all of them. Adding a vCenter means adding an element, not changing code.
Changes from many runs. If several runs might update the same variable at once, for example a counter, two of them can read the same old value and both write old value + 1. Wrap the read and the write in a lock: LockingSystem.lockAndWait("vcfguide-settings", workflow.id) before, and LockingSystem.unlock("vcfguide-settings", workflow.id) in a finally block after.
Python, Node.js, and PowerShell actions can’t read elements. The configuration element API exists only in JavaScript. Read the values in a JavaScript script or with a binding, and pass them to the polyglot action as inputs, as step 11 does for the PowerCLI action.
Configuration elements, resource elements, or system properties? Use a configuration element for typed values that workflows read. Use a resource element (Chapter 6) for a whole file, such as a template or a script. System properties (recipe 2.8) are for the server’s own behaviour, not for your workflows’ settings.
Changing values from outside. The Orchestrator REST API can read and update configuration elements, so a pipeline or another tool can set values without the client. That’s how you’d load the production values after importing a package without them.
On 9.1.1, GET /vco/api/configurations/{id} returns the element with its attributes, and PUT on the same path saves it. The PUT replaces the whole list of attributes, so send every attribute back, not just the one you change, or the others are deleted. Read the element, change the one value, and put the whole thing back.
A GET never shows a password. A SecureString attribute comes back encrypted, with a flag that says so:
{ "name": "password", "type": "SecureString", "value": { "secure-string": { "value": "14BI43U6FO64…", "isPlainText": false } }}Sent back unchanged in a PUT, the encrypted value stays as it is. To set a new password from outside, send the plain text with "isPlainText": true:
{ "name": "password", "type": "SecureString", "value": { "secure-string": { "value": "the-new-password", "isPlainText": true } } }Both were checked on 9.1.1: after the plain-text PUT, a script read the new password, and a GET returned it encrypted with "isPlainText": false. The PUT body also takes version, so a pipeline can bump the element’s version in the same call. Keep the plain-text password out of your shell history and logs: read it from a file or a secret store, not the command line.
See also
- 4.5 PowerShell and PowerCLI actions, for the action this workflow calls.
- 4.6 Logging from scripts, for what not to log.
- 2.8 Setting system properties that matter, for server settings that aren’t configuration elements.
- Broadcom TechDocs (VCF 9.0): Managing Configuration Elements.
- VMware Docs (Aria Automation Orchestrator 8.17): Create a configuration element. Broadcom TechDocs (8.18): Create and apply policies, which mentions Bind to configuration.
- Christian Stankowic: vRealize Orchestrator configuration elements in a nutshell, on reading elements from scripts.
- CloudBlogger, the author’s blog: vRO Configuration Element: Creation using CSV Import/Export.
