When launching a sandbox based on your blueprint, the user/API/CI process can enter input parameters that will be used by your application and optionally used by the application scripts. In this article we describe how to declare which parameters are required by your application, how to pass user inputs from your blueprint to your application and how to use parameters in your application scripts. We present an example that covers the use of parameters for both the configuration of the cloud provider network (opening the required port for incoming traffic) and the configuration of an Apache server (which will listen to the defined port).
In this article:
- Defining Application Parameters
- Passing Inputs to your Application
- Using Parameters in Application Scripts
In your application's YAML file, under the inputs section, declare all the parameters required by your application. The following is an excerpt from an apache-application YAML, in which the connectivity port is defined using an input parameter:
kind: application inputs: - port_number infrastructure: connectivity: external: - port_info: port: $port_number
In this example, under the inputs section, the parameter's port_number is declared and under the infrastructure section the application's connectivity port is assigned with the input value $port_number. To learn more about assigning application parameters with a value from input, see Passing input value from your blueprint to your application.
To pass the input value from the blueprint to the application that requires it:
- In your blueprint's YAML file under the inputs section, declare the parameters required for all the applications in your blueprint. For example:
When declaring a parameter, use any of the following parameter definition components:
.... kind: blueprint inputs: - apache_port: display_style: masked description: please set the Apache server's port default_value: 1234 optional: true applications: - apache: instances: 1 input_values: - port_number : $apache_port
To display the password content in the UI, do not assign a value.
To hide the password behind bullets, enter the value 'masked'.
description In the relevant UI field, enter a description to be displayed to the user. default_value
When the sandbox is created, the default value automatically fills in. The end user can choose to edit the value or leave as-is.
This is a boolean value: enter either true or false.
When optional is set to true, the user can leave the parameter empty. When optional is set to false, empty value(s) result in validation error(s).
- In the blueprint's YAML file under the applications section, list for each application the required parameters by the application, and assign them with the input value using the special character $.
For example, in the code sample above, under the apache application, the parameter port_number, (required by the apache application) is listed and assigned with the input value $apache_port. When a sandbox is launched based on this blueprint, the expression $apache_port will be replaced with the value of the apache_port blueprint input parameter that is provided by the user/API/CI Process.
When CloudShell Colony deploys your application, it automatically creates an environment variable for each parameter declared under the inputs section of your application's YAML. In addition, CloudShell Colony creates the following environment variables:
|ARTIFACTS_PATH||The path to the folder in which Colony keeps all your scripts and artifacts.|
|DOMAIN_NAME||The local DNS name that identifies your sandbox.|
|SANDBOX_ID||The identifier of the sandbox.|
|COLONY_INSTANCE_ID||The identifier of the compute instance|
The following example shows the use of environment variables port_number to configure the Apache server's connectivity port. By creating the environment variables, CloudShell Colony makes the application parameters available for use by your application scripts.
sed -i "s/Listen 80/Listen $port_number/g" /etc/apache2/ports.conf sed -i "s/80/$port_number /g" /etc/apache2/sites-enabled/000-default.conf systemctl start apache2