Parsing Template Variables
Function
ParseTemplateVariables
This API parses variables in your input template and returns all variable blocks in the template.
URI
POST /v1/{project_id}/template-analyses/variables
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | A project ID is obtained by calling an API or from the console. Minimum: 3 Maximum: 64 |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Client-Request-Id | Yes | String | A unique request ID is specified by a user to locate a request. UUID is recommended. Minimum: 36 Maximum: 128 |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| template_body | No | String | HCL template. It describes the target status of a resource. RFS compares the differences between the statuses of this template and the current remote resources. Exactly one of template_body, template_uri, or private_template must be specified. In the CreateStack API, template_body, template_uri and private_template are optional. Note:
(If a variable is marked as sensitive in the template, its value will be masked in the vars_structure, vars_uri_content, and vars_body fields returned by the GetStackMetadata and GetExecutionPlanMetadata APIs.) Minimum: 0 Maximum: 51200 |
| template_uri | No | String | OBS address of an HCL template. The template describes the target status of a resource. RFS compares the differences between the statuses of this template and the current remote resources. Ensure that the OBS address is located in the same region as the RFS. The corresponding file must be a tf file or a zip package. A pure .tf file must end with .tf or .tf.json and comply with the HCL syntax. Currently, only the .zip package is supported. The file name extension must be .zip. The decompressed file cannot contain the .tfvars file and must be encoded in UTF8 format (the .tf.json file cannot contain the BOM header). The .zip package supports a maximum of 100 subfiles. Exactly one of template_body, template_uri and private_template must be specified. In the CreateStack API, template_body, template_uri and private_template are optional. Note:
(If a variable is marked as sensitive in the template, its value will be masked in the vars_structure, vars_uri_content, and vars_body fields returned by the GetStackMetadata and GetExecutionPlanMetadata APIs.) Minimum: 0 Maximum: 2048 |
| private_template | No | PrivateTemplate object |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| variables | Array of VariableResponse objects | Variables parsed from a template. |
| Parameter | Type | Description |
|---|---|---|
| name | String | Variable name. For example, in the following HCL template, the value of name is my_hello_world_variable. variable "my_hello_world_variable" {
type = string
description = "this is a variable"
default = "hello world"
sensitive = false
nullable = false
validation {
condition = length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == "hello"
error_message = "my_hello_world_variable should start with 'hello'."
}
} In a JSON template, the value of name is my_hello_world_variable. {
"variable": {
"my_hello_world_variable": [
{
"default": "hello world",
"description": "this is a variable",
"nullable": false,
"sensitive": false,
"type": "string",
"validation": [
{
"condition": "${length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == \"hello\"}",
"error_message": "my_hello_world_variable should start with 'hello'."
}
]
}
]
}
} |
| type | String | Variable type. For example, in the following HCL template, the value of type is string. variable "my_hello_world_variable" {
type = string
description = "this is a variable"
default = "hello world"
sensitive = false
nullable = false
validation {
condition = length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == "hello"
error_message = "my_hello_world_variable should start with 'hello'."
}
} In a JSON template, the value of type is string. {
"variable": {
"my_hello_world_variable": [
{
"default": "hello world",
"description": "this is a variable",
"nullable": false,
"sensitive": false,
"type": "string",
"validation": [
{
"condition": "${length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == \"hello\"}",
"error_message": "my_hello_world_variable should start with 'hello'."
}
]
}
]
}
} |
| description | String | Variable description. For example, in the following HCL template, the value of description is this is a variable. variable "my_hello_world_variable" {
type = string
description = "this is a variable"
default = "hello world"
sensitive = false
nullable = false
validation {
condition = length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == "hello"
error_message = "my_hello_world_variable should start with 'hello'."
}
} In a JSON template, the value of description is this is a variable. {
"variable": {
"my_hello_world_variable": [
{
"default": "hello world",
"description": "this is a variable",
"nullable": false,
"sensitive": false,
"type": "string",
"validation": [
{
"condition": "${length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == \"hello\"}",
"error_message": "my_hello_world_variable should start with 'hello'."
}
]
}
]
}
} |
| default | Object | Default variable value. The type of the return value is the same as that defined in the type field. For example, for a variable whose type is string, the type of the return value is string; for a variable whose type is number, the type of the return value is number. For example, in the following HCL template, the value of default is hello world. variable "my_hello_world_variable" {
type = string
description = "this is a variable"
default = "hello world"
sensitive = false
nullable = false
validation {
condition = length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == "hello"
error_message = "my_hello_world_variable should start with 'hello'."
}
} In a JSON template, the value of default is hello world. {
"variable": {
"my_hello_world_variable": [
{
"default": "hello world",
"description": "this is a variable",
"nullable": false,
"sensitive": false,
"type": "string",
"validation": [
{
"condition": "${length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == \"hello\"}",
"error_message": "my_hello_world_variable should start with 'hello'."
}
]
}
]
}
} |
| sensitive | Boolean | Whether the variable is sensitive. If sensitive is not defined in the variable, false is returned by default. For example, in the following HCL template, the value of sensitive is false. variable "my_hello_world_variable" {
type = string
description = "this is a variable"
default = "hello world"
sensitive = false
nullable = false
validation {
condition = length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == "hello"
error_message = "my_hello_world_variable should start with 'hello'."
}
} In a JSON template, the value of sensitive is false. {
"variable": {
"my_hello_world_variable": [
{
"default": "hello world",
"description": "this is a variable",
"nullable": false,
"sensitive": false,
"type": "string",
"validation": [
{
"condition": "${length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == \"hello\"}",
"error_message": "my_hello_world_variable should start with 'hello'."
}
]
}
]
}
} |
| nullable | Boolean | Whether the variable can be set to null. If nullable is not defined in the variable, true is returned by default. For example, in the following HCL template, the value of nullable is false. variable "my_hello_world_variable" {
type = string
description = "this is a variable"
default = "hello world"
sensitive = false
nullable = false
validation {
condition = length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == "hello"
error_message = "my_hello_world_variable should start with 'hello'."
}
} In a JSON template, the value of nullable is false. {
"variable": {
"my_hello_world_variable": [
{
"default": "hello world",
"description": "this is a variable",
"nullable": false,
"sensitive": false,
"type": "string",
"validation": [
{
"condition": "${length(var.my_hello_world_variable) > 0 && substr(var.my_hello_world_variable, 0, 5) == \"hello\"}",
"error_message": "my_hello_world_variable should start with 'hello'."
}
]
}
]
}
} |
| validations | Array of VariableValidationResponse objects | Variable verification module. |
| Parameter | Type | Description |
|---|---|---|
| condition | String | Variable expression. |
| error_message | String | Error message generated upon verification failure. |
Status code: 400
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. |
| error_msg | String | Response message. |
Status code: 401
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. |
| error_msg | String | Response message. |
Status code: 403
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. |
| error_msg | String | Response message. |
Status code: 429
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. |
| error_msg | String | Response message. |
Status code: 500
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Response code. Minimum: 11 Maximum: 11 |
| error_msg | String | Response message. |
| encoded_authorization_message | String | The message contains information about unauthorized requests. |
| details | Array of Detail objects | Detailed error messages returned by service when permission is denied. |
Example Requests
-
Parse template variables in the URI.
POST https://{endpoint}/v1/ba2b9930c977f71edaeaa3a5e96a8ff1/template-analyses/variables { "template_uri" : "https://my_hello_world_bucket.{region}.myhuaweicloud.com/my_hello_world_template.zip" } -
Parse template variables in the request. RFS supports the HCL syntax, and source field of required_providers module, which is used to define provider path, should be as the format of huawei.com/provider/{provider_name} (for example: huawei.com/provider/huaweicloud).
POST https://{endpoint}/v1/ba2b9930c977f71edaeaa3a5e96a8ff1/template-analyses/variables { "template_body" : "terraform {\n required_providers {\n huaweicloud = {\n source = \"huawei.com/provider/huaweicloud\"\n version = \"1.41.0\"\n }\n }\n}\nprovider \"huaweicloud\"{\n insecure = true\n cloud = \"{cloud_name}\"\n region = \"{region}\"\n endpoints = {\n iam = \"{iam_endpoint}\"\n }\n}\n\nvariable \"name\" {\n type = string\n default = \"my_default_vpc\"\n sensitive = true\n nullable = true\n validation {\n condition = length(var.name) > 2 && substr(var.name, 0, 2) == \"my\"\n error_message = \"The name value must be a valid name, starting with my.\"\n }\n}\n\nresource \"huaweicloud_vpc\" \"vpc\" {\n cidr = \"172.16.0.0/16\"\n name = var.name\n}" } -
Parse template variables in the private_templateBUG2025122540298.
POST https://{endpoint}/v1/ba2b9930c977f71edaeaa3a5e96a8ff1/template-analyses/variables { "private_template" : { "template_id" : "69f8d5ea-eaa4-4a3b-a96d-bae9230e97c9", "template_version" : "V1" } }
Example Responses
Status code: 200
Variables parsed.
{
"variables" : [ {
"default" : "my_default_vpc",
"name" : "name",
"nullable" : true,
"sensitive" : true,
"type" : "string",
"validations" : [ {
"condition" : "${length(var.name) > 2 && substr(var.name, 0, 2) == \"my\"}",
"error_message" : "The id value must be a valid id, starting with my."
} ]
} ]
} Status Codes
| Status Code | Description |
|---|---|
| 200 | Variables parsed. |
| 400 | Invalid request. |
| 401 | Authentication failed. |
| 403 | The user does not have the permission to call this API. |
| 429 | Too frequent requests. |
| 500 | Internal server error. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.