You can use terraform fileexists() function to check if a file exists in terraform. fileexists() determines whether a file exists at a given path.
Syntax: fileexists(file_path)
Example:
1 2 3 4 5 6 7 8 9 10 11 12 |
## create a file with some content echo 'locals { name = "debjeet" }' > main.tf ## Open terraform console terraform console ## Check if a file exists in terraform fileexists("main.tf") ## returns true fileexists("outputs.tf") ## returns false |