You can use terraform basename() function to get only the file name from the file path. basename() takes a string containing a filesystem path and removes all except the last portion from it.
Syntax: basename(file_path)
Example:
1 2 3 4 5 6 7 8 9 10 |
## Open terraform console terraform console ## Get only file name from filepath basename("/home/debjeet/main.tf") ## returns "main.tf" ## Get only file path without the file name dirname("/home/debjeet/main.tf") ## returns "/home/debjeet" |