skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    Problem solved. Two solutions:

    1. Add Terraform install task into the pipeline before adding other Terraform tasks. You can find useful links for this in the approved answer above.

    2. Run pipeline with Ubuntu (any version I guess) agent (Pipeline -> Agent Specification -> ubuntu-latest).

    I prefer the second solution because the ubuntu agent finished the tasks significantly faster than the Microsoft agent (and not because of the added install task which only took 7 seconds). For comparison: Ubuntu agent: 1 min 16 sec (first execution; the executions afterwards ~30 sec total) Windows agent: 4 min 31 sec


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search