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