Back to Packer

`index` Function

website/content/docs/templates/hcl_templates/functions/collection/index-fn.mdx

1.15.31013 B
Original Source

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

[!IMPORTANT]
Documentation Update: Product documentation previously located in /website has moved to the hashicorp/web-unified-docs repository, where all product documentation is now centralized. Please make contributions directly to web-unified-docs, since changes to /website in this repository will not appear on developer.hashicorp.com. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

index Function

index finds the element index for a given value in a list.

hcl
index(list, value)

The returned index is zero-based. This function produces an error if the given value is not present in the list.

Examples

shell-session
> index(["a", "b", "c"], "b")
1
  • element retrieves a particular element from a list given its index.