You can use terraform abspath() function to get absolute path of a file or directory. abspath() takes a string containing a filesystem path and converts it to an absolute path. That is, if the path is not absolute, it will be joined with the current working directory.
Syntax: abspath(relative_path)
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
## create a file and directory echo 'locals { name = "debjeet" }' > main.tf mkdir module ## Open terraform console terraform console ## Get absolute path of a file abspath("main.tf") ## returns "/home/debjeet/demo/main.tf" ## Get absolute path of a folder abspath("module") ## returns "/home/debjeet/demo/module" |