Search code examples
azureazure-devopsterraformyamlpipeline

Azure DevOps Pipeline unable to locate executable file: 'terraform'


I´m trying to setup a pipeline in Azure DevOps which initiates a Azure Resource Group. The configurations for which are saved in a .tf file in the DevOps repository.

The pipeline was created with the classic editor. Following tasks were added to the job agent in the same order: terraform init (Terraform CLI) and Build Project (.NET Core).

Terraform is already installed (file path was added to environment variables).

I´m really new to this and am trying to do my first steps. So any help would be appreciated. Also, you can tell me if any important information is missing.

This is the job agent´s log for the Terraform init task:

2023-01-19T15:15:19.3880770Z ##[section]Starting: terraform init
2023-01-19T15:15:19.3895740Z ==============================================================================
2023-01-19T15:15:19.3896080Z Task         : Terraform CLI
2023-01-19T15:15:19.3896240Z Description  : Execute terraform cli commands
2023-01-19T15:15:19.3896440Z Version      : 0.7.8
2023-01-19T15:15:19.3896590Z Author       : Charles Zipp
2023-01-19T15:15:19.3896770Z Help         : 
2023-01-19T15:15:19.3896890Z ==============================================================================
2023-01-19T15:15:21.3070520Z ##[error]Error: Unable to locate executable file: 'terraform'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
2023-01-19T15:15:21.3186320Z ##[error]Error: Unable to locate executable file: 'terraform'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
2023-01-19T15:15:21.5201550Z ##[section]Finishing: terraform init

I have tried running this in various Backend Type settings. Also have tried to change the Agent specifications multiple times. Furthermore have I tried runnning this after putting the terraform.exe in the repository root.

My expection was that the pipeline creates a new resource group, but the task won´t even be executed.


Solution

  • It looks like you're using the Azure Pipelines Terraform Tasks extension for Azure DevOps which also includes an installer task for Terraform called "TerraformInstaller". Try adding that to your pipeline before "terraform init" to ensure that Terraform is installed (by default it will install the latest version unless you give it a specific one) and is correct for the agent's OS.

    As to why the existing terraform binary isn't being found my guess is that you've been trying to use the windows version of terraform (terraform.exe) instead of the linux version which is just terraform and that the pipeline is running on a linux agent. I'm guessing this because the output of the task says that it can't find the file named terraform without the .exe extension.