How to fix Error: Provisioner execution failed - command not found in Terraform

TerraformINTERMEDIATEMEDIUMUpdated Dec 31, 2025· 113 views

This error occurs when a Terraform provisioner (local-exec, remote-exec, or file) tries to execute a command that doesn't exist in the target environment's PATH. This typically happens when commands are called by name rather than full path, or when dependencies aren't available in Terraform Cloud environments.

Quick fix

Fixes Error: Provisioner execution failed - command not found

provisioner "local-exec" {
  command = "gcloud auth list"
}
  1. Use the full path to the command instead of relying on PATH
  2. Explicitly specify the interpreter for local-exec provisioners
  3. Set the working directory for relative paths to work correctly
  4. Install dependencies in Terraform Cloud or use local-exec for setup
terraform — error
provisioner "local-exec" {
command = "gcloud auth list"
}
Error: Provisioner execution failed - command not found

What this error means

When Terraform executes provisioners, they rely on commands available in the system PATH. If a command (like gcloud, ssh-keygen, or any custom script) is not found in the expected PATH, the provisioner fails with exit status 127. This is especially common in local-exec provisioners running in Terraform Cloud where the execution environment may differ from your local machine, or when provisioners reference commands that aren't installed or aren't in the expected location.

Typical symptoms

  • Provisioner execution fails with 'command not found' error
  • Exit status 127 appears in error output (standard Unix 'not found' error code)
  • Works locally but fails in Terraform Cloud
  • Error message includes full command path like '/bin/sh: 1: gcloud: not found'
  • Remote-exec provisioner can't find commands on target instance

Common causes

  1. Command is not installed in the environment where the provisioner runs
  2. Command is not in the system PATH or the environment's PATH is different than expected
  3. Using relative paths to custom scripts instead of absolute paths
  4. Running in Terraform Cloud where the execution environment lacks required tools
  5. Provisioner runs in a different shell environment than expected
  6. Working directory is not set correctly, causing relative paths to fail

How to fix "Error: Provisioner execution failed - command not found"

1Use the full path to the command instead of relying on PATH

Replace the command name with its absolute path. For example, instead of:

hcl
provisioner "local-exec" {
  command = "gcloud auth list"
}

Use:

hcl
provisioner "local-exec" {
  command = "/usr/bin/gcloud auth list"
}

Find the full path using which <command> on Linux/macOS or where <command> on Windows.

2Explicitly specify the interpreter for local-exec provisioners

Use the interpreter argument to ensure commands run in a known shell environment:

hcl
provisioner "local-exec" {
  interpreter = ["bash", "-c"]
  command     = "echo 'Running in bash'"
}

This is especially important when using shell-specific syntax like variable expansion or pipes.

3Set the working directory for relative paths to work correctly

Use the working_dir argument to ensure relative paths resolve correctly:

hcl
provisioner "local-exec" {
  command     = "./deploy.sh"
  working_dir = "${path.module}/scripts"
}

Ensure the directory exists before the provisioner runs.

4Install dependencies in Terraform Cloud or use local-exec for setup

If running in Terraform Cloud, ensure all required tools are available in that environment. For the gcloud example, you may need to:

hcl
provisioner "local-exec" {
  command = "curl https://sdk.cloud.google.com | bash"
}

provisioner "local-exec" {
  command = "gcloud auth list"
}

Alternatively, use a custom Docker image or build step that includes required tools.

5Use absolute paths for custom scripts in provisioners

When referencing your own scripts, use absolute paths instead of relative paths:

hcl
provisioner "local-exec" {
  command = "${path.module}/scripts/deploy.sh"
}

Never rely on the current working directory for script resolution.

6Configure on_failure behavior to diagnose errors

Use on_failure = "continue" temporarily to see error output without stopping the entire apply:

hcl
provisioner "local-exec" {
  command     = "failing-command"
  on_failure  = "continue"
}

This helps you diagnose PATH or environment issues without rolling back resources. Once fixed, remove this argument or set it back to "fail".

Advanced notes

Exit status 127 is the standard Unix convention for 'command not found'. On remote systems with restrictive shells or limited PATH configurations, all relative command resolution fails. For remote-exec provisioners, ensure the target instance has the necessary commands installed and that the connection user has permission to execute them. In Terraform Cloud, the execution happens in a stateless, minimal Linux environment—many system utilities and programming tools are not available by default. Always prefer explicit paths over PATH resolution. When using remote-exec on instances where you control the image, pre-bake required tools into the AMI or container to avoid provisioner failures.

Frequently asked questions

What does "Error: Provisioner execution failed - command not found" mean?
When Terraform executes provisioners, they rely on commands available in the system PATH. If a command (like gcloud, ssh-keygen, or any custom script) is not found in the expected PATH, the provisioner fails with exit status 127. This is especially common in local-exec provisioners running in Terraform Cloud where the execution environment may differ from your local machine, or when provisioners reference commands that aren't installed or aren't in the expected location.
How do I fix "Error: Provisioner execution failed - command not found"?
This error occurs when a Terraform provisioner (local-exec, remote-exec, or file) tries to execute a command that doesn't exist in the target environment's PATH. This typically happens when commands are called by name rather than full path, or when dependencies aren't available in Terraform Cloud environments.
What causes "Error: Provisioner execution failed - command not found"?
Command is not installed in the environment where the provisioner runs Command is not in the system PATH or the environment's PATH is different than expected Using relative paths to custom scripts instead of absolute paths
Is the "Error: Provisioner execution failed - command not found" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading