github.com/jaredpalmer/terraform@v1.1.0-alpha20210908.0.20210911170307-88705c943a03/website/docs/language/functions/pathexpand.html.md (about)

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