tencent cloud

Using Installation Parameters, Variables and Output
Last updated: 2025-04-23 14:27:48
Using Installation Parameters, Variables and Output
Last updated: 2025-04-23 14:27:48

Installation Parameters

Installation parameters can let customers install software in a suitable way. Common scenarios include:
Select and install in the specified Virtual Private Cloud (VPC) and subnet (Subnet) to implement network planning.
Select a customer security group (Security Group) to implement a network access policy.
Select the model to better fit the user's actual capacity.
Select the domain name and certificate for final deployment, so that the certificate can be automatically deployed.

Declare Installation Parameters in package.yaml

The installation package can declare installation parameters in package.yaml. The Cloud App will generate an appropriate installation interface for these declared installation parameters. The following example comes from the Cloud App template CT_001_cvm-ip.
# <package.yaml>
# Custom installation parameters, declare the installation form to be retrieved through the widget.
args:
- name: app_target
label: target network
widget: subnet-select
- name: cvm_type
label: Cloud Virtual Machine (CVM) type
widget: cvm-instance-type-select
region: ${app_target.region}
zone: ${app_target.subnet.zone}
- name: sg
label: security group
widget: security-group-select
regions:
- ${app_target.region}




Fields used in declaring installation parameters in package.yaml are explained as follows:
Field
Description
args
Declare a parameter list with args. Each item is a parameter. The installation interface will render installation components in the declared order.
args[i].name
Parameter identification. This is also the variable name to be declared and used in Terraform subsequently.
args[i].label
Parameter name. The installation interface will show the parameter name.
args[i].widget
The installation components for parameter use. For supported components, see Installation Parameter Manual.
args[i].region
args[i].zone
...
The configuration of installation components for parameters. Different component types have different configuration fields. See Installation Parameter Manual for details.
The configuration of components generally provides a finer selection range when users enter data. For example, after the user has selected the target network, the server type can be limited to the example type range supported by the target subnet to avoid invalid selections.
args[i].when
(Advanced usage) Conditions for the occurrence of parameters. Parameters do not appear in the installation interface by default and only appear when the conditions of when are met. Applicable to the form linkage of installation components.
args[i].hidden
(Advanced usage) Conditions for hiding parameters. Parameters will appear in the installation interface by default and hide when the conditions of when are met. Applicable to the form linkage of installation components.
args[i].validator
(Advanced usage) Verification rules for parameters can help users reduce configuration errors.

Using Installation Parameters in a tf File

After defining the installation parameters in the package.yaml file, you can declare and use them in the tf file. The following example comes from CT_001_cvm-ip.
# <variable.tf>
# CVM model selection variable
variable "cvm_type" {
type = object({
region = string
region_id = string
zone = string
instance_type = string
})
}
Different types of installation parameters have different variable value types. See Installation Parameter Manual for details.
After declaration, it can be used as an ordinary Terraform variable.
# <deployment.tf>
resource "tencentcloud_instance" "demo_cvm" {
# CVM model
instance_type = var.cvm_type.instance_type
}

Variable

Declare a Variable

All variables used in the installation package need to be declared before use.
# <variable.tf>
# CVM model selection variable
variable "cvm_type" {
type = object({
region = string
region_id = string
zone = string
instance_type = string
})
}
Similar to a resource block, use a variable block variable to declare a variable. In the above declaration, cvm_type is the variable name, and var.cvm_type can be used to refer to it in the resource block.

Variable Separation Practice

Using variables can effectively manage orchestration parameters of resources. For example, if a service provider has two components with basically the same orchestration architectures but different server images, the image ID can be extracted as a variable.
In practice, it is recommended to separate variables and orchestration parts in the infrastructure directory of the installation package according to variable.tf and deployment.tf. See CloudApp Template Library for more practical ideas.

Variable Type

The available variables in the installation package are divided into two kinds: system variables and application variables.
System variable: Used to provide deployment requirements information, such as image repository address and credentials, CAM role information, etc. It is prefixed with cloudapp_ and can be used by ALL installation packages.
Parameter variable: The application parameters defined in package.yaml will generate corresponding application variables. The variable name is exactly the parameter name.
Common variable: A variable declared and used by the application itself, such as CVM image ID, basic database settings, etc.
For a list and information about system variables, please see System Variable Manual. For the method of application parameter configuration, please see Installation Parameter Manual.
Variables used must be declared
Even if the values of system variables and application variables are automatically injected, they must be declared when using the .TF file. Variables used without declaration can cause the installation package to fail to package.

Output

The results after application installation need to be provided to the customer. For example, the access address of the application, the address of the management system, or the initial password of the management system, etc. This can be achieved by declaring output in the tf file.
output "main" {
value = "https://my.${var.selected_domain}"
# value = "http://${tencentcloud_instance.cloudapp_cvm.public_ip}:8080"
description = "access entrance"
}
output "a_admin_url" {
value = "https://admin.${var.selected_domain}"
description = "operation system"
}
output "b_admin_default_user" {
value = "admin"
description = "default admin user"
}
output "c_admin_default_password" {
value = random_password.default_admin.result
description = "default administrator password"
sensitive = true
}
Note:
Recommendation to increase the output with the variable name main and set the value to URL. This value will be used as the default open address for the customer application.
If sensitive = true is declared, it indicates sensitive information (customers can perform CAM or MFA security restrictions against sensitive information APIs).
The display order of the final result items is not based on the declaration sequence in the tf file, but sorted alphabetically according to the output variable names.
The declared output. Customers can see the corresponding installation result in the dashboard app details.

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback