Skip to content

Instantly share code, notes, and snippets.

@maxsei
Created June 6, 2026 13:47
Show Gist options
  • Select an option

  • Save maxsei/99c4ee04f5f68e55e3d977adfba1253f to your computer and use it in GitHub Desktop.

Select an option

Save maxsei/99c4ee04f5f68e55e3d977adfba1253f to your computer and use it in GitHub Desktop.
how to use data external scripts in terraform
console.log(
JSON.stringify({
result: "hello world",
json: JSON.stringify({
hello: "world",
}),
}),
);
data "external" "hello_world" {
program = ["node", "main.js"]
}
output "result" {
value = data.external.hello_world.result["result"]
}
output "json" {
value = jsondecode(data.external.hello_world.result["json"])
}
$ tofu apply
data.external.hello_world: Reading...
data.external.hello_world: Read complete after 0s [id=-]
No changes. Your infrastructure matches the configuration.
OpenTofu has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
json = {
"hello" = "world"
}
result = "hello world"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment