github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/website/docs/language/expressions/function-calls.html.md (about)

     1  ---
     2  layout: "language"
     3  page_title: "Function Calls - Configuration Language"
     4  ---
     5  
     6  # Function Calls
     7  
     8  > **Hands-on:** Try the [Perform Dynamic Operations with Functions](https://learn.hashicorp.com/tutorials/terraform/functions?in=terraform/configuration-language&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) tutorial on HashiCorp Learn.
     9  
    10  The Terraform language has a number of
    11  [built-in functions](/docs/language/functions/index.html) that can be used
    12  in expressions to transform and combine values. These
    13  are similar to the operators but all follow a common syntax:
    14  
    15  ```hcl
    16  <FUNCTION NAME>(<ARGUMENT 1>, <ARGUMENT 2>)
    17  ```
    18  
    19  The function name specifies which function to call. Each defined function
    20  expects a specific number of arguments with specific value types, and returns a
    21  specific value type as a result.
    22  
    23  Some functions take an arbitrary number of arguments. For example, the `min`
    24  function takes any amount of number arguments and returns the one that is
    25  numerically smallest:
    26  
    27  ```hcl
    28  min(55, 3453, 2)
    29  ```
    30  
    31  A function call expression evaluates to the function's return value.
    32  
    33  ## Available Functions
    34  
    35  For a full list of available functions, see
    36  [the function reference](/docs/language/functions/index.html).
    37  
    38  ## Expanding Function Arguments
    39  
    40  If the arguments to pass to a function are available in a list or tuple value,
    41  that value can be _expanded_ into separate arguments. Provide the list value as
    42  an argument and follow it with the `...` symbol:
    43  
    44  ```hcl
    45  min([55, 2453, 2]...)
    46  ```
    47  
    48  The expansion symbol is three periods (`...`), not a Unicode ellipsis character
    49  (`…`). Expansion is a special syntax that is only available in function calls.
    50  
    51  ## Using Sensitive Data as Function Arguments
    52  
    53  When using sensitive data, such as [an input variable](https://www.terraform.io/docs/language/values/variables.html#suppressing-values-in-cli-output)
    54  or [an output defined](https://www.terraform.io/docs/language/values/outputs.html#sensitive-suppressing-values-in-cli-output) as sensitive
    55  as function arguments, the result of the function call will be marked as sensitive.
    56  
    57  This is a conservative behavior that is true irrespective of the function being
    58  called. For example, passing an object containing a sensitive input variable to
    59  the `keys()` function will result in a list that is sensitive:
    60  
    61  ```shell
    62  > local.baz
    63  {
    64    "a" = (sensitive)
    65    "b" = "dog"
    66  }
    67  > keys(local.baz)
    68  (sensitive)
    69  ```
    70  
    71  ## When Terraform Calls Functions
    72  
    73  Most of Terraform's built-in functions are, in programming language terms,
    74  [pure functions](https://en.wikipedia.org/wiki/Pure_function). This means that
    75  their result is based only on their arguments and so it doesn't make any
    76  practical difference when Terraform would call them.
    77  
    78  However, a small subset of functions interact with outside state and so for
    79  those it can be helpful to know when Terraform will call them in relation to
    80  other events that occur in a Terraform run.
    81  
    82  The small set of special functions includes
    83  [`file`](/docs/language/functions/file.html),
    84  [`templatefile`](/docs/language/functions/templatefile.html),
    85  [`timestamp`](/docs/language/functions/timestamp.html),
    86  and [`uuid`](/docs/language/functions/uuid.html).
    87  If you are not working with these functions then you don't need
    88  to read this section, although the information here may still be interesting
    89  background information.
    90  
    91  The `file` and `templatefile` functions are intended for reading files that
    92  are included as a static part of the configuration and so Terraform will
    93  execute these functions as part of initial configuration validation, before
    94  taking any other actions with the configuration. That means you cannot use
    95  either function to read files that your configuration might generate
    96  dynamically on disk as part of the plan or apply steps.
    97  
    98  The `timestamp` function returns a representation of the current system time
    99  at the point when Terraform calls it, and the `uuid` function returns a random
   100  result which differs on each call. Without any special behavior these would
   101  would both cause the final configuration during the apply step not to match the
   102  actions shown in the plan, which violates the Terraform execution model.
   103  
   104  For that reason, Terraform arranges for both of those functions to produce
   105  [unknown value](references.html#values-not-yet-known) results during the
   106  plan step, with the real result being decided only during the apply step.
   107  For `timestamp` in particular, this means that the recorded time will be
   108  the instant when Terraform began applying the change, rather than when
   109  Terraform _planned_ the change.
   110  
   111  For more details on the behavior of these functions, refer to their own
   112  documentation pages.