Plan on Pull Request

🚧

Currently, we support Plan on Pull Request for GitHub and GitLab repositories only. Support for Bitbucket is coming soon.

Pull Request Plan in env0

env0 allows you to control and monitor your infrastructure code changes via pull requests 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. Environment has Pull Request Plan enabled.
  2. Environment is 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 over 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 which the push contains file changes by match to the pattern. see below how to configure 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 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 curly braces, for example: +((/first/path/)|(/second/path/))

📘

Plans in parallel

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 when they reach their turn. If a deploy/destroy is queued after this batch of PR Plans, it will wait until all of those plans are finished before starting.

🚧

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.

Pull Request Comments

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

  1. When a PR Plan has started:
GitHubGitHub

GitHub

GitLabGitLab

GitLab

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

GitHub

GitLabGitLab

GitLab

BitbucketBitbucket

Bitbucket

  1. When a PR Plan has failed:
GitHubGitHub

GitHub

GitLabGitLab

GitLab

BitbucketBitbucket

Bitbucket

  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 deploy 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.

A Merge Request and its associated env0 pipeline run statusA Merge Request and its associated env0 pipeline run status

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 run "PR plan" we mark "in progress" the commit
  1. When a Terraform plan was generated:
  1. When the run was not able to generate a proper Terraform plan:
A Merge Request pipeline jobs  running for each env0 environmentA Merge Request pipeline jobs  running for each env0 environment

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 run "PR plan" we mark "in progress" the commit
  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 in 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.


Did this page help you?