1

I have a multi-stage pipeline for my terraform code. This is my first pipeline so I am sure I'm missing something but there appears to be some inconsistent behaviour that is rather frustrating.

The pipeline trigger is defined as follows:

trigger:
  branches:
    include:
      - master
  paths:
    include:
      - terraform/*

My repo has the following folder structure:

IaC
 |
 +-- terraform
 |    |
 |    +-- main.tf
 |   
 |    
 +-- azure-pipeline.yml
 +-- readme.md

My two stages are defined as follows (I cut out the job steps, its just tarraform commands):

stages:
  - stage: plan
    displayName: 'terraform plan'
    condition: eq(variables['Build.Reason'], 'PullRequest')
    ...
  - stage: apply
    displayName: 'terraform apply'
    condition: ne(variables['Build.Reason'], 'PullRequest')
    ...

Whenever I update code in the terraform directory and create a PR, the pipeline works exactly as expected. It does the terraform plan for the reviewer to see and once the PR is approved, the second stage fires and it does a terraform apply.

The issue I am having is whenever I update a file outside the terraform directory and create a PR, the first stage still runs! Oddly, once the PR is approved, the second stage does not.

Are my stage conditions to simple? Does a multi-stage pipeline always have to do something?

  • Not sure if it could be that, but you have mentioned the Path to include files from inside your Terraform directory alone. Did you check by including the outer folder as well? If all files are excluded by default and you explicitly need to include them, then that could be the reason. – Karthik Venkatesan Jul 14 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.