Wednesday, 31 August 2022

Show Terraform Plan in Azure Pipeline Summary

You can view the terraform plan details in the Azure pipeline terraform task logs when you are executing terraform plan in Azure pipelines. However, I would be great to view  the plan in the pipeline summary. The great extension here allows us to have the terraform plan details in the pipeline summary and let's look at the steps required.

As the first step you need to install the "Azure Pipelines Terraform Tasks" terraform extension from marketplace. Then in your YAML piplines terraform plan task can be specified similar to below. You need to make sure you are using -out=mytfplan.tfplan to output the terraform plan. Then use same plan name in publishPlanResults argument as shown below.

- task: TerraformCLI@0
  displayName: terraform plan
  inputs:
    command: 'plan'
    workingDirectory: '$(System.DefaultWorkingDirectory)/ViewPlan'
    commandOptions: '-var-file=env.tfvars -out=mytfplan.tfplan'
    allowTelemetryCollection: true
    publishPlanResults: 'mytfplan'

This will make the pipeline summary to show the terraform plan summary saying what would happen if plan is executed.


Plan details will be available in Tearraform Plan tab of pipeline summary window.


Same works fine wth classic build pipelines in Azure DevOps. However, if you are using the same tasks in classic release pipelines in Azure DevOps you will not get a summary view as explained in this post.



No comments:

Popular Posts