Terraform: [Errno 2] No such file or directory using External Data Source

Created on 5 Mar 2019  ยท  3Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.11.11 + provider.external v1.0.0

Terraform Configuration Files

data "external" "script" {
program = ["python", "${path.module}\secret.py -id SFTP-Key -keyname private-key"]
}

output "Private Key" {
value = "${data.external.script.result.program}"
}

Expected Behavior

I was hoping to recieve the output of the script in the same way stdout would after running python C:\Users\oliverj\Documents\Code\github\test\secret.py -id SFTP-Key -keyname private-key

Actual Behavior

Error: Error refreshing state: 1 error(s) occurred:

  • data.external.script: 1 error(s) occurred:

  • data.external.script: data.external.script: failed to execute "python": python: can't open file 'C:\Users\oliverj\Documents\Code\github\test\secret.py -id SFTP-Key -keyname private-key': [Errno 2] No such file or directory-->

Steps to Reproduce

  1. terraform init
  2. terraform plan or terraform apply

Additional Context

I am able to runpython C:\Users\oliverj\Documents\Code\github\test\secret.py -id SFTP-Key -keyname private-key without issue

question

Most helpful comment

Hi @JasonOliverEmaze,

The external data source expects each argument to be a separate element in the list, like this:

  program = ["python", "${path.module}\secret.py", "-id", "SFTP-Key", "-keyname", "private-key"]

I think with your current configuration, Python is trying to treat the entire string C:\Users\oliverj\Documents\Code\github\test\secret.py -id SFTP-Key -keyname private-key as the script to run, which therefore doesn't work.

All 3 comments

Hi @JasonOliverEmaze,

The external data source expects each argument to be a separate element in the list, like this:

  program = ["python", "${path.module}\secret.py", "-id", "SFTP-Key", "-keyname", "private-key"]

I think with your current configuration, Python is trying to treat the entire string C:\Users\oliverj\Documents\Code\github\test\secret.py -id SFTP-Key -keyname private-key as the script to run, which therefore doesn't work.

failed to execute "python": it finds the python file prints some of the values in it but still gives this error any idea about this

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.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shanmugakarna picture shanmugakarna  ยท  3Comments

larstobi picture larstobi  ยท  3Comments

franklinwise picture franklinwise  ยท  3Comments

pawelsawicz picture pawelsawicz  ยท  3Comments

ronnix picture ronnix  ยท  3Comments