- What's New
- Service Overview
- User Guide
- Template Reference
-
API Reference
- Before You Start
-
API
- Calling APIs
-
Stacks
- Listing Events of a Stack
- Obtaining Stack Metadata
- Listing Stacks
- Creating a Stack
- Obtaining a Stack Template
- Listing Stack Resources
- Listing Stack Outputs
- Continuing to Deploy a Stack
- Deploying a Stack
- Deleting a Stack
- Updating a Stack
- Deleting a Stack with Conditions
- Continuing to Roll Back a Stack
- Execution Plans
- Template Analysis
- Template Management
-
Stack Sets
- Listing Stack Sets
- Creating a Stack Set
- Obtaining a Stack Set Template
- Listing Stack Set Operations
- Obtaining Metadata of a Stack Set
- Listing Stack Instances
- Creating Stack Instances
- Deleting Stack Instance Deprecated
- Updating Stack Instances
- Deleting Stack Instances
- Deploying a Stack Set
- Deleting a Stack Set
- Updating a Stack Set
- Obtaining Metadata of a Stack Set Operation
- Obtaining a Stack Instance
- Customized Providers
- Resource Formation - Hook
- Resource Formation - Module Management
- Permissions and Supported Actions
- Appendix
- Change History
- FAQs
- Videos
-
More Documents
-
User Guide (ME-Abu Dhabi Region)
- Service Overview
- Getting Started
- Stack Management
- CTS
-
Template Reference
- Template Introduction
-
List of Elements
- Resource Indexes
- AOS.Stack
- CCE.Addon.AutoScaler
- CCE.Cluster
- CCE.HelmRelease
- CCE.NodePool
- CCE.Pod
- CCE.Storage.OBS
- CCE.Storage.SFS
- DCS.Redis
- ECS.CloudServer
- ECS.KeyPair
- NAT.Instance
- NAT.SNatRule
- OBS.Bucket
- RDS.MySQL
- SFS.FileSystem
- ULB.Healthmonitor
- ULB.Listener
- ULB.LoadBalancer
- ULB.Member
- ULB.Pool
- VPC.EIP
- VPC.SecurityGroup
- VPC.SecurityGroupRule
- VPC.Subnet
- VPC.VPC
-
Data Structure
- AOS.BatchItem
- Basic.KeyValuePair
- Basic.Label
- Basic.LabelSelector
- Basic.NameAndSecretValue
- Basic.NameKeyPair
- Basic.NameValuePair
- CCE.Addon.AutoScaler.Node
- CCE.DataVolume
- CCE.HelmChart
- CCE.Labels
- CCE.NodePool
- CCE.PublicIP
- DCS.InstanceBackupPolicy
- DCS.PeriodicalBackupPlan
- ECS.DataVolume
- ECS.EIP
- ECS.ExtendParam
- ECS.MountedVolumes
- ECS.NICS
- ECS.Personality
- ECS.PublicIP
- ECS.RootVolume
- ECS.SecurityGroup
- ECS.ServerTags
- ECS.VolumeExtendParam
- K8S.PodSecurityContext
- K8S.SecurityContext.SeLinuxOptions
- MySQL.DBUser
- MySQL.DataBase
- MySQL.DataStore
- RDS.BackupStrategy
- RDS.HA.Mysql
- RDS.Volume
- ULB.StickySession
- VPC.BandWidth
- VPC.PublicIP
- Appendix
- FAQs
- Change History
-
API Reference (ME-Abu Dhabi Region)
- Before You Start
- API Overview
- Calling APIs
-
API
- Creating a Template
- Querying a Template List
- Updating a Template
- Deleting a Template
- Downloading a Template
- Querying a Template
- Querying the Input Parameters of a Template
- Creating a Stack
- Deleting a Stack
- Executing a Stack Lifecycle
- Querying a Stack List
- Querying a Stack
- Querying a Stack Element List
- Querying a Stack Element
- Querying a Stack Output
- Querying Stack Input
- Querying the Execution Record of a Stack
- Querying a Stack Execution Record List
- Appendix
- Change History
-
API Reference (Kuala Lumpur Region)
- Before You Start
-
API
- Calling APIs
-
Stacks
- Listing Events of a Stack
- Obtaining Stack Metadata
- Listing Stacks
- Creating a Stack
- Obtaining a Stack Template
- Listing Stack Resources
- Listing Stack Outputs
- Continuing to Deploy a Stack
- Deploying a Stack
- Deleting a Stack
- Updating a Stack
- Deleting a Stack with Conditions
- Continuing to Roll Back a Stack
- Execution Plans
- Template Analysis
- Template Management
-
Stack Sets
- Listing Stack Sets
- Creating a Stack Set
- Obtaining a Stack Set Template
- Listing Stack Set Operations
- Obtaining Metadata of a Stack Set
- Listing Stack Instances
- Creating Stack Instances
- Deleting Stack Instance Deprecated
- Updating Stack Instances
- Deploying a Stack Set
- Deleting Stack Instances
- Deleting a Stack Set
- Updating a Stack Set
- Obtaining Metadata of a Stack Set Operation
- Obtaining a Stack Instance
- Appendix
- Change History
- User Guide (Kuala Lumpur Region)
-
User Guide (ME-Abu Dhabi Region)
- General Reference
Copied.
Expressions
Expressions refer to or compute values within a configuration. The simplest expressions are just literal values, like hello world or 5. Terraform allows multiple expressions such as operators, conditional expressions, and built-in functions.
You can experience and test expressions and built-in functions using the Terraform expression console, by running the terraform console command.
Operators
Operators perform specific mathematical or logical operations. Terraform supports the following types of operators:
- Arithmetic operators: expect number values and produce number values as results, including +, - (subtraction), *, /, %, and - (multiplication by -1).
- Equality operators: both take two values of any type and produce bool values as results, including == and ! =.
- Comparison operators: expect number values and produce bool values as results, including >, >=, <, and <=.
- Logical operators: expect bool values and produce bool values as results, including ||, &&, and !.
When multiple operators are used together in an expression, they are evaluated in the following order of operations:
- !, - (multiplication by -1)
- *, /, %
- +, - (subtraction)
- >, >=, <, <=
- ==, !=
- &&
- ||
Conditional Expressions
A conditional expression uses the value of a bool expression to select one of two values. The syntax is as follows:
condition ? true_value : false_value
This statement indicates that if condition is true, the result is true_value. Otherwise, the result is false_value. The result of a conditional expression can be of any type, but the types of true_value and false_value must be the same. A common use of conditional expressions is to define defaults to replace invalid values:
var.a != "" ? var.a : "default-a"
This statement indicates that if var.a is not empty, the actual value of var.a is returned. Otherwise, the result is default-a.
For Expressions
A for expression creates a set type by traversing and transforming each element in another set type (map, list, or set). The type of brackets around the for expression decide what type of result it produces.
- Using [ and ] will generate a list.
- Using { and } will generate a map or object.
Assume that the value of mylist is ["AA", "BBB", "CCCC"]. You can use the for expression to convert each string element in mylist to lowercase and output another list.
> [for str in var.mylist : lower(str)] [ "aa", "bbb", "cccc", ]
You can also output a map, which is determined by =>:
> {for str in var.mylist : str => lower(str)} { "AA" = "aa" "BBB" = "bbb" "CCCC" = "cccc" }
The for expression can also convert a map. Assume that the value of mymap is {element1="aaa", element2="bbb", element3="ccc"}. You can convert each value in the map to uppercase.
> {for key, value in var.mymap : key => upper(value)} { "element1 = "AAA" "element2 = "BBB" "element3 = "CCC" }
In addition, the for expression can use the if clause to filter elements:
> [for str in var.list : upper(str) if length(str) >= 3] [ "bbb", "cccc", ]
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot