-
Notifications
You must be signed in to change notification settings - Fork 50
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
Failure on Windows with paths that include a single quote (') #200
Comments
Hi @KyleKotowick 👋🏻 , thanks for submitting the issue and sorry you're running into trouble here. Can you try surrounding the single quote with double quotes (you'll need to escape them in your terraform config) and see if that solves it? data "external" "run" {
program = [
"powershell.exe",
"foo \"'\" bar.ps1",
]
}
output "run" {
value = data.external.run.result
} I've made an attempt recreating the issue with a gist with an example of quoting/escaping: https://gist.github.com/austinvalle/5305fd995a8e7e8d4ceb6067773592e1 |
Hi @austinvalle, thanks for the reply. Yes, quoting it does work. The problem is that the file path in our system is dynamically specified, and as far as I'm aware, there's no Terraform function that could automatically do that kind of quoting. In our module, we use the variable "working_dir" {
type = string
}
data "external" "run" {
working_dir = var.working_dir
program = [
"powershell.exe",
"${abspath(path.module)}/script.ps1"
]
}
output "run" {
value = data.external.run.result
} This allows us to build a module that runs our script, but allows the user to run it in whatever working directory they like. For reference, this is for our fairly popular Invicton-Labs/shell-data/external and Invicton-Labs/shell-resource/external modules. The issue arises if the user's Terraform directory (that uses our module) has a We could try doing a |
Thanks for the additional info! You'll have to bear with me as I'm not super proficient with Powershell 😄 If the main goal is to invoke a Powershell script from a path that may or may not contain fun characters, are you able to utilize the Looking at https://stackoverflow.com/a/45762288 they differ in how the file paths are processed and it may alleviate the quote handling. I created an example in a folder called main.tflocals {
curr_path = "${abspath(path.module)}/script.ps1"
}
data "external" "run_file" {
program = [
"powershell.exe",
"-File",
"${local.curr_path}"
]
}
output "run_file" {
value = data.external.run_file.result
}
output "local_curr_path" {
value = local.curr_path
} script.ps1Write-Output @{ result = "hello" } | ConvertTo-Json result |
Terraform CLI and Provider Versions
Terraform Configuration
Expected Behavior
Single quotes are valid in file/folder names on Windows. This should execute the given script file as expected.
Actual Behavior
Steps to Reproduce
terraform apply
How much impact is this issue causing?
High
Logs
No response
Additional Information
I've tried escaping the single quote with both a backtick and a backslash, neither fix the issue.
Code of Conduct
The text was updated successfully, but these errors were encountered: