azure-pipelines-terraform: Terraform plan shows error with extra command

Upon the error condition below, the task did not fail the task nor the pipeline, and produced a jsonPlanFilePath of size 0. It seems an extra “terraform show -json” command is being run, but the command line is not output to the logs. This command does not take into account my -var parameters so ends up failing when using the var to access a key vault entry.

Code is at https://github.com/algattik/terraform-azure-pipelines-starter/tree/github.com/microsoft/azure-pipelines-extensions/issues/747

image

    - task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV1@0
      name: 'terraform_plan'
      displayName: 'Terraform plan'
      inputs:
        command: plan
        workingDirectory: '$(System.DefaultWorkingDirectory)/infrastructure/terraform'
        commandOptions: -out tfplan -var environment=${{ parameters.environment}} ${{ parameters.TerraformVariables }}
        environmentServiceNameAzureRM: '${{ parameters.TerraformEnvironmentServiceConnection }}'
        backendServiceArm: '${{ parameters.TerraformBackendServiceConnection }}'
2019-12-12T06:28:43.8040581Z ##[section]Starting: Terraform plan
2019-12-12T06:28:43.8045948Z ==============================================================================
2019-12-12T06:28:43.8046383Z Task         : Terraform
2019-12-12T06:28:43.8046621Z Description  : Execute terraform commands to manage resources on AzureRM, Amazon Web Services(AWS) and Google Cloud Platform(GCP)
2019-12-12T06:28:43.8046841Z Version      : 0.0.137
2019-12-12T06:28:43.8047032Z Author       : Microsoft Corporation
2019-12-12T06:28:43.8047286Z Help         : [Learn more about this task](https://aka.ms/AA5j5pf)
2019-12-12T06:28:43.8047561Z ==============================================================================
2019-12-12T06:28:43.9546191Z [command]/opt/hostedtoolcache/terraform/0.12.18/x64/terraform providers
2019-12-12T06:28:44.2264902Z .
2019-12-12T06:28:44.2266821Z ├── provider.azurerm =1.38.0
2019-12-12T06:28:44.2267798Z └── module.sqlserver
2019-12-12T06:28:44.2268733Z     └── provider.azurerm (inherited)
2019-12-12T06:28:44.2269282Z 
2019-12-12T06:28:44.2328246Z ##[warning]Multiple provider blocks specified in the .tf files in the current working drectory.
2019-12-12T06:28:44.2342819Z [command]/opt/hostedtoolcache/terraform/0.12.18/x64/terraform plan -out tfplan -var environment=stage -var department=Engineering
2019-12-12T06:28:45.5400834Z Refreshing Terraform state in-memory prior to plan...
2019-12-12T06:28:45.5402427Z The refreshed state will be used to calculate this plan, but will not be
2019-12-12T06:28:45.5403137Z persisted to local or remote state storage.
2019-12-12T06:28:45.5405546Z 
2019-12-12T06:28:47.7062647Z azurerm_resource_group.main: Refreshing state... [id=/subscriptions/a4ed7b9a-b128-49b4-a6ee-fd07ff6e296d/resourceGroups/rg-starterterraform-stage-main]
2019-12-12T06:28:47.7063754Z data.azurerm_client_config.current: Refreshing state...
2019-12-12T06:28:47.7072014Z data.azurerm_key_vault.keyvault: Refreshing state...
2019-12-12T06:28:47.7594208Z module.sqlserver.data.azurerm_key_vault_secret.sql_password: Refreshing state...
2019-12-12T06:28:47.9504198Z module.sqlserver.azurerm_sql_server.example: Refreshing state... [id=/subscriptions/a4ed7b9a-b128-49b4-a6ee-fd07ff6e296d/resourceGroups/rg-starterterraform-stage-main/providers/Microsoft.Sql/servers/algattik01sqlserver]
2019-12-12T06:28:48.0025319Z 
2019-12-12T06:28:48.0027927Z ------------------------------------------------------------------------
2019-12-12T06:28:50.2890823Z 
2019-12-12T06:28:50.2892856Z No changes. Infrastructure is up-to-date.
2019-12-12T06:28:50.2893194Z 
2019-12-12T06:28:50.2893376Z This means that Terraform did not detect any differences between your
2019-12-12T06:28:50.2893635Z configuration and real physical resources that exist. As a result, no
2019-12-12T06:28:50.2895874Z actions need to be performed.
2019-12-12T06:28:50.3229687Z [command]/opt/hostedtoolcache/terraform/0.12.18/x64/terraform version
2019-12-12T06:28:50.8207298Z Terraform v0.12.18
2019-12-12T06:28:50.8209431Z + provider.azurerm v1.38.0
2019-12-12T06:28:54.7166180Z 
2019-12-12T06:28:54.7168517Z Error: KeyVault Secret "dev-sql-password" (KeyVault URI "https://terraformstarter.vault.azure.net/") does not exist
2019-12-12T06:28:54.7170425Z 
2019-12-12T06:28:54.7172146Z   on sqlserver/main.tf line 1, in data "azurerm_key_vault_secret" "sql_password":
2019-12-12T06:28:54.7173621Z    1: data "azurerm_key_vault_secret" "sql_password" {
2019-12-12T06:28:54.7177543Z 
2019-12-12T06:28:54.7179193Z 
2019-12-12T06:28:55.7041120Z Terraform couldn't read the given file as a state or plan file.
2019-12-12T06:28:55.7042289Z The errors while attempting to read the file as each format are
2019-12-12T06:28:55.7042705Z shown below.
2019-12-12T06:28:55.7042933Z 
2019-12-12T06:28:55.7043727Z State read error: Error loading statefile: open /home/vsts/work/1/s/plan-binary-54b477c5-fc04-4727-9cab-f98aa11a7d87.tfplan: no such file or directory
2019-12-12T06:28:55.7044407Z 
2019-12-12T06:28:55.7045166Z Plan read error: open /home/vsts/work/1/s/plan-binary-54b477c5-fc04-4727-9cab-f98aa11a7d87.tfplan: no such file or directory
2019-12-12T06:28:55.7109502Z ##[section]Finishing: Terraform plan

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 20

Most upvoted comments

Facing the same issue. Init and Validate work without any problems, Plan and Apply is unable to read remote state file.

Too many command line arguments. Configuration path expected.
Terraform couldn't read the given file as a state or plan file.
The errors while attempting to read the file as each format are
shown below.

State read error: Error loading statefile: open /home/vsts/work/1/s/plan-binary-db4ed225-a78a-4ca8-88bd-8ada715d9c2d.tfplan: no such file or directory

Plan read error: open /home/vsts/work/1/s/plan-binary-db4ed225-a78a-4ca8-88bd-8ada715d9c2d.tfplan: no such file or directory
Finishing: TerraformTaskV1

I’m having the same problem. I’m running the plan action, however there’s some unexpected additional command being run, as can be seen in the logs.

[command]C:\hostedtoolcache\windows\terraform\0.12.19\x64\terraform.exe version
Terraform v0.12.19
+ provider.azurerm v1.32.1
Too many command line arguments. Configuration path expected.
Terraform couldn't read the given file as a state or plan file.
The errors while attempting to read the file as each format are
shown below.

State read error: Error loading statefile: open d:\a\1\s\plan-binary-8d32fa13-73b6-4789-9e7e-541a0ef228ee.tfplan: The system cannot find the file specified.

Plan read error: open d:\a\1\s\plan-binary-8d32fa13-73b6-4789-9e7e-541a0ef228ee.tfplan: The system cannot find the file specified.

So… what is the extension doing, and why is it failing, and why is the failure not causing the task to fail?

Hi folks,

Any news on this @Roshan-Kumar-Microsoft ? This seems to be happening with everyone. I have a very dummy pipeline and I’m also getting this error.

Thank you