Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: spawn terraform ENOENT during Azure Pipeline Terraform

When attempting to run terraform init as a task in an Azure Pipeline, it errors stating

spawn C:\hostedtoolcache\windows\terraform\0.12.7\x64\terraform.exe ENOENT

The installation appears fine, as basic functionality is verified during the install step (terraform version)

Relevant Pipeline Tasks

...
  - task: TerraformInstaller@0
    displayName: 'Install Terraform 0.12.7'
    inputs:
      terraformVersion: 0.12.7
  - task: TerraformTaskV1@0
    displayName: 'Terraform : init'
    inputs:
        command: 'init'
        workingDirectory: '$(System.DefaultWorkingDirectory)/Terraform/terraform'
...

Install Terraform 0.12.7

...
Verifying Terraform installation...
C:\hostedtoolcache\windows\terraform\0.12.7\x64\terraform.exe version
Terraform v0.12.7

Your version of Terraform is out of date! The latest version
is 0.12.19. You can update by downloading from www.terraform.io/downloads.html
Finishing: Install Terraform 0.12.7

Terraform : init

...
C:\hostedtoolcache\windows\terraform\0.12.7\x64\terraform.exe validate
##[error]Error: There was an error when attempting to execute the process 'C:\hostedtoolcache\windows\terraform\0.12.7\x64\terraform.exe'. This may indicate the process failed to start. Error: spawn C:\hostedtoolcache\windows\terraform\0.12.7\x64\terraform.exe ENOENT
Finishing: Terraform : validate

Many other users reported success fixing this by adding a checkout step, but the pipeline automatically does this (presumably previous versions did not), and manually adding it had no effect (actually took 2s longer due to different options).

like image 376
ti7 Avatar asked Jan 17 '20 21:01

ti7


1 Answers

Turns out the working directory path was incorrect, as the directory structure had been changed.

Changing all the named working directories from Terraform/terraform to just terraform corrected the issue.

Presumably both in this and cases where checkout was not performed, Terraform simply cannot locate main.tf, but the error is missing or lost.

like image 136
ti7 Avatar answered Nov 11 '22 06:11

ti7