Usage of variables files

🟢 Beginner

template variable

This example explains how to define default values using variables.ospp files, including nested variable files and per-owner overrides.

  • Use a variables.ospp file to provide a default value to an owner via variablesFiles.

  • Override a variable locally inside the owner using templateVariables.

  • Chain a sub-variables file to supply additional variables from a nested variables.ospp.

git checkout origin/osp-web-configuration .
git checkout origin/osp-variables-configuration .
git checkout origin/example-inheritance-template-variables-file .

Steps

1. Create a value and his owner

The default is directly extracted from the variables.ospp.

root/final/value.ospp

{
    "name": "Example value",
    "description": "Example value",
    "type": "TEXT"
}

root/final/owner.variables

{
    "moduleId": "modules.variables.variables-1",
    "default": "${default-value}",
    "variablesFiles": [
        "root.variables"
    ]
}

root/variables/variables.ospp

{
    "variables": {
        "default-value": "My content"
    },
    "variablesFiles": [
        "root.variables.sub"
    ]
}

Which result in the following owner.

@startuml
skinparam backgroundColor transparent

[*] --> v
state "root.final/owner.variables" as v :\
{\n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"${defaultValue}"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ]\n\
}

v -> t : Variables file
state "root.variables/variables.ospp" as t  : \
{\n\
    "variables": { \n\
        "defaultValue": <color:red>"My content"</color>\n\
    },\n\
    "variablesFiles": [\n\
        "root.variables.sub"\n\
    ]\n\
}

v --> result : Result after the aggregation

result : {\n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"My content"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ]\n\
}

@enduml

2. Redefine the default value inside the owner

The default is overridden by the locally define one.

root/redefine/value.ospp

{
    "name": "Example value",
    "description": "Example value",
    "type": "TEXT"
}

root/redefine/owner.variables

{
    "moduleId": "modules.variables.variables-1",
    "default": "${default-value}",
    "variablesFiles": [
        "root.variables"
    ],
    "templateVariables": {
        "default-value": "My new content"
    }
}

root/variables/variables.ospp

{
    "variables": {
        "default-value": "My content"
    },
    "variablesFiles": [
        "root.variables.sub"
    ]
}

Which result in the following owner as the default-value define on the root.redefine/owner.ospp is overriding the one define on root.variables/variables.ospp.

@startuml
skinparam backgroundColor transparent

[*] --> v
state "root.redefine/owner.variables" as v :\
{\n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"${defaultValue}"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ],\n\
    "templateVariables" : {\n\
        "default-value" : <color:red>"My new content"</color>\n\
    }\n\
}

v -> t : Variables files
state "root.variables/variables.ospp" as t  : \
{\n\
    "variables": { \n\
        "defaultValue": <color:red>"My content"</color>\n\
    },\n\
    "variablesFiles": [\n\
        "root.variables.sub"\n\
    ]\n\
}

v --> result : Result

result : {\n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"My new content"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ]\n\
}

@enduml

3. Use variables from a sub variables file

The default is overridden by the locally define one and add a new variable.

root/sub-variables/value.ospp

{
    "name": "Example value",
    "description": "Example value",
    "type": "TEXT"
}

root/sub-variables/owner.variables

{
    "moduleId": "modules.variables.variables-1",
    "default": "${default-value}",
    "variablesFiles": [
        "root.variables"
    ],
    "templateVariables": {
        "default-value": "My new content is [${content}]"
    }
}

root/variables/variables.ospp

{
    "variables": {
        "default-value": "My content"
    },
    "variablesFiles": [
        "root.variables.sub"
    ]
}

root/variables/sub/variables.ospp

{
    "variables": {
        "content": "A message"
    }
}

Which result in the following owner as the default-value define on the root.sub-variables/owner.ospp is overriding the one define on root.variables/variables.ospp and use content define on root.variables.sub/variables.ospp.

@startuml
skinparam backgroundColor transparent

[*] --> v
state "root.redefine/owner.variables" as v :\
{ \n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"${defaultValue}"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ],\n\
    "templateVariables" : {\n\
        "default-value" : <color:red>"My new content is [<color:blue>${content}</color><color:red>]"</color>\n\
    }\n\
}

v -> t : Variables file
state "root.variables/variables.ospp" as t  : \
{ \n\
    "variables": { \n\
        "defaultValue": <color:red>"My content"</color>\n\
    },\n\
    "variablesFiles": [\n\
        "root.variables.sub"\n\
    ]\n\
}

t -> t2 : Variables file
state "root.variables.sub/variables.ospp" as t2  : \
{\n\
    "variables": { \n\
        "content": <color:blue>"A message"</color>\n\
    }\n\
}

v --> result : Result

result : {\n\
    "moduleId": "modules.variables.variables-1",\n\
    "default": <color:red>"My new content is [<color:blue>A message</color><color:red>]"</color>,\n\
    "variablesFiles": [\n\
        "root.variables"\n\
    ]\n\
}

@enduml