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 will 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 script. In this article we will include 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 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, you can 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 applications: - apache: instances: 1 input_values: - port_number : $apache_port
- To display the password content in the UI, do not assign any value.
- To hide the password behind bullets, enter the value 'masked'.
description Enter a description to be displayed to the user, in the relevant UI field. default_value Enter the parameter's default value. If you choose not to enter a default value, the user/API/CI process will be required to provide this value when launching a sandbox based on this blueprint.
You can choose whether to set a default value for the input or not. Any parameter without a default value will require the user/API/CI process to enter a value. If the parameter does have a default value it will be regarded as optional and the user can choose whether to edit.
- In the blueprint's YAML file under the applications section, for each application list the required parameteres 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 appache 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/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