From c635ae0f89ccbba30953fad238d63ce04a0bb112 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Tue, 28 Jun 2022 18:27:38 +0200 Subject: [PATCH] docs: fixup HCL2 index collection function documentation. (#13511) --- .../hcl2/functions/collection/index-fn.mdx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/website/content/docs/job-specification/hcl2/functions/collection/index-fn.mdx b/website/content/docs/job-specification/hcl2/functions/collection/index-fn.mdx index f58c7b8f3..7ab775319 100644 --- a/website/content/docs/job-specification/hcl2/functions/collection/index-fn.mdx +++ b/website/content/docs/job-specification/hcl2/functions/collection/index-fn.mdx @@ -1,25 +1,30 @@ --- layout: docs page_title: index - Functions - Configuration Language -description: The index function finds the element index for a given value in a list. +description: |- + The index function returns an element from the given list or map + using the given index or key. --- # `index` Function -`index` finds the element index for a given value in a list. +`index` finds the element at the index when handling lists, or the element at +the key when handling maps. ```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 +> index(["a", "b", "c"], 1) +"b" +``` + +```shell-session +> index({"a"=1, "c"=2, "d"=3}, "c") +2 ``` ## Related Functions