Updated on 2023-08-11 GMT+08:00

inputs

To enable a template to be more commonly used, do not set all parameter values of the elements to fixed values. For example, it is recommended that the image ID of a VM be used as an input of a template. In this case, users can set the value of this parameter freely. The image ID is set only when the template is used, that is, during stack deployment.

The inputs section is optional and defines the inputs of a stack created based on a template. A maximum of 60 input parameters can be defined in a template. Each input parameter must have a unique name so that the value can be obtained by using the get_input built-in function. If an input parameter is defined repeatedly, the latest definition will overwrite the previous one.

Function scope: node_templates and outputs sections. That is, input parameters can be transferred in the properties of node_templates and values of outputs.

Format of the inputs section:

 <Input parameter name>:
    type: <Type>
    default: <Default value>
    constraints: <Constraints>
    description: <Description>
    label: <Label>
    invisible: <Whether command outputs are visible>

In addition to the reusability of a template, methods of restricting and verifying user inputs also need to be considered during template input design. Designers must understand parameter statements.

Table 1 Parameter property description

Property

Mandatory

Type

Value Constraint

Description

Input parameter name

Yes

String

The value must be 1 to 20 characters long. Only lowercase letters, digits, and hyphens (-) are allowed.

A maximum of 60 input parameter names can be defined and each name must be unique.

type

Yes

  • string: character string
  • integer: number
  • float: floating-point number
  • boolean: boolean value
  • password: password

When the type is set to password, no output is visible. Currently, only the passwords entered at the system level can be decrypted. If a common parameter is defined as a password, encrypted information may be obtained and such information fails to be decrypted.

Parameter type.

description

No

String

The value must be 0 to 255 characters long.

Parameter description information.

default

No

String

When creating a stack, you can enter a value to replace the default value. If no default value is set, you must enter the value of this parameter.

NOTICE:

The default value type must be the same as the defined parameter type. If they are inconsistent, the parser may perform automatic conversion, resulting in an unexpected result.

Default parameter value.

label

No

String

The value is a string of 0 to 64 characters.

Label of a parameter. The label defined here can be displayed by category during stack creation.

constraints

No

String

There are several constraints. You can define only one rule for each condition of an input parameter. If any of the constraints is not met, the parameter is considered invalid.
  • equal: The value of this parameter must be equal to the specified value.

    For example, if the value of the input parameter is not aos, the value is regarded as invalid.

    constraints:

    equal: 'aos'

  • valid_values: valid value range. This parameter is used to define an array.

    For example, set the valid value of the output parameter to TCP or UDP.

    constraints:

    valid_values: ['TCP', 'UDP' ]

  • regex: The parameter must meet a certain regular condition and must be of the string type.

    For example, if the input parameter does not meet the regular condition, the parameter is regarded as invalid.

    constraints:

    regex: "^[-_a-zA-Z0-9]*$"

  • invalid_values: invalid value range. If you set a parameter to a value which is within the invalid value range, such a value is regarded as invalid and an error is reported.

    For example, if the value of the input parameter is set to 1 or 12, the value is regarded as invalid.

    constraints:

    invalid_values: ['1', '12' ]

Parameter constraints, which are used to restrict the valid value range of an input parameter.

invisible

No

-

When invisible of an input parameter is set to true, ****** is displayed.

Whether the output is visible.

Example configuration of inputs:

tosca_definitions_version: huaweicloud_tosca_version_1_0
inputs: # defines the variables of a stack created based on a template. 
  instance:
    description: number of Elastic Cloud Servers (ECSs) to be created
    default: 1
  image:
    description: ID of the image used by the ECS
    type: HuaweiCloud.ECS.Image.Id
  vpc:
    description: ID of the Virtual Private Cloud (VPC) to which the ECS belongs
  subnet:
    description: ID of the subnet to which the ECS belongs