In my ADO pipeline I have stage called terraform_plan and am referring it to another stage called manual_validation. But am getting the below error.
An error occurred while loading the YAML build pipeline. Unrecognized value: ‘terraform_plan’. Located at position 70 within expression: and(in(dependencies.manual_validation.result,’Succeeded’,’Skipped’), terraform_plan.outputs[‘terraform_plan_job.produceVar.TERRAFORM_PLAN_HAS_CHANGES’], ‘true’)). For more help, refer to https://go.microsoft.com/fwlink/?linkid=842996
Pipeline code is given below.
stages:
- stage: terraform_plan
displayName: Terraform Provisioning - Plan
variables:
pool:
vmImage: ubuntu-latest
jobs:
- job: terraform_plan_job
displayName: Plan and Persist
steps:
- checkout: self
referring the terraform_plan in below stage condition.
- stage: manual_validation
displayName: Manual Validation Phase
condition: and(succeeded(), eq('${{ parameters.RequireManualValidation }}', true), eq(dependencies.terraform_plan.outputs['terraform_plan_job.setvar.HAS_DESTROY_CHANGES'], 'true'), ne(variables['Build.Reason'], 'PullRequest'))
pool: server
jobs:
- job: manual_validation_test
displayName: Please approve in order to proceed
timeoutInMinutes: ${{ parameters.ApprovalTimeoutMinutes }}
steps:
- task: ManualValidation@0
inputs:
notifyUsers: ${{ parameters.PlanApprovers }}
instructions: the planned changes to the infrastructure
onTimeout: reject
- stage: terraform_apply
displayName: "Terraform Provisioning: Apply"
variables:
condition: and(in(dependencies.manual_validation.result,'Succeeded','Skipped'), terraform_plan.outputs['terraform_plan_job.produceVar.TERRAFORM_PLAN_HAS_CHANGES'], 'true'))
pool:
vmImage: ubuntu-latest
jobs:
- job: terraform_apply_job
I tried using dependencies and "stageDependencies" but both are not working
2
Answers
There is an obvious syntax error. Look at what happens if you break down the expression slightly.
The parenthesis aren’t even balanced. You probably wanted to write
eq(terraform_plan.outputs['terraform_plan_job.produceVar.TERRAFORM_PLAN_HAS_CHANGES'], 'true')
, but that’s probably not going to work as-is; it probably does need to be qualified withstageDependencies
and so forth.To solve this issue, you need to modify the condition in the terraform_apply stage.