Get started
In this example, we will create aTerragrunt
configuration based on Terragrunt Infrastructure Example repository.
First things first, you will need to create a one time configuration of your discovery settings. This is a per Project configuration.
Under Project Settings
select Environment Discovery
tab. To continue, click Get Started
.

Choose The Infrastructure
As with setting up a Template, choose the type of infrastructure you are using, then clickNext
.

Configure Your Repository
Next, choose the desired Git provider, and configure the repository you would like to discover from and clickNext

Configure the Environment Mapping
The final step is crucial as it defines the structure of your project. In this section, you will specify the layout of your project, including which Environments will be created, how they will be named, and where they will be located within env zero
Match Environments Glob
You will need to define your project structure using a multi-glob pattern. Any match to this pattern will trigger the creation and planning of an environment in env zero. In this example, we aim to create an env zero Environment for anyterragrunt.hcl
file that is not located under the _envcommon
folder

Glob patternGlob patterns specify sets of filenames with wildcard characters. For example,
In this case, we will create new env zero Environments only if the new
Note that for extglob, when using OR/AND statements, make sure to wrap each option with parentheses, for example:
\*.tf
or prod/\*\*
For example, you can configure pattern like src/prod/**/*.tf
In this case, we will create new env zero Environments only if the new
main.tf
is located under src/prod/...
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:
!(prod/us-east-1/\*\*)+(dev/us-east-1/**|dev/us-west-2/main.tf)
This means we will listen to any change indev/us-east-1
anddev/us-west-2/main.tf
, and ignore changes underprod/us-east-1
. (Recommend including exclusions first.)+(Terraform/!(prod)**|Terragrunt/dev/**)
Listen for any changes inTerraform
orTerragrunt/dev
but ignore any changes inTerraform/prod
Root Path
The root path configuration defines the starting point from which env zero will generate environments. For instance, if the glob pattern is set tosrc/prod/storage/*_/_.tf
, and the discovered file is src/prod/storage/environment0/main.tf
, with the root path configured as src/prod
, env zero will exclude the root path from the full path of the discovered main.tf
file. Therefore, it will be treated as storage/environment0/main.tf
when determining where to place the environment.
Environment Placement
This section will let you choose the Environment placement strategy within your project.
prod/us-east-1/prod/mysql
will create an Environment called us-east-1/prod/mysql
Create Environments in the closest matching Sub-Project path, matching the directory path - Will consider the closest Sub-Project to match the path, for example a PR to change prod/us-east-1/prod/mysql
will create an Environment called us-east-1/prod/mysql
on prod
Sub-Project
Click Done
and you should be greeted with the success screen if all went well. The discovery process will be started automatically but automatic Pull Request creation should be enabled in the settings section.
Enabling Automatic Pull Request Creation

Workspace Naming
Here we can choose to either usedefault
as the workspace names or derive it from the Environmentโs name
Deploy Discovered Environments on
In the next section, youโll be able to set the Continuous Deployment and PR Plan settings which your Environments will be created with.
Custom Glob VariablesWe also support using custom string templates that are set during runtime -
env0_template_dir_path
- The entire template path.env0_template_dir_name
- The name of the directory of the template files.env0_template_dir_ancestors
- Will be interpolated with each ancestor directory up the template path, and is meant to be used in an extended glob expression. It is most useful for picking up configuration files up the path, like in a Terragrunt style repository. ** NOTE: this should NOT be used with a file extension
e.g: If the template directory isnon-prod/us-east-1/dev/postgres
, then it will be interpolated as `non-prod/|non-prod/us-east-1/|non-prod/us-east-1/dev/|non-prod/us-east-1/dev/postgres/*`.
+((_envcommon/${env0_template_dir_name}/**)|(${env0_template_dir_path}/**)|${env0_template_dir_ancestors})
which means match everything under the path defined in the environmentโs template and match any changes under _envcommon
matching the template dir name, and any files changes in the ancestors (or parent) folders.Heads UpIn case the even that the environment creation glob and the environment CD / PR plan glob do not match, it is possible that the changes that trigger the Environment creation wonโt trigger the initial PR Plan (see section below for more info)
Using Environment Discovery
After configured, using environment discovery is easy as opening and merging a pull request.- Create a branch with desired changes and open a PR.

a PR Plan has started on env0
- Navigate to the relevant Project or Sub-Project in env zero or click the env zero bot comment (Remember: multiple environments can be created via a single PR)

- In the
Deployments
tab, youโll be able to see the initial PR Plan env zero ran on your code.

A real world example of multiple iteration on a failed PR
Closing a PRClosing a PR will archive the
Never Deployed
Environment. Note, that for Bitbucket Cloud and Bitbucket Server automatic archival is not supported, and you will have to do so manually.- After the plan has been reviewed and merged, env zero will trigger a deployment for that Environment.

