Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 11:49:21 +01:00
|
|
|
---
|
2020-03-18 18:46:47 -04:00
|
|
|
page_title: fileexists - Functions - Configuration Language
|
|
|
|
description: The fileexists function determines whether a file exists at a given path.
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 11:49:21 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
# `fileexists` Function
|
|
|
|
|
|
|
|
`fileexists` determines whether a file exists at a given path.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
fileexists(path)
|
|
|
|
```
|
|
|
|
|
|
|
|
Functions are evaluated during configuration parsing rather than at apply time,
|
|
|
|
so this function can only be used with files that are already present on disk
|
|
|
|
before Packer takes any actions.
|
|
|
|
|
|
|
|
This function works only with regular files. If used with a directory, FIFO,
|
|
|
|
or other special mode, it will return an error.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2020-05-29 17:12:05 -04:00
|
|
|
```shell-session
|
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.
* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 11:49:21 +01:00
|
|
|
> fileexists("${path.folder}/hello.txt")
|
|
|
|
true
|
|
|
|
```
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
fileexists("custom-section.sh") ? file("custom-section.sh") : local.default_content
|
|
|
|
```
|
|
|
|
|
|
|
|
## Related Functions
|
|
|
|
|
2021-03-23 12:02:05 +01:00
|
|
|
- [`file`](/docs/templates/hcl_templates/functions/file/file) reads the contents
|
|
|
|
of a file at a given path.
|