-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fileexists should not return an error when subject is a directory (should always return boolean) #25316
Comments
I think that the suggestion in #22260 to introduce a new |
Indeed, even And also |
Hey everyone 👋🏻 , The You can test this out now with Terraform # Configuration using provider functions must include required_providers configuration.
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "2.5.1"
}
}
# Provider functions require Terraform 1.8 and later.
required_version = ">= 1.8.0"
}
output "exists" {
value = provider::local::direxists("${path.module}/example-directory")
}
output "does_not_exist" {
value = provider::local::direxists("${path.module}/fake-directory")
} $ tree
.
├── example-directory
└── main.tf
2 directories, 1 file
$ terraform plan
Changes to Outputs:
+ does_not_exist = false
+ exists = true
It's designed similar to If you run into any problems testing out the new function, please create an issue over in the |
This approach doesn't work in Terragrunt configuration files, which only have access to Terraform's built-in functions. Is there a particular reason why this functionality cannot be added inside Terraform itself? It is confusing and not consistent at all that checking files is built-in, but checking a folder needs a separate provider. |
A function such as |
Understood, and in general it seems like a good approach. In this particular case I'd argue that moving it to be a built-in function would make sense though, given that this is a very natural pair for the existing |
Yes, go ahead an open a new issue. We can use it to both nudge this idea in the future and gather support for the request (move |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Terraform Version
Terraform Configuration Files
Debug Output
Crash Output
Expected Behavior
Actual Behavior
Steps to Reproduce
Additional Context
I am trying to determine if the
node_modules
directory exists to determine ifnpm install
needs to be performed, e.g.There doesn't appear to be a useful case where you would want to error on a file being a directory (that I can think of) but in this case there also doesn't appear to be any other native way to discover if a directory resource exists (no
direxists
function for example)References
Identical to issue #22260 but with a different use case
The text was updated successfully, but these errors were encountered: