Safeguard
Security Guides•

What is the Terraform external data source, and what should you check?

The external data source runs a program and feeds its output into Terraform. Why the docs call it an escape hatch and what a security reviewer should ask.

Safeguard Security Team
3 min read

The external data source runs a program you name and uses the JSON it prints as data in your configuration. Its own documentation calls it an escape hatch for exceptional cases, so a reviewer should treat every use as code execution during planning.

What it does

You give the data source a program list and an optional query map. Terraform runs the program, passes it the query, and reads a result back. The provider documentation says the mechanism is for situations where a first class provider is not more appropriate, and that its capabilities are limited compared with a true data source.

Why reviewers should care

Data sources are read during planning. An external program therefore runs on whatever machine runs terraform plan, which may be a developer laptop or a CI runner holding cloud credentials. A pull request that adds one is a pull request that adds a script to your pipeline.

The documentation also notes that this approach hurts portability, since it creates dependencies on programs and libraries that may not exist on every operating system, and that Terraform Enterprise does not guarantee any language runtime beyond standard shell utilities.

Review checklist

  1. What program runs, and where does its source live? A script in the repository is reviewable. A tool fetched at runtime is not.
  2. What does it read: environment variables, files, network endpoints?
  3. What credentials does the runner hold when it runs?
  4. Does the query include values that could carry untrusted input?
  5. Is there a provider data source that does the same job?
  6. Is the program pinned, and is its dependency list pinned?

Alternatives

NeedTry first
Read cloud dataThe provider's own data source
Compute a valueTerraform functions and locals
Fetch a file or HTTP responseA purpose built provider data source
Run a one off task after createA provider feature or configuration management

Practical limits to set

  • Allow the external data source only in reviewed modules, and flag it with a code owner rule.
  • Run plan in a runner with narrow credentials, since plan executes the program.
  • Log what the script does, without printing secrets.

Quick check

Does the external data source run during apply only?

No. As a data source, it can run during planning, so a plan can execute the program.

Is it deprecated?

The documentation describes it as an escape hatch for exceptional situations, not as deprecated.

Can the script output be a secret?

It can be, so mark downstream values sensitive, and remember state may still store them.

Safeguard offers SBOM and dependency scanning and policy gates that can block a pull request on findings, and you can try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.