Syntax

A policy template consists of a sequence of definitions. Definitions may be simple definitions of the form:

<name> <term>

Where <name> is the name of the definition and <term> is a term, for example:

short_description "Limit the total number of VMs running in a project." 

Terms can be literal values like in the example above, function calls, certain reserved words or in some cases references to other definitions.

Definitions may also be composite definitions of the form:

<name> <term> [, <property>: <string literal>] do

   <property> <term>

   <property> <term>

   …

end

Where <property> is the name of a definition property, for example:

parameter "max_instances" do 

   type "number" 

   label "Maximum number of instances" 

end 

or

resources "instances", type: "rs_cm.instances" do 

   cloud_href href(@clouds

   state "operational" 

end 

Click the appropriate link to learn more about definitions for:

Comments
Reserved Words
String Literals
Number Literals
Array Literals
Object Literals

Comments

Comments start with the character #. They may appear at the end of a line or on a new line:

short_description "Limit number of VMs." # Note: only works on cloud X

# Comment on a new line 

Reserved Words

The Policy Template Language also defines a few reserved words that make it possible to retrieve contextual information or iterate over data collections. The list of complete reserved words and their usage is described in the Reserved Word Reference. For example rs_org_id returns the ID of the RightScale organization.

String Literals

A string literal begins and ends with a double or single-quote mark. Double-quoted string expressions are subject to backslash notation. A single-quoted string expression isn't; except for \' and \.

For more information, see:

Backslash Notation
Multiline String Literals

Backslash Notation

Also called escape characters, backslashes are used to insert special characters in a string.

Example:

"this is a\ntwo line string" 

"this string has \"quotes\" in it" 

Backslash Notation

Escape Sequence

Meaning

\n

newline

\s

space

\r

carriage return

\t

tab

\”

double quote character

\’

single quote character

\

backslash

Multiline String Literals

Multi-line string literals can be defined with here documents, where the delimiter can be any string:

<<END

on the one ton temple bell 

a moon-moth, folded into sleep, 

sits still. 

END

The syntax begins with << and is followed immediately by the delimiter. To end the string, the delimiter appears alone on a line.

Number Literals

A number literal can be a integer such as 5 or a floating point number such as 5.5.

Array Literals

Arrays are defined using square brackets and commas to separate the elements:

["a", "b", "c"]

[1, 2, 3]

["a", [1, "b"]]

Object Literals

Objects are defined using curly braces and colons to separate keys and values:

{

   "a": 1,

   "b": "c",

   "d": [2, 3],

   "e": {

     "f": 4 

   }

}