# Data source from command output?

**URL:** <https://discuss.hashicorp.com/t/data-source-from-command-output/52634>\
**Category:** Terraform\
**Created:** [April 12, 2023, 2:57pm UTC](https://discuss.hashicorp.com/t/data-source-from-command-output/52634 "2023-04-12T14:57:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnmvisser](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/dnmvisser/32/43275_2.png) [@dnmvisser](https://discuss.hashicorp.com/u/dnmvisser)\
**Post date:** [April 12, 2023, 2:57pm UTC](https://discuss.hashicorp.com/t/data-source-from-command-output/52634/1 "2023-04-12T14:57:50Z")

</div>

Hi, I am trying to find a way to fetch variables from an external command, but so far I did not succeed.  
The things that comes closest seems to be local\_file:

```auto
data "local_file" "foo" {
  filename = "/opt/foo.txt"
}

```

But I would like to retrieve the output of a command, and use that.  
I guess such a thing would look something like:

```auto
data "local_command" "foo" {
   command = "/usr/local/bin/foo --name bar --context baz"
}

```

thx!

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/dnmvisser/32/43275_2.png) [@dnmvisser](https://discuss.hashicorp.com/u/dnmvisser)\
**Post date:** [April 12, 2023, 3:45pm UTC](https://discuss.hashicorp.com/t/data-source-from-command-output/52634/2 "2023-04-12T15:45:43Z")

</div>

I think [Terraform Registry](https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/external) would be good enough, albeit with a wrapper script to handle the JSON formatted variables.

---

<div class="post-metadata">

**Author:** ![macmiranda](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/macmiranda/32/34065_2.png) [@macmiranda](https://discuss.hashicorp.com/u/macmiranda)\
**Post date:** [April 12, 2023, 3:59pm UTC](https://discuss.hashicorp.com/t/data-source-from-command-output/52634/3 "2023-04-12T15:59:49Z")

</div>

An alternative would be to save the output of your command to a file using the [local-exec](https://developer.hashicorp.com/terraform/language/resources/provisioners/local-exec) provisioner inside a [null\_resource](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) and read the file using the [local\_file](https://registry.terraform.io/providers/hashicorp/local/latest/docs/data-sources/file) data source you mentioned.

Ultimately, it will depend on whether you want to make the output available to use inside your Terraform code (in which case the JSON output would be preferable) or just pass it on to a resource as a blob.

Also note:

> Terraform Enterprise does not guarantee availability of any particular language runtimes or external programs beyond standard shell utilities, so it is not recommended to use this data source within configurations that are applied within Terraform Enterprise.
