Why env0
Solutions
Infrastructure as Code (IaC) Automation Teams and GovernanceManaged Self-Service env0 for the Enterprise
DocumentationPricing
Resources
Case StudiesIn the NewsVideosWebinars
Blog
Login
Get a Demo
FREE TRIALContact us
Apr 21, 2022

Multi-Environment Deployment Workflow with env0’s Terraform Provider

Andrew Way
Director of Sales Engineering

Infrastructure is typically built up from multiple layers, starting with the network to the compute layer. In order to deploy your K8s cluster, you typically need your subnets and VPCs defined ahead of time. As I talk to customers about their IaC deployment challenges, I often get asked how env0 can help with orchestrating dependencies amongst these multi-tiered, multi-layered infrastructure deployments.

Today, I’d like to share how a simple, yet powerful, tweak to our TF provider env0_environment resource gives us a method of orchestrating these complex workflows. By introducing a “wait_for” flag in our env0_environment resource, we can now define multiple env0 environments that essentially depend on one another, and also ensure that they get deployed synchronously by Terraform.

Background

env0 Terraform Provider

We’re excited to announce the release of v1.0 of our Terraform Provider! If you’re not familiar with the env0 Terraform Provider, it is simply a way to define your env0 configuration as Terraform code. We have resources for creating Projects, Templates, and most importantly, Environments. For example, this will allow you to create a project factory from within env0 as you onboard new teams.

Terraform - lifecycle

Terraform has a “depends_on” meta-argument flag that helps you explicitly define resource dependencies. Typically, this is optional, as Terraform will automatically calculate the dependencies based on variable and module dependencies. However, with env0, Terraform doesn’t know about the environment dependencies, unless we explicitly use this flag. Even then, env0 environments will simply be deployed synchronously, despite the usage of “depends_on.”

Introducing the “wait_for” flag

By introducing the “wait_for” flag, we can force the env0 Terraform provider to wait for the environment creation before deploying the next resource.

Here’s a simple example of Terraform code that utilizes the wait feature (check the code here).

resource "env0_environment" "infra-base" {
name                       = "infra-base-${var.name}"
 project_id                 = data.env0_project.project.id
 template_id                = "84727784-587b-4e58-83ea-b0e2f9c872bd"
 revision                   = "main"
 approve_plan_automatically = true
 force_destroy              = var.force_destroy
 wait_for                   = "FULLY_DEPLOYED"
}

resource "env0_environment" "infra-mid" {
 name                       = "infra-mid-${var.name}"
 project_id                 = data.env0_project.project.id
 template_id                = "8c86ee3e-c42d-4f7b-b7be-8513f20fcc65"
 revision                   = "main"
 approve_plan_automatically = true
 force_destroy              = var.force_destroy
‍ wait_for                   = "FULLY_DEPLOYED"
 depends_on                 = [env0_environment.infra-base]
‍
}

resource "env0_environment" "infra-top" {
 name                       = "infra-top-${var.name}"
 project_id                 = data.env0_project.project.id
 template_id                = "5cfcb877-bdf2-402f-a5fc-343d2e1a8f8e"
 revision                   = "main"
 approve_plan_automatically = true
‍ force_destroy              = var.force_destroy
‍ depends_on                 = [env0_environment.infra-mid]
‍
}

Here's a short video of what this looks like in real life.

Other Exciting Features in TF Provider 1.0 release

  • AWS, GCP, Azure Credentials, and associated Cost Credentials
  • Notifications - Slack and Teams integration
  • Private Module Registry resource
Interested in learning more about env0?
Request a Demo
SHARE
You may also like
Recommendations for Migrating from Terraform Cloud
Infrastructure as Code is a Creative Job
How to integrate Azure DevOps with env0
Go back to blog
CNCF Member Badge
Company
About UsIn the NewsPress ReleasesCase StudiesAdditional ResourcesCareers
Developer and DevOps
APITerraform ProviderTerratag Open Source
Terraform Cloud AlternativeDIY AlternativeAtlantis Alternative
FREE TRIAL
Follow Us
Terms of ServicePrivacy PolicySecuritySystem Status
© Copyright env0 2023
This website uses cookies. We use cookies to ensure that we give you the best experience on our website. Learn More
PreferencesDenyAccept
Privacy Preference Center
When you visit websites, they may store or retrieve data in your browser. This storage is often necessary for the basic functionality of the website. The storage may be used for marketing, analytics, and personalization of the site, such as storing your preferences. Privacy is important to us, so you have the option of disabling certain types of storage that may not be necessary for the basic functioning of the website. Blocking categories may impact your experience on the website.
Reject all cookiesAllow all cookies
Manage Consent Preferences by Category
Essential
Always Active
These items are required to enable basic website functionality.
Marketing
These items are used to deliver advertising that is more relevant to you and your interests. They may also be used to limit the number of times you see an advertisement and measure the effectiveness of advertising campaigns. Advertising networks usually place them with the website operator’s permission.
Personalization
These items allow the website to remember choices you make (such as your user name, language, or the region you are in) and provide enhanced, more personal features. For example, a website may provide you with local weather reports or traffic news by storing data about your current location.
Analytics
These items help the website operator understand how its website performs, how visitors interact with the site, and whether there may be technical issues. This storage type usually doesn’t collect information that identifies a visitor.
Confirm my preferences and close