All Products
Search
Document Center

Cloud Architect Design Tools:Specify values for template variables

Last Updated:Mar 10, 2023

This topic describes how to specify values for custom template variables.

Data types of template variables

Data type

Description

String

Elastic Compute Service (ECS) instance name.

Integer

ECS system disk capacity.

Boolean

Whether to disable deployment for a resource.

Map

Resource tag information.

List

IP address whitelist of ECS instances.

List<Map>

ECS data disk list.

ChargeType

Only applicable to the Charge type variable.

Define template variables

This topic uses an ECS template in the example to describe how to specify values for different types of variables.

  1. Create an ECS template. The following figure shows an example. For more information, see Create a custom template.image

  2. Define the following variables for the template. For more information, see Configure template variables.

    Variable

    Variable value

    Default value

    count

    ${count}

    1

    instance_name

    ${name}

    ecs

    system_disk_size

    ${storage}

    40

    data_disks

    ${data_disk}

    []

    tags

    ${tags}

    {"cadt":"uat"}

  3. After you complete the settings, find the desired template on the My Solutions page to view the defined variables. You can see that the variable types include Integer, String, List<Map>, and Map. image

Specify values for template variables by using Java code

If you are familiar with the Java programming language, you can use Java code to specify values for template variables. The following sample code provides an example:

variables = Maps.newHashMap();

// Specify a value for the instance_name variable. Format: ${name}.
variables.put("${name}", "ecs123");

// Specify a value for the count variable. Format: ${count}.
variables.put("${count}", "1");

// Specify a value for the system_disk_size variable. Format: ${storage}.
variables.put("${storage}", "40");

// Specify a value for the data_disks variable. Format: ${data_disk}.
List<Map<String, String>> disks = Lists.newArrayList();
Map<String, String> disk1 = Maps.newHashMap();
disk1.put("name", "disk1");
disk1.put("size", "50");
disk1.put("category", "cloud_essd");
disk1.put("performance_level", "PL1");
disk1.put("encrypted", "false");
disks.add(disk1);

Map<String, String> disk2 = Maps.newHashMap();
disk2.put("name", "disk2");
disk2.put("size", "60");
disk2.put("category", "cloud_essd");
disk2.put("performance_level", "PL1");
disk2.put("encrypted", "false");
disks.add(disk2);
variables.put("${data_disk}", JSON.toJSONString(disks));

// Specify a value for the tags variable. Format: ${tags}.
Map<String, String> tags = Maps.newHashMap();
tags.put("role", "dev");
tags.put("project", "abc");
variables.put("${tags}", JSON.toJSONString(tags));

// After you specify values for the variables, call the following API operations to create an application: 
createApplicationRequest = new CreateApplicationRequest()
        .setTemplateId(templateId)      // The ID of the template that uses the variables.
        .setName(appName)                  // The ID of the generated application.
        .setAreaId(region)                       // The region of the template.
        .setVariables(variables)              // Pass the variables.
        .setClientToken(UUID.randomUUID().toString());

Configure template variables by using a YAML file

You can use the CADT command-line tool to call API operations to deploy CADT applications. The basic information required to create an application is defined in a YAML configuration file. For more information, see .