Creating Conditions

Create and use conditions within your Oracle Cloud Stack template in order to change how the template behaves for different scenarios.

For an introduction, see What are Conditions.

A conditional expression includes at least one comparison, which compares two arguments by using a comparison operator (equals, greater than, and so on). Each argument in a comparison can be a literal value or you can use functions like GetParam. A comparison evaluates to true or false.

A filter in a conditional expression combines the results of two or more comparisons. A filter can evaluate if any, all, or none of the comparisons are true.

The following image depicts a filter that contains two comparisons:

For more complex conditional expressions, you can also add filters to a filter.

Defining Global Conditions

If you need to use the same conditional expression at multiple locations in your Oracle Cloud Stack template, create a condition at the template level. You can then refer to these global conditions throughout the template.

  1. Access the Oracle Cloud Stack console, and then edit your template.
  2. To the right of Conditions, click Add condition Plus icon.
  3. Enter a name for the condition.
  4. If your condition requires a single comparison, perform these steps:
    1. Select Add comparison, and then click Add condition expression Plus icon.
    2. Enter two expressions and select a comparison operator.
  5. If your condition requires two or more comparisons, perform these steps:
    1. Select Add filter, and then click Add condition expression Plus icon.
    2. In the second input field, select Add comparison, and then click Add condition expression Plus icon.
    3. For the first comparison, enter two expressions and select a comparison operator.
    4. Below the first comparison, verify that Add comparison is selected, and then click Add condition expression Plus icon.
    5. For the second comparison, enter two expressions and select a comparison operator.
    6. Repeat this process for each comparison you want to add to this condition.
    7. Select a logical operator to evaluate the results of the comparisons: Match all, Match any, or Match none.

    Tip:

    If you prefer to enter a conditional expression manually, select the Add value option. You can use any combination of functions in the expression, but the result must return either true or false. See List of Functions.
  6. Click Apply Changes.
  7. Repeat from step 2 for each additional condition that you want to create.
  8. Click Save the current template Save icon.

When editing an existing condition:

  • Click Add condition expression Plus icon to add filters or comparisons.

  • Click Delete condition expression Trash icon to delete filters or comparisons.

Adding a Condition to a Resource

Assign a global condition to a resource in your Oracle Cloud Stack template.

If this condition evaluates to true, the resource will be created as part of the stack. If it evaluates to false the resource (and any resources on which it depends) will not be created.

  1. Access the Oracle Cloud Stack console, and then edit your template.
  2. On the canvas, right click the resource to which you want to add a condition.
  3. Select Assign ConditionName.

    Resources on the canvas that have been assigned a condition are identified with the Question mark icon.

  4. Click Save the current template Save icon.

As an alternative to using the canvas, you can also create, assign, and remove conditions when editing a resource’s configuration.

Adding a Condition to a Resource Parameter

Use global conditions to dynamically change a resource’s configuration in an Oracle Cloud Stack template.

For example, you can set a resource’s computeShape to the value oc3 if a condition is true, or to the value oc4 if the condition is false.

  1. Access the Oracle Cloud Stack console, and then edit your template.
  2. On the canvas, right-click the resource you want to modify, and then select Edit.
  3. Click the value of the parameter to edit it.
  4. Use the If function. Enter the name of the global condition along with two string values as a YAML sequence.

    Format: 'Fn::If': [conditionName,trueValue,falseValue]

    For example: 'Fn::If': [mycondition,oc3,oc4]

    If the specified condition evaluates to true, the function returns the first value. Otherwise, the function returns the second value.

  5. Click Apply Changes.
  6. Click Save the current template Save icon.

Tip:

A YAML sequence can also be expressed with the following syntax:
'Fn::If':
  - conditionName
  - trueValue
  - falseValue

Adding a Condition to a Template Parameter

Assign a global condition to a parameter or parameter group in your Oracle Cloud Stack template.

If the condition evaluates to false, the parameter or group is hidden in the Oracle Cloud Stack console when a user creates a stack from this template. If it evaluates to true, the parameter or group is displayed to the user. These conditions are dynamically reevaluated each time the user modifies the value of a template parameter.

  1. Access the Oracle Cloud Stack console, and then edit your template.
  2. To the left of Parameters or Parameter Groups, click Grey arrow.
  3. To the right of the parameter or group that you want to modify, click Edit Pencil icon.
  4. From the Conditions field, select an existing condition.
  5. Click Apply Changes.
  6. Click Save the current template Save icon.