How to work with variables

During the deployment process on Edge Orchestrator, you can work with variables. A variable can be set on an edge service and an edge node.

You can create edge node and edge services variables using:


  1. Go to Azion Console > Edge Libraries > Edge Services.
  2. Select the edge service to which you want to add a variable.
  3. Go to the Environment tab.
  4. Add the following variable:
Terminal window
name=azion
  1. Click the Save button.

Now, you’ve created a variable related to a specific service. You need to access this variable through a resource.

  1. Navigate to the Resources tab.
  2. Select the resource to which you wish to use the variable.
  3. Click on Add Resource.
  4. Enter the filepath of the resource.
  5. Choose the type Text.
  6. Add the following content to the content block:
Terminal window
I am using {{name}} edge orchestrator
  1. Run the following GET request in your terminal, replacing [TOKEN VALUE] with your personal token and retrieve the edge service ID to which you wish to add a variable:
Terminal window
curl --location 'https://api.azionapi.net/edge_services/' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]'
  1. Create a variable related to the service. Run the following PATCH request in your terminal, replacing [TOKEN VALUE] with your personal token and informing the variable’s name and value:
Terminal window
curl --location --request PATCH 'https://api.azionapi.net/edge_services/:id' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
"active": true,
"name": "service",
"variables": [
{
"name": "name",
"value": "azion"
}
]
}'

Now, you’ve created a variable related to a specific service. You need to access this variable through a resource.

  1. Run the following POST request in your terminal:
Terminal window
curl --location 'https://api.azionapi.net/edge_services/:id/resources' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
"content_type": "Text",
"name": "/resource",
"content": "I am using {{name}} edge orchestrator"
}'

Replace [TOKEN VALUE] with your personal token, :id with the ID of the edge service and inform the following parameters in the request body:

PropertyDescriptionRequired
content_typeContent type of the resource being createdYes
nameName of the resource being createdYes
contentContent that defines actions performed when the resource state changes in the edge nodeYes

  1. Go to Azion Console > Edge Nodes.
  2. Select the edge node to which you want to add a variable.
  3. Go to the Services tab.
  4. Choose the service to which you want to apply the variable.
  5. Add the following content to the variables block:
Terminal window
name=azion
  1. Click the Save button.

Now, you’ve created a variable related to a specific node. You need to access this variable through a resource.

  1. Go to Azion Console > Edge Libraries > Edge Services and select the service related to the resource.
  2. Select the resource where you wish to use the variable.
  3. Click on Add Resource.
  4. Enter the filepath of the resource.
  5. Choose the type Text.
  6. Add the following content to the content block:
Terminal window
I am using {{name}} edge orchestrator
  1. Run the following GET request in your terminal, replacing [TOKEN VALUE] with your personal token and retrieve the edge node ID to which you wish to add a variable:
Terminal window
curl --location 'https://api.azionapi.net/edge_nodes/' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]'
  1. Run the following GET request in your terminal, replacing [TOKEN VALUE] with your personal token and :id with the ID of the edge node, and retrieve the ID of the relation between the edge node and the chosen service:
Terminal window
curl --location 'https://api.azionapi.net/edge_nodes/:id/services' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]'
  1. Run the following PATCH request in your terminal:
Terminal window
curl --location --request PATCH 'https://api.azionapi.net/edge_nodes/:node_id/services/:bind_id' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--data '{
"variables": [
{
"name": "name",
"value": "Azion"
}
]
}'

Replace [TOKEN VALUE] with your personal token, :id with the ID of the edge node and :bind_id with the ID of the relation retrieved in step 2, informing the following properties in the request body:

PropertyDescriptionRequired
variablesVariables to be replaced during the processing on the edge node.No

Now, your variables are created and ready to be accessed during the execution on your nodes related to the specific service. It’s relevant to stress that when you have a variable with the same name configured on a service and on a node, the value stored on the node will prevail, for example:

Variable configured on the edge service:

Terminal window
name=azion

Variable configured on the edge node

Terminal window
name=azion2

When the resource is accessed, the value of the variable will be azion2 instead of azion.

To access the resource on the edge node, you need to access the file. You can access it through the filepath you informed during the creation of the resource.

Resource name:

Terminal window
/txt/test

To access it:

Terminal window
nano /txt/test

Contributors