github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/pathexpand.html.md (about)

     1  ---
     2  layout: "functions"
     3  page_title: "pathexpand - Functions - Configuration Language"
     4  sidebar_current: "docs-funcs-file-pathexpand"
     5  description: |-
     6    The pathexpand function expands a leading ~ character to the current user's
     7    home directory.
     8  ---
     9  
    10  # `pathexpand` Function
    11  
    12  -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
    13  earlier, see
    14  [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
    15  
    16  `pathexpand` takes a filesystem path that might begin with a `~` segment,
    17  and if so it replaces that segment with the current user's home directory
    18  path.
    19  
    20  This function works only with the path string and does not access the
    21  filesystem itself. It is therefore unable to take into account filesystem
    22  features such as symlinks.
    23  
    24  If the leading segment in the path is not `~` then the given path is returned
    25  unmodified.
    26  
    27  Using this function in resource arguments will cause spurious diffs if the
    28  same configuration is run by multiple users with different home directory
    29  paths, or used on different host operating systems. We recommend using this
    30  function only for transient values, such as in `connection` and `provisioner`
    31  blocks to locate SSH keys, etc.
    32  
    33  The rules for determining the "home directory" for the current user vary
    34  depending on host operating system.
    35  
    36  **For Unix systems**, the following sources are consulted, in order of preference:
    37  
    38  * The `HOME` environment variable.
    39  * The result of running `getent passwd` followed by the Terraform process uid.
    40  * The result of running `cd && pwd` in `sh`.
    41  
    42  **For Windows systems**, there is not really the concept of a home directory
    43  in the same sense as on Unix, but the following sources are consulted in
    44  order of preference:
    45  
    46  * The `HOME` environment variable.
    47  * The `HOMEDRIVE` and `HOMEPATH` environment variables, if both are set.
    48  * The `USERPROFILE` environment variable.
    49  
    50  The exact rules employed for each operating system may change in future
    51  releases of Terraform.
    52  
    53  ## Examples
    54  
    55  ```
    56  > pathexpand("~/.ssh/id_rsa")
    57  /home/steve/.ssh/id_rsa
    58  > pathexpand("/etc/resolv.conf")
    59  /etc/resolv.conf
    60  ```