microsoft / azure-pipelines-extensions

Collection of all RM and deployment extensions
http://www.visualstudio.com/explore/release-management-vs
MIT License
279 stars 422 forks source link

Terraform: irrelevant error message if working directory does not exist #780

Open algattik opened 4 years ago

algattik commented 4 years ago

Pipeline YAML:

  - task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV1@0
    displayName: Terraform init
    inputs:
      workingDirectory: a/directory/that/does/not/exist

Output:

Starting: Terraform init
==============================================================================
Task         : Terraform
Description  : Execute terraform commands to manage resources on AzureRM, Amazon Web Services(AWS) and Google Cloud Platform(GCP)
Version      : 0.0.142
Author       : Microsoft Corporation
Help         : [Learn more about this task](https://aka.ms/AA5j5pf)
==============================================================================
/opt/hostedtoolcache/terraform/0.12.20/x64/terraform init -backend-config=storage_account_name=dataopsterraform -backend-config=container_name=terraformstate -backend-config=key=test.tfstate -backend-config=resource_group_name=dataops-terraform -backend-config=arm_subscription_id=a4ed7b9a-b128-49b4-a6ee-fd07ff6e296d -backend-config=arm_tenant_id=*** -backend-config=arm_client_id=*** -backend-config=arm_client_secret=***
##[error]Error: There was an error when attempting to execute the process '/opt/hostedtoolcache/terraform/0.12.20/x64/terraform'. This may indicate the process failed to start. Error: spawn /opt/hostedtoolcache/terraform/0.12.20/x64/terraform ENOENT
Finishing: Terraform init

Expected error message:

The directory a/directory/that/does/not/exist does not exist.
johnnyhuy commented 4 years ago

Yep, I'm getting a similar error. I suspect the task is refusing to get stdout of the script it runs.

hdpoe commented 4 years ago

I also spent several hours trying to solve a nonexistent problem with my agent before realizing I had a slight typo in the working directory name.

Had the following error in the debug logs. Please either fix or document this.

##[debug]arguments:
##[debug]   init
##[debug]   -backend-config=storage_account_name=**redacted**
##[debug]   -backend-config=container_name=**redacted**
##[debug]   -backend-config=key=**redacted**
##[debug]   -backend-config=resource_group_name=**redacted**
##[debug]   -backend-config=arm_subscription_id=**redacted**
##[debug]   -backend-config=arm_tenant_id=***
##[debug]   -backend-config=arm_client_id=***
##[debug]   -backend-config=arm_client_secret=***
/opt/tfsagent/ad1/_work/_tool/terraform/0.12.24/x64/terraform init -backend-config=storage_account_name=**redacted** -backend-config=container_name=**redacted**-backend-config=key=**redacted** -backend-config=resource_group_name=**redacted** -backend-config=arm_subscription_id=**redacted** -backend-config=arm_tenant_id=*** -backend-config=arm_client_id=*** -backend-config=arm_client_secret=***
##[debug]task result: Failed
##[error]Error: There was an error when attempting to execute the process '/opt/tfsagent/ad1/_work/_tool/terraform/0.12.24/x64/terraform'. This may indicate the process failed to start. Error: spawn /opt/tfsagent/ad1/_work/_tool/terraform/0.12.24/x64/terraform ENOENT
##[debug]Processed: ##vso[task.issue type=error;]Error: There was an error when attempting to execute the process '/opt/tfsagent/ad1/_work/_tool/terraform/0.12.24/x64/terraform'. This may indicate the process failed to start. Error: spawn /opt/tfsagent/ad1/_work/_tool/terraform/0.12.24/x64/terraform ENOENT
##[debug]Processed: ##vso[task.complete result=Failed;]Error: There was an error when attempting to execute the process '/opt/tfsagent/ad1/_work/_tool/terraform/0.12.24/x64/terraform'. This may indicate the process failed to start. Error: spawn /opt/tfsagent/ad1/_work/_tool/terraform/0.12.24/x64/terraform ENOENT
Finishing: terraformInit
DenWin commented 3 years ago

I would assume the error comes from terraform cannot be executed in a directory that does not exist.

I would rather add an additional verification the workingDirectory does actually exist!

stewartadam commented 3 years ago

+1, just bumped against this - would be great to have a more helpful error message when this happens.

yunqian44 commented 2 years ago

The error message is misleading. The problem is actually that Terraform can't find your TF file. We should manually add "-check: self" to the Task of "terraform init"; For Example: ....... steps: - checkout: self