Plan on Pull Request

Pull Request Plan in env0

env0 allows you to control and monitor your infrastructure code changes via pull request automation. When setting Pull Request Plan (aka PR Plan), your environment will automatically run a deployment consisting of only the Terraform Plan phase (without running the Terraform Apply) and share the results with you via a comment on your pull request. Pull Request Plan will run on every push to the opened pull request.

For a PR Plan to run automatically, the following prerequisites must be met:

  1. The environment has Pull Request Plan enabled.
  2. The environment originated from a VCS-integrated template, and its configured revision is the same as the base branch (aka target) of the opened pull request.

Enable Pull Request Plan

Go to your existing Environment in env0, and head to the Settings tab.
Enable the checkbox stating "Run Terraform Plan on Pull Requests targeting this branch".

You can choose to run by the following options:

  • Any change - your environment will receive PR Plan on every push
  • Changes on Template Directory files - your environment will receive PR Plan on every push which the push contains file changes under Terraform Folder
  • Changes by file filter pattern - your environment will receive PR Plan on every push in which the push contains file changes by match to the pattern. see below how to configure the glob pattern.

You can follow the Deployment History for deployments of PR Plan type:

๐Ÿ“˜

Glob pattern

Glob patterns specify sets of filenames with wildcard characters. For example, *.txt or my_folder/**

It means you can configure pattern by git repository which re-deploy environment only if the push contains files that change by free pattern.

For example, you can configure pattern like src/project_1/**
In this case, we will re-deploy only if the push contains file(s) which starts with src/project_1/...

We also support extglob patterns with that you can write pattern which ignores files or use a list of folders.
Note that for extglob, when using OR/AND statements, make sure to wrap each option with parentheses, for example:

  • !(third/path/\*\*)+(first/path/**|second/path/myfile.txt)
    This means we will listen to any change in first/path and second/path/myfile.txt, and ignore changes under third/path. (Recommend including exclusions first.)
  • +(Terraform/!(prod)**|Terragrunt/dev/**)
    Listen for any changes in Terraform or Terragrunt/dev but ignore any changes in Terraform/prod

๐Ÿ“˜

PR Plans Concurrency

PR Plans do not lock the Terraform state, and can be run in parallel. If a bunch of PR Plans are queued in sequence, all of these PR Plans will run simultaneously.

๐Ÿšง

Status Checks

If the PR plan doesn't run because the push doesn't contain change files, we will mark the latest status of this PR that we got or skipped status if the Version Control supported it. Additional policy configuration can be found under Do Not Report Skipped Status Check.

๐Ÿ“˜

PR Plans from Merge Commits

Did you know you can control whether Merge commits will trigger PR Plans? Consider this policy setting: Skip PR Plan on Merge Commits

Pull Request Comments

env0 will make a comment on your pull request for three different reasons:

  1. When a PR Plan has started:
948

GitHub

1013

GitLab

1194

Azure DevOps

  1. When a PR Plan has finished successfully: (full log is attached under Plan Details)
942

GitHub

987

GitLab

1892

Bitbucket

1193

Azure DevOps

  1. When a PR Plan has failed:
929

GitHub

993

GitLab

1894

Bitbucket

1186

Azure DevOps

  1. Rerun a PR Plan:
    you can rerun a PR plan deployment, the newly created deployment will be an exact snapshot in terms of commits and code source of the original Pr plan.

GitHub Commit Status Checks

env0 will set a status check on the commit you want to merge in the pull request
We will make the status as failing when the run had failed to generate a Terraform plan, and successful when a plan was generated.

  1. When we push the "PR plan" to the queue

  1. When we start running "PR Plan" - Notice - in case you didn't approve the previous deployment we will wait until then

  1. When a Terraform plan was generated:

  1. When the run was not able to generate a proper Terraform plan:

  1. If you linked your PR to multiple environments you will get the summary of all the PR Plans

By pressing on Details GitHub will forward you to the Checks tab

and by pressing View more details on env0 you will be forward to your environment on env0

GitLab Pipelines

env0 will run set a GitLab pipeline and job status on the commit you want to merge in the merge request.
We will show its status as failed when the run had failed to generate a Terraform plan, and successful when a plan was generated.

1944

A Merge Request and its associated env0 pipeline run status

Clicking the pipeline on the Merge Request will reveal which env0 environment deployments were triggers, and their status.
Clicking the status will take you back to env0, where you can see more details on this automatic plan run.

  1. When we start running the PR plan we mark the commit to be in progress

  1. When a Terraform plan was generated:

  1. When the run was not able to generate a proper Terraform plan:
1378

A Merge Request pipeline jobs running for each env0 environment

Bitbucket Commit Build Status

env0 will set a status check on the commit you want to merge in the pull request.
We will set the status as failing when the run had failed to generate a Terraform plan, and successful when a plan was generated.

  1. When we start running the PR plan we mark the commit to be in progress

  1. When a Terraform plan was generated:

  1. When the run was not able to generate a proper Terraform plan:

Azure DevOps PR Status

env0 will set a status check on your pull request.
We will set the status as failing when the run had failed to generate a Terraform plan, and successful when a plan was generated.

  1. When we start running the PR plan we mark in the PR status to be pending

  1. When a Terraform plan was generated:

  1. When the run was not able to generate a proper Terraform plan:

Rerun a PR Plan

You can rerun a PR plan deployment on the deployment page.
The newly created deployment will be an exact snapshot of the commits and code source of the original PR plan.
This will recreate the comment on the PR and the status checks.

Deployment Comment

When a PR Plan is triggered - a comment will be added in env0, linking to the PR

:pencil2: Suggested Content

Do Not Report Skipped Status Check

Skip PR Plan on Merge Commits

Terraform Modules Guide

Terraform Plan Examples

Migrating from Atlantis to env0

Alternative to Atlantis