- v1.3.x (latest)
- v1.2.x
- v1.1 and earlier
- Overview
- Attributes as Blocks - Configuration Language
- Data Sources
- Overview
- abs
- abspath
- alltrue
- anytrue
- base64decode
- base64encode
- base64gzip
- base64sha256
- base64sha512
- basename
- bcrypt
- can
- ceil
- chomp
- chunklist
- cidrhost
- cidrnetmask
- cidrsubnet
- cidrsubnets
- coalesce
- coalescelist
- compact
- concat
- contains
- csvdecode
- dirname
- distinct
- element
- endswith
- file
- filebase64
- filebase64sha256
- filebase64sha512
- fileexists
- filemd5
- fileset
- filesha1
- filesha256
- filesha512
- flatten
- floor
- format
- formatdate
- formatlist
- indent
- index
- join
- jsondecode
- jsonencode
- keys
- length
- list
- log
- lookup
- lower
- map
- matchkeys
- max
- md5
- merge
- min
- nonsensitive
- one
- parseint
- pathexpand
- pow
- range
- regex
- regexall
- replace
- reverse
- rsadecrypt
- sensitive
- setintersection
- setproduct
- setsubtract
- setunion
- sha1
- sha256
- sha512
- signum
- slice
- sort
- split
- startswith
- strrev
- substr
- sum
- templatefile
- textdecodebase64
- textencodebase64
- timeadd
- timecmp
- timestamp
- title
- tobool
- tolist
- tomap
- tonumber
- toset
- tostring
- transpose
- trim
- trimprefix
- trimspace
- trimsuffix
- try
- type
- upper
- urlencode
- uuid
- uuidv5
- values
- yamldecode
- yamlencode
- zipmap
- Upgrading to Terraform v1.3
- v1.x Compatibility Promises
- Terraform Internals
- Intro to Terraform
- Configuration Language
- Terraform CLI
- Terraform Cloud
- Terraform Enterprise
- Provider Use
- Plugin Development
- Registry Publishing
- Integration Program
- Terraform Tools
- CDK for Terraform
- Glossary
Terraform Language
Other Docs
A new platform for documentation and tutorials is launching soon.
We are migrating Terraform documentation into HashiCorp Developer, our new developer experience.
»slice
Function
slice
extracts some consecutive elements from within a list.
slice(list, startindex, endindex)
slice(list, startindex, endindex)
startindex
is inclusive, while endindex
is exclusive. This function returns
an error if either index is outside the bounds of valid indices for the given
list.
»Examples
> slice(["a", "b", "c", "d"], 1, 3) [ "b", "c", ]
> slice(["a", "b", "c", "d"], 1, 3)
[
"b",
"c",
]
»Related Functions
substr
performs a similar function for characters in a string, although it uses a length instead of an end index.