<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by env zero Team on Medium]]></title>
        <description><![CDATA[Stories by env zero Team on Medium]]></description>
        <link>https://medium.com/@env0Team?source=rss-9233b109305d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8-nXII4gF5G4JIrc2zc08g.png</url>
            <title>Stories by env zero Team on Medium</title>
            <link>https://medium.com/@env0Team?source=rss-9233b109305d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 01:45:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@env0Team/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Four Stages of Terraform Automation]]></title>
            <link>https://medium.com/env0/the-four-stages-of-terraform-automation-3ba3a0686210?source=rss-9233b109305d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ba3a0686210</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[cloud-infra-management]]></category>
            <dc:creator><![CDATA[env zero Team]]></dc:creator>
            <pubDate>Thu, 19 Sep 2024 14:22:54 GMT</pubDate>
            <atom:updated>2024-09-19T14:22:54.138Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mmO7PDBQQSf99z6s.png" /></figure><p>As your organization grows, so does the complexity of your infrastructure, making automation not just beneficial but essential.</p><p>In this blog post, we’ll explore the four stages of Terraform automation, providing a roadmap as you look to scale your Terraform practices.</p><h3>Video Overview</h3><p><strong>TLDR:</strong> You can find<a href="https://github.com/samgabrail/env0-terraform-automation"> the main repo here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F998836620%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F998836620&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1914972627-1a57c1bf8c9f36d5ded8e1f4bcbaf2b902fbf3c9d17ca55b2d0e09ce9c79f108-d_1280&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="1920" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/d53680cbb40fb210bd4815ab7d2f2708/href">https://medium.com/media/d53680cbb40fb210bd4815ab7d2f2708/href</a></iframe><blockquote><strong><em>Disclaimer<br>‍</em></strong><em>All use cases of Terraform automation discussed here work similarly in </em><a href="https://www.env0.com/blog/opentofu-the-open-source-terraform-alternative"><em>OpenTofu</em></a><em>, the open-source Terraform alternative. However, to keep it simple and familiar for DevOps engineers, we will refer to these as “Terraform automation” throughout this blog post.</em></blockquote><h3>Terraform Workflow Basics</h3><p>Terraform operates on a simple yet powerful workflow: write, <a href="https://www.env0.com/blog/terraform-plan">plan</a>, and <a href="https://www.env0.com/blog/terraform-apply-guide-command-options-and-examples">apply</a>. However, manually running these commands can be time-consuming and error-prone, especially as infrastructure scales. Automation brings several key benefits:</p><ul><li><strong>Increases efficiency:</strong> Reduces the need for manual intervention</li><li><strong>Minimizes human errors:</strong> Ensures that scripts run consistently every time</li><li><strong>Ensures consistency:</strong> Maintains uniformity across multiple deployments</li><li><strong>Enables scalable operations:</strong> Supports larger teams and complex environments without bottlenecks</li></ul><p>I want to introduce you to the four stages of Terraform Automation based on my experience over the years working with customers as they mature in their adoption of Terraform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XouLvvFsNH8dRWFB.png" /></figure><h3>Stage 1: Basic Automation with VCS</h3><p>We will skip over discussing the use of the command line with Terraform as we assume a certain level of expertise with the tool. However, if you want to learn more about the CLI, check out this blog post:<a href="https://www.env0.com/blog/what-is-terraform-cli"> Terraform CLI: Terraform Commands, Examples and Best Practices</a>.</p><p>Let’s start our discussion by looking at how to automate Terraform deployments with a version control system (VCS). This is the first step towards streamlined operations.<a href="https://www.env0.com/blog/atlantis-terraform-guide"> Tools like Atlantis</a> integrate with VCS to trigger automated Terraform plans and applies through pull requests (PRs).</p><h3>Workflow with Atlantis</h3><ol><li><strong>Creating Pull Requests:</strong> When a PR is opened or updated, Atlantis automatically runs <em>terraform plan</em> and posts the output as a comment on the PR.</li><li><strong>Applying Changes:</strong> After reviewing the plan, if changes are approved, commenting <em>atlantis apply</em> on the PR applies the changes, and posts the results.</li></ol><h4>How env0 Can Help</h4><p><a href="http://env0.com/">env0</a> simplifies this process even further by enabling you to create templates tied to your VCS, automating the redeployment process and running Terraform plans on pull requests. This setup forms the foundation of your Terraform automation journey, ensuring that changes are tracked, reviewed, and applied seamlessly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8fCeCR0XtHyXdSzd.png" /></figure><h3>Stage 2: Infrastructure as Code (IaC) Specialized Pipelines</h3><p>As organizations mature in their automation practices, they adopt specialized CI/CD pipelines tailored for <a href="https://www.env0.com/blog/infrastructure-as-code-101">IaC</a>. Building infrastructure provisioning pipelines allows teams to enforce best practices such as integrating linting, security scans, and testing as they provision infrastructure.</p><p>This makes the automation process more robust and reliable and the same pipelines can then pass the logic to a configuration management tool such as Ansible to continue configuring the resources as needed.</p><h3>Custom Workflows</h3><p>Creating workflows designed for IaC involves:</p><ul><li><strong>Linting Terraform code:</strong> Ensuring code quality and style consistency</li><li><strong>Running security scans:</strong> Detecting vulnerabilities early</li><li><strong>Validating configurations:</strong> Checking the correctness of configurations before they are applied</li><li><strong>Configuration management tools:</strong> Integrating tools like Ansible for post-deployment configuration</li></ul><h4>How env0 Can Help</h4><p><a href="http://env0.com/">env0</a> supports IaC specialized pipelines through custom flows. These custom flows allow you to run bash commands at various stages of the Terraform process, such as init, plan, apply, and output.</p><p>You can also install tools such as Ansible for configuration management. This flexibility ensures that all necessary checks and configurations are performed automatically, enhancing the reliability and security of your deployments.</p><p>Below is an example of using custom flows in the <strong>env0.yaml</strong> file from the blog post:<a href="https://www.env0.com/blog/ansible-vs-terraform-when-to-choose-one-or-use-them-together"> Ansible vs. Terraform: Choose One or Use Both?</a></p><pre>deploy:<br>  steps:<br>    terraformOutput:<br>      after:<br>        - terraform output -raw private_key &gt; /tmp/myKey.pem<br>        - chmod 400 /tmp/myKey.pem<br>        - sed -i &quot;s/[placeholder_app]/$(terraform output -raw public_ip)/g&quot; Ansible/inventory<br>        - pip3 install --user ansible<br>        - ls -lah<br>        - cat Ansible/inventory<br>        - cd Ansible &amp;&amp; ansible-playbook --private-key /tmp/myKey.pem -i inventory jenkinsPlaybook.yaml</pre><h3>Stage 3: Advanced Terraform Orchestration</h3><p>As automation practices advance, managing infrastructure as micro-infrastructure becomes crucial. This approach involves breaking down large, monolithic Terraform configurations into smaller, loosely coupled ones based on environment, function, or team. The advantages of doing so are similar to breaking monolithic applications into microservices. Here are a few:</p><ul><li><strong>Improved Scalability</strong>: Each infrastructure component can be scaled independently based on its specific needs, ensuring optimal performance and resource usage</li><li><strong>Enhanced Maintainability</strong>: Managing smaller, independent infrastructure components simplifies updates, testing, and troubleshooting, making the overall system easier to maintain</li><li><strong>Greater Flexibility and Agility with RBAC</strong>: Teams have control over their own piece of the micro-infrastructure with Role-Based Access Control (RBAC). For example, a networking team can have read/write access to their networking environment while providing read access to others, allowing for faster adjustments and deployments in response to changing requirements.</li></ul><h3>Orchestrating Micro-Infrastructures</h3><p>We need a mechanism to orchestrate these micro-infrastructures and determine their dependencies.</p><p>For instance, if we want an application to run, we first need a database. So, we should have a workflow to create the database first and have the necessary credentials and configuration ready for apps that need access to it.</p><p>Below are the key components for orchestration:</p><ul><li><strong>Determining dependencies:</strong> Identifying the order in which resources should be created</li><li><strong>Managing environments:</strong> Creating environments owned by certain teams via RBAC that are specific to environment, function, and team. For example, an application could have the following environments:</li><li>dev-compute-teamA</li><li>dev-database-teamA</li><li>dev-storage-teamA</li><li>dev-networking-teamA</li><li>qa-compute-teamA</li><li>qa-database-teamA<br>…and so on</li><li><strong>Using workflows:</strong> Automating the creation and configuration of dependent resources using an orchestrator</li></ul><h4>How env0 Can Help</h4><ul><li><a href="http://env0.com/">env0</a> uses the term environment for a micro-infrastructure</li><li>The way to orchestrate multiple environments with their dependencies is by using<a href="https://docs.env0.com/docs/workflows"> env0’s Workflows functionality</a></li><li>Benefits of env0’s workflows:</li><li>Manage your entire infrastructure with complex dependencies between Environments</li><li>Visual presentation of the complex deployment</li><li>Each environment can use a different IaC tool — one environment can be managed by Terraform while another is managed by K8s, for example</li></ul><h3>Stage 4: Self-Service with Governance</h3><p>At the pinnacle of Terraform automation, governance becomes a critical focus. This includes ensuring security, compliance, cost management, and reliability.</p><h3>Terraform Security and Compliance</h3><p>As the organization matures with its Terraform automation efforts, it will typically move towards a self-service model. In a self-service model, you would have producers and consumers.</p><p>Producers would build standardized Terraform modules that consumers would use. Producers are typically well-versed in Terraform, whereas consumers don’t necessarily need to be profoundly acquainted with It.</p><p>For this self-service model to work, we must have governance and policies in place. We can ensure these guardrails are in place using Policy as Code. Open Policy Agent (OPA) has become an industry standard for Policy as Code.</p><h4>How env0 Can Help</h4><p><a href="https://docs.env0.com/docs/policies">env0 supports Policy as Code</a>, allowing you to automate policy enforcement and maintain compliance across your infrastructure.</p><p>With env0, you can define and enforce policies at runtime and during deployments, ensuring that all infrastructure changes adhere to your organization’s standards.</p><h3>Cost Management with Automated Terraform Cost Control</h3><p>Cost management is a crucial aspect of governance. Tools like Infracost help estimate the cost impact of IaC changes.</p><p>Proper tagging of resources is also crucial for optimizing costs. Some organizations implement bots that scan environments and shut down resources based on tags. Manually tagging resources is a painful process, one that an automated process can definitely help with.</p><h4>How env0 Can Help</h4><p>env0 offers<a href="https://docs.env0.com/docs/cost-monitoring"> Cost Estimation and Monitoring</a> and <a href="https://docs.env0.com/docs/budget-notifications">Budget Notifications</a> to keep an eye on cost. env0 also offers an automatic tagging feature using its open-source<a href="https://github.com/env0/terratag?tab=readme-ov-file"> Terratag project</a>.</p><h3>Reliability with Auto-Drift Detection and Remediation</h3><p>Monitoring infrastructure changes and detecting configuration drift is vital for maintaining reliability. Drift can occur for various reasons, and detecting and addressing it promptly is important.</p><h4>How env0 Can Help</h4><p>env0 provides real-time monitoring and smart<a href="https://docs.env0.com/docs/drift-detection-policy"> Drift Detection</a> features, ensuring that any configuration changes or drifts are identified and remediated quickly, maintaining the integrity and reliability of your infrastructure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uBlcb17bEln2-yl6.png" /></figure><h3>Demo Time!</h3><p>This section provides a detailed demo showcasing how a mature organization can leverage <a href="http://env0.com/">env0</a> to automate Terraform workflows. This demo will highlight the practical applications of the concepts discussed in the previous sections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/0*kIEFtoGmDe6nf1g7.png" /></figure><h3>Setting Up the Initial Environment</h3><p>The network team has already set up basic networking requirements to kick off, such as a VPC and some subnets. This highlights the idea of micro-infrastructures and relationships between different environments and teams. Here’s a quick overview of what to work with:</p><ul><li><strong>Region</strong>: us-east-1</li><li><strong>VPC ID</strong>: Unique identifier for the VPC</li><li><strong>VPC Private Subnet IDs</strong>: List of subnet IDs within the VPC</li></ul><p>These outputs from the initial networking setup will be crucial for configuring our subsequent environments and they are found in a project called “Networking-AWC” with the screenshot of the output below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bnokLO96yNeZeN0A.png" /></figure><h3>Creating the Terraform Automation Project</h3><p>Next, you will need to create a new project called “Terraform Automation for Mature Org.” This project will include several key templates:</p><ol><li><strong>Terraform Automation Template</strong>: This workflow template sets up an EKS (Elastic Kubernetes Service) cluster and deploys Grafana and Prometheus inside the cluster</li><li><strong>EKS Template</strong>: This Terraform template handles the creation of the EKS cluster</li><li><strong>Grafana and Prometheus Helm Templates</strong>: These Helm templates manage the deployment of Grafana and Prometheus via Helm charts</li></ol><p>Here are our project templates below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E-s9xEx_cgXIT-OS.png" /></figure><p>Each template is configured with specific variables and tied to our version control system.</p><h3>Configuring Templates and Environments</h3><p>The templates are tied to our project, and the environment variables are set up to ensure smooth deployment. Let’s take a look at the Terraform Automation template first.</p><h4>The Terraform Automation Template</h4><p>These are the environment variables used:</p><ul><li><strong>INFRACOST_API_KEY:</strong> An API key for Infracost to run cost estimates on the infrastructure</li><li><strong>ENV0_TERRATAG_CUSTOM_TAGS: </strong>A map of key-value pairs for Terratag to automatically tag all the resources you’re building</li><li><strong>SOFT_FAIL:</strong> A setting for soft fail during Terraform scans by Checkov, which gives us a notification of the Checkov policies that have passed and failed with their severity without stopping the run</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dTsW7N_028GB8HZD.png" /></figure><h4>The EKS Environment</h4><p>Below are the Terraform variables that we are assigning: <strong>VPC ID, Subnet IDs, </strong>and <strong>Region</strong>: These variables are imported from the outputs of our initial networking project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yjG34wi3-YEvcv9p.png" /></figure><h4>‍The Prometheus and Grafana Environments</h4><p>The Prometheus and Grafana VCS templates are linked to their Helm repositories on GitHub as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*500GS8MFgc5O3Vl0.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/0*aIRCVWcmVlmG-r0v.png" /></figure><p>Also, look at the settings for the Prometheus and Grafana environments. Notice the Environment Name, Release Name, and Namespace for Prometheus below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WfGXR9HTDbWHHEoW.png" /></figure><p>And again for Grafana:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zJOmGnfp8veQ0jI9.png" /></figure><h3>Project Settings</h3><ul><li><strong>Credentials</strong>: AWS and Kubernetes credentials are configured to allow Terraform to interact with your cloud resources. You can also configure cost credentials to monitor your environment’s cost.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PuTcSp1BOptgIzbm.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/0*EhZl6D23MLZjyZa5.png" /></figure><ul><li>Approval Policies: We have two approval policies using OPA. The Main one checks costs, and the Remediation one ensures approval for any “create” or “destroy” operations in the Terraform workflow.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*szXQQf1za2pRM31G.png" /></figure><h3>Deploying the Environments</h3><p>Using a combination of<a href="https://docs.env0.com/docs/workflows"> env0’s Workflows</a> along with<a href="https://docs.env0.com/docs/custom-flows"> Custom Flows</a>, the automation process will:</p><ol><li><strong>Create the EKS Cluster</strong>: Deploying the EKS cluster based on the Terraform configuration</li><li><strong>Create Namespace</strong>: Setting up a Kubernetes namespace for monitoring purposes</li><li><strong>Deploy Prometheus and Grafana</strong>: Using Helm charts to install these monitoring tools within the EKS cluster</li></ol><p>Deploying or redeploying the workflow environment will look similar. You can deploy the entire workflow or just a subset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bwbhRv9oOfhsAOR_.png" /></figure><p>Here is what your deployment will look like once completed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Y5ru5aCBs1_4FNUs.png" /></figure><h3>Deployment Steps</h3><p>The deployment logs provide detailed insights into each step. Here they are listed for the Terraform EKS environment:</p><ol><li><strong>Git Clone</strong>: Clones the repository containing the Terraform configuration files from the specified Git source</li><li><strong>Get Working Directory</strong>: Prepares the working directory for the deployment by setting up the necessary files and structure</li><li><strong>Loading env0 YAML file</strong>: Reads and processes the env0 YAML configuration file to apply specified settings, configurations, and custom flows</li><li><strong>Load Variables</strong>: Loads environment-specific <a href="https://www.env0.com/blog/terraform-variables">variables</a> needed for the Terraform deployment</li><li><strong>Setting Version</strong>: Ensures the correct <a href="https://www.env0.com/blog/tutorial-how-to-manage-terraform-versioning">versions of Terraform</a> and other required tools are set up for the deployment</li><li><strong>Initialize</strong>: Prepares the environment for Terraform operations</li><li><strong>Terraform Init</strong>: Initializes the Terraform configuration, setting up the backend and provider configurations (Learn more about <a href="https://www.env0.com/blog/terraform-init"><em>terraform init</em></a>)</li><li><strong>Setting Terraform Workspace</strong>: Configures the appropriate Terraform workspace to isolate state and resources for different environments</li><li><strong>Tag Resources</strong>: Applies tags to the managed resources for better organization and cost tracking. This step runs Terratag</li><li><strong>Terraform Plan</strong>: Generates and displays an execution plan showing what actions Terraform will take to achieve the desired state</li><li><strong>Checkov Install</strong>: Installs <a href="https://www.env0.com/blog/best-iac-scan-tool-what-is-checkov">Checkov</a>, a static code analysis tool for Infrastructure as Code, to ensure compliance with security policies</li><li><strong>Checkov Security Scan</strong>: Runs a security scan using Checkov to identify potential misconfigurations and security issues in the Terraform code</li><li><strong>Cost Estimation</strong>: Provides an estimate of the costs associated with the resources defined in the Terraform plan. This step runs Infracost</li><li><strong>Approval Policies</strong>: Applies approval policies to ensure that the plan meets organizational requirements before execution</li><li><strong>Terraform Apply</strong>: Executes the actions proposed in the Terraform plan to create or update infrastructure resources</li><li><strong>Terraform Output</strong>: Retrieves and displays the <a href="https://www.env0.com/blog/terraform-output-variables-in-depth-guide-with-examples">output values</a> defined in the Terraform configuration</li><li><strong>Create Monitoring Namespace</strong>: Creates the monitoring namespace in Kubernetes for Prometheus and Grafana</li><li><strong>Store Working Directory</strong>: Saves the working directory state and relevant files for future reference or reuse</li></ol><p>Moreover, here are the steps for the Grafana and Prometheus environments:</p><ol><li><strong>Get Working Directory</strong>: Prepares the working directory by setting up the necessary files and structure for the deployment</li><li><strong>Loading env0 YAML file</strong>: Reads and processes the env0 YAML configuration file to apply specified settings, configurations, and custom flows</li><li><strong>Load Variables</strong>: Loads environment-specific variables</li><li><strong>Setting Version</strong>: Ensures the correct versions of Helm and other required tools are set up for the deployment</li><li><strong>Initialize</strong>: Connects to the EKS cluster, updates <strong>kubeconfig</strong>, and adds the specified Helm repository</li><li><strong>Helm Diff</strong>: Compares the current Helm release with the proposed changes to show what will be updated</li><li><strong>Approval Policies</strong>: Applies approval policies to ensure the proposed Helm changes meet organizational requirements before execution</li><li><strong>Helm Upgrade</strong>: Applies the changes to the Kubernetes cluster by upgrading the Helm release with the specified configurations</li><li><strong>Store Working Directory</strong>: Saves the working directory state and relevant files for future reference or reuse</li></ol><h3>Drift Detection and Remediation Setup</h3><p>To maintain the integrity of the environments, you need to enable automatic drift detection and remediation. This involves:</p><ul><li><strong>Enabling Drift detection:</strong> This was initially enabled when creating the environments</li><li><strong>Scheduled Deployments</strong>: Setting up a schedule in the form of a cron job to run deployments every two hours, ensuring any drift is detected and addressed promptly</li><li><strong>OPA Policies</strong>: Enforcing policies that allow automatic updates but require approvals for resource creation or deletion, mitigating the risk of unintended changes causing outages</li></ul><p>Below is a screenshot of the Workflow settings showing Scheduling for continuous deployment along with Drift Detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rmLrq_Q7d8H4snUU.png" /></figure><h3>Simulating and Handling Drift</h3><p>In the demo video, I manually introduced drift by changing the tags on the EKS cluster to test the drift detection and remediation setup.</p><p>The automation detected the drift, and the redeployment reverted the changes, demonstrating the robustness of our setup. It was a simple update in this case, so the approval policy allowed the automation to continue unattended.</p><p>Additionally, I simulated a more complex drift scenario by adding an S3 bucket via Terraform. This triggered an approval workflow, ensuring that significant changes are reviewed before being applied.</p><h3>Code Walk-through</h3><p>Finally, let’s explore the key configuration files in our repository. Below is the file structure in our repo.</p><pre>├── LICENSE<br>├── Policies<br>│   ├── Main<br>│   │   └── cost-policy.rego<br>│   └── Remediation<br>│       └── update-only.rego<br>├── README.md<br>└── Terraform<br>    ├── EKS<br>    │   ├── LICENSE<br>    │   ├── README.md<br>    │   ├── env0.yml<br>    │   ├── input.json<br>    │   ├── main.tf<br>    │   ├── outputs.tf<br>    │   ├── plan.json<br>    │   ├── variables.tf<br>    │   └── versions.tf<br>    ├── VPC<br>    │   ├── LICENSE<br>    │   ├── README.md<br>    │   ├── env0.yml<br>    │   ├── main.tf<br>    │   ├── outputs.tf<br>    │   ├── variables.tf<br>    │   └── versions.tf<br>    └── env0.workflow.yaml</pre><ul><li><strong>Policies</strong>: OPA policies are defined in the <strong>Policies </strong>folder and used to manage approvals and cost estimations.</li><li><strong>Terraform Scripts</strong>: The <strong>Terraform</strong> directory contains detailed configurations for creating the VPC and the EKS cluster. Notice that we have our <strong>variables.tf</strong> file, which is our variable definitions file, but the variable assignment is directly added to templates and environments within env0. You could add *.auto.tfvars files here as well if you like.</li><li><strong>Workflow Definitions</strong>: Two files are of importance here: <strong>env0.workflow.yaml</strong> for workflow definitions and <strong>env0.yaml</strong> for custom flows</li></ul><h3>Conclusion</h3><p>Automating Terraform with <a href="https://www.env0.com/">env0</a> offers numerous benefits, including increased efficiency, reduced errors, enhanced security, and compliance.</p><p>Following the four stages outlined in this post, organizations can systematically scale their Terraform automation practices, ensuring robust and scalable infrastructure management.</p><p>To recap:</p><ul><li><strong>Stage 1</strong>: Basic automation with VCS sets the foundation for streamlined operations</li><li><strong>Stage 2</strong>: Infrastructure as Code (IaC) Specialized Pipelines introduce additional checks and configurations</li><li><strong>Stage 3</strong>: Advanced Terraform orchestration breaks down complex infrastructure into manageable components</li><li><strong>Stage 4</strong>: Self-service with governance ensures security, compliance, and cost management at scale</li></ul><p>Explore env0’s features further to elevate your Terraform automation practices. Start your journey today by signing up for an<a href="https://app.env0.com/"> env0 account</a> and begin transforming your infrastructure automation process.</p><p>Happy automating!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ba3a0686210" width="1" height="1" alt=""><hr><p><a href="https://medium.com/env0/the-four-stages-of-terraform-automation-3ba3a0686210">The Four Stages of Terraform Automation</a> was originally published in <a href="https://medium.com/env0">env0</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform vs AWS CloudFormation: An In-Depth Comparison]]></title>
            <link>https://medium.com/env0/terraform-vs-aws-cloudformation-an-in-depth-comparison-38f901fb4984?source=rss-9233b109305d------2</link>
            <guid isPermaLink="false">https://medium.com/p/38f901fb4984</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[env zero Team]]></dc:creator>
            <pubDate>Thu, 21 Mar 2024 12:56:37 GMT</pubDate>
            <atom:updated>2024-03-21T12:56:37.691Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sXLPoarV4-aThbIq.png" /></figure><p>In our last discussion on<a href="https://www.env0.com/blog/pulumi-vs-terraform-an-in-depth-comparison"> Pulumi vs. Terraform</a>, we explored the intricate world of <a href="https://www.env0.com/blog/infrastructure-as-code-101">Infrastructure-as-Code</a> (IaC) tools, delving into how these technologies streamline the deployment and management of cloud environment resources.</p><p>Continuing on this path, today we’re comparing two other IaC giants: Terraform and CloudFormation. Both tools have established substantial footholds within their respective areas, becoming the preferred options for developers aiming to automate their cloud infrastructure.</p><p>In this post, I’ll compare the tools, discuss their pros and cons, and demonstrate how they can be used with env0, leveraging the platform’s multi-framework support, which makes it compatible with any IaC tool.</p><h3>What is Terraform?</h3><p>Terraform, developed by HashiCorp, excels as an IaC tool facilitating the provisioning and management of AWS resources, as well as infrastructure resources across different cloud providers, embodying a cloud-agnostic approach with native support for Google Cloud, AWS Cloud, and more.</p><p>Historically speaking, Terraform’s open-source roots encouraged a vibrant community contribution, leading to an extensive provider ecosystem that spans beyond cloud providers to include SaaS and PaaS offerings. One of Terraform’s unique features is its ability to manage resources declaratively, allowing users to define their infrastructure in code that can be versioned, reused, and shared.</p><blockquote><strong>Note: </strong>Following the <a href="https://www.env0.com/blog/hashicorp-license-change">license change</a> in August 2023, all future releases of Terraform will adopt the BUSL license, while all versions prior to 1.5.x will remain open-source.</blockquote><blockquote>After the shift, OpenTofu emerged as an open-source alternative to Terraform. Originating from a fork of Terraform as a drop-in replacement for Terraform version 1.6, OpenTofu preserves all of the core functionalities that have endeared Terraform to developers, including the use of all providers and Terraform modules. As such, all of the points raised about Terraform in this article equally apply to <a href="https://www.env0.com/blog/opentofu-the-open-source-terraform-alternative">OpenTofu</a>.</blockquote><h3>What is AWS CloudFormation?</h3><p>On the flip side, CloudFormation is Amazon Web Services’ (AWS) native IaC service, designed to seamlessly integrate with AWS’s vast array of services.</p><p>As a managed service, AWS CloudFormation allows users to define their AWS resources with JSON or YAML templates, automating the provisioning and updating processes. Its deep integration with AWS ensures that users can leverage the full spectrum of AWS features and services with minimal hassle, making it a powerful tool for those heavily invested in the AWS ecosystem.</p><h3>What are the differences between Terraform and CloudFormation?</h3><p>To compare Terraform and CloudFormation side-by-side, let’s look at several key aspects:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*rhg5F94M6eXg65NRiUxqYg.png" /></figure><h3>Terraform vs CloudFormation: Pros and Cons</h3><p>The answer is “it depends,” as each tool has its strengths and weaknesses. Here is the TLDR:</p><h3>Terraform Pros and Cons</h3><h4>Pros:</h4><ul><li>Terraform is renowned for its flexibility and support for multiple cloud providers, offering a consistent syntax and deployment strategy across various environments. While it’s true that you can’t directly transfer the same codebase from one provider to another, Terraform offers consistent syntax and deployment techniques across different clouds.</li><li>For many organizations, this consistency is a major advantage, as it allows for the use of familiar syntax and deployment strategies when managing resources across multiple cloud environments, which is undoubtedly beneficial.</li></ul><h4>Cons:</h4><ul><li>The versatility and multi-cloud capabilities of Terraform, while beneficial, can complicate state management and configuration across diverse environments. Tailoring deployments to suit each provider’s unique requirements may raise the risk of errors and demand a comprehensive grasp of each cloud platform’s specific characteristics, posing challenges for teams less experienced with multi-cloud strategies.</li><li>In this context,<a href="https://www.env0.com/integrations/terraform"> platforms like env0</a> emerge as invaluable allies, offering targeted support that can streamline and simplify the scaling process for organizations looking to expand their Terraform implementations.</li><li>Furthermore, Terraform relies on providers that connect to the APIs of the cloud vendors. There is usually a delay between when a service or feature is released in the cloud and when it gets supported by the Terraform provider.</li><li>This is in contrast to AWS CloudFormation which, being a native AWS service, seamlessly integrates with AWS offerings faster.</li></ul><h3>CloudFormation Pros and Cons</h3><h4>Pros:</h4><ul><li>CloudFormation stands out in AWS-centric environments, providing deep integration and a managed service experience that simplifies the management of AWS resources. Its native design for AWS ensures that users can fully exploit the capabilities of the cloud service, streamlining the deployment process and reducing the overhead typically associated with infrastructure management. The service’s direct integration with AWS also means that users can rely on AWS’s robust support structure and continuous updates.</li></ul><h4>Cons:</h4><ul><li>The primary limitation of CloudFormation is its exclusive focus on AWS, which can be a significant constraint for organizations with a multi-cloud strategy or those looking to avoid vendor lock-in. Additionally, while CloudFormation simplifies AWS resource management, it may not offer the same level of flexibility or community support as Terraform, potentially limiting its adaptability to complex or highly customized deployment scenarios.</li></ul><h3>Use Cases</h3><h4>Scenario 1: Multi-Cloud Management</h4><p>Terraform shines in scenarios where organizations aim to leverage the strengths of multiple cloud platforms, such as AWS, Azure, and Google Cloud.</p><p>By offering a single configuration language (HCL) and workflow, Terraform simplifies the complexity of managing diverse cloud services and infrastructure. This unified approach enables teams to maintain consistency in infrastructure provisioning and management practices across different clouds, reducing the learning curve and operational overhead associated with using distinct tools or interfaces for each cloud provider.</p><p>Furthermore, Terraform’s extensive provider ecosystem allows organizations to easily integrate with a wide array of cloud services, APIs, and custom in-house solutions, facilitating a cohesive and flexible infrastructure strategy that can dynamically adapt to changing business requirements and technological landscapes.</p><h4>Scenario 2: AWS-Specific Projects</h4><p>For AWS cloud-centric projects, AWS CloudFormation stands out, offering a managed AWS service experience with deep integration and native support for efficiently deploying custom resources within the AWS environment. It leverages AWS’s native integration to offer a seamless and optimized experience for defining, deploying, and managing AWS resources.</p><p>With CloudFormation, users can utilize AWS-specific features and services to their fullest potential, taking advantage of AWS’s scalability, reliability, and security features without the need for bridging tools or external dependencies.</p><p>This deep integration simplifies the process of configuring complex AWS environments, enabling automatic handling of dependencies between resources, rollbacks on failures, and updates to existing stacks. CloudFormation’s template-based configuration, using either JSON or YAML, also ensures that <a href="https://www.env0.com/blog/infrastructure-as-code-101">infrastructure as code</a> (IaC) practices can be easily adopted, promoting version control, collaboration, and repeatability in AWS-focused development projects.</p><h4>Scenario 3: Compliance and Governance</h4><p>In environments where compliance and governance are critical, Terraform’s ability to integrate with policy-as-code tools like Open Policy Agent (OPA) allows organizations to enforce policies and ensure that infrastructure deployments comply with internal and external regulations.</p><p>This use case is particularly relevant for enterprises that need to adhere to stringent security standards, audit requirements, and governance policies across their cloud infrastructure, regardless of the cloud provider.</p><p>Terraform’s state management and planning features also contribute to a transparent, auditable, and controlled infrastructure management process, making it easier to track changes, review impacts before applying them, and ensure consistency across environments.</p><h3>A Practical Demo</h3><p>Let’s take a look at a simple demo to show how to create an S3 bucket in AWS using these two tools. We will use env0 for this task, leveraging its multiple-framework support, which makes it compatible with any IaC tool, Terraform, OpenTofu, Cloudformation, Pulumi, etc.</p><h3>Video Walkthrough</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F919957856%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F919957856&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1809711508-8d7d74a391524f82c0bec0e5c4a4db76a65cf1cace03922d721d63c686d7c89b-d_1280&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="1920" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/61d4e5694ae46d6345b56f9be5dbdb75/href">https://medium.com/media/61d4e5694ae46d6345b56f9be5dbdb75/href</a></iframe><p><strong>Requirements</strong></p><ul><li>A free GitHub account</li><li>Access to an AWS account</li><li>A <a href="https://www.env0.com/lp/iac-automation-free-trial">free env0 account</a></li></ul><p><strong>TLDR:</strong> You can find<a href="https://github.com/samgabrail/env0-terraform-vs-cloudformation"> the main repo here</a></p><h3>Terraform Demo</h3><p>Per the video above, let’s first start with Terraform.</p><h4>1. Create an env0 Template for Terraform</h4><p>Start by creating a template in env0 that connects our GitHub repo. Make sure to select Terraform as the template type and give it a name as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bKIo6pmsaxMt7MDC.png" /></figure><p>Now it’s time to connect our template with our GitHub repo. The Terraform configuration is in the <strong>TerraformS3.tf</strong> file and is written in HCL (HashiCorp Configuration Language). You don’t need to specify the Terraform folder or branch since <strong>TerraformS3.tf </strong>is in the main branch at the root of the repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8eDtneO4GyfhpBwB.png" /></figure><p>No variables are necessary for this deployment, so the final step for the template is to associate it with our project.</p><p>Now we’re set to establish a new environment. Navigate to the <strong>Project Environments </strong>tab on the left and proceed to initiate a new environment, choosing the template we’ve recently crafted. The deployment will commence, allowing you to monitor the logs.</p><h4>2. Terraform Plan Log</h4><p>Take a look at terraform plan log in env0 below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SFZABznIvME8lUAb.png" /></figure><p>Terraform gives you a dry-run of your plan when you run either <a href="https://www.env0.com/blog/terraform-plan">terraform plan</a> or <a href="https://www.env0.com/blog/terraform-apply-guide-command-options-and-examples">terraform apply</a>. Check out this blog post to learn about <a href="https://www.env0.com/blog/what-is-terraform-cli">Terrform CLI commands and examples</a>.</p><p><strong>Terraform Apply Log</strong></p><p>Once you confirm that you’d like to proceed, you will see the output below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vInldjm_YC8g7KIM.png" /></figure><h4>4. View the Output in AWS</h4><p>In the AWS console, we can now see the resulting S3 bucket with all the options that we requested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jrn7yPMIyT_lt6GP.png" /></figure><p>Notice how bucket versioning is enabled along with a tag that shows we built this with Terraform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GpdWcf6tEeebIh4P.png" /></figure><p>Next, you can see the permissions and how we block public access to this S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2CPBTSvmMmNFsvdx.png" /></figure><p>Finally, you can see the lifecycle of this S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jNom4LfPr4Q8wf3U.png" /></figure><h4>5. Destroy the S3 Bucket with Terraform</h4><p>Once you’re done examining this S3 bucket, you can destroy it by clicking the red destroy button in env0 inside the environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_Wz6K8w4rX_w5h2s.png" /></figure><p>The Terraform plan log will show you what is about to be destroyed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hKrFeuLhEZG9zvAe.png" /></figure><p>Finally, the Terraform Destroy log will show you that the resources were destroyed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i45NsaltbcMgOiD4.png" /></figure><h3>AWS CloudFormation Demo</h3><p>Let’s move on to our second demo to build the same S3 bucket using AWS CloudFormation.<strong>‍</strong></p><h4>1. Create an env0 Template for CloudFormation</h4><p>We need to create a Template in env0 similar to the template we created for Terraform, except now we select CloudFormation as our template type, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XJdhO9V4bgIw-iVy.png" /></figure><p>Next, we need to select the same GitHub repo as we did for Terraform. Please note that you need to specify the AWS CloudFormation template file name — in our case, <strong>CloudFormationS3.yaml</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DC__yVh-bpgujweu.png" /></figure><p>Next, add the AWS region as a variable and add this template to either all your projects or the one you created for this demo called: <strong>Terraform vs CloudFormation.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vGDia3wqirRAov5m.png" /></figure><p>We are now ready to create a new environment. From the <strong>Project Environments</strong> tab on the left, go ahead and create a new environment and select the template we just created. The deployment will start running and observing the logs.</p><h4>2. CloudFormation Describe Change Set</h4><p>The first log I captured for you is the one showing what will change, similar to the Terraform plan we saw before. You can see it below.</p><pre>Cloudformation parameters: {}<br>&gt; awsv2 cloudformation deploy --stack-name tf-vs-cloudformation --template-file CloudFormationS3.yaml --no-execute-changeset $ENV0_CF_CLI_ARGS_deploy<br><br>Waiting for changeset to be created..<br><br>Changeset created successfully. Run the following command to review changes:<br>aws cloudformation describe-change-set --change-set-name arn:aws:cloudformation:us-east-1:706933696988:changeSet/awscli-cloudformation-package-deploy-1707149843/fa8066ab-00ae-4004-af27-419c6eddd1c0<br><br>&gt; awsv2 cloudformation describe-change-set --change-set-name arn:aws:cloudformation:us-east-1:706933696988:changeSet/awscli-cloudformation-package-deploy-1707149843/fa8066ab-00ae-4004-af27-419c6eddd1c0<br>{<br>    &quot;Changes&quot;: [<br>        {<br>            &quot;Type&quot;: &quot;Resource&quot;,<br>            &quot;ResourceChange&quot;: {<br>                &quot;Action&quot;: &quot;Add&quot;,<br>                &quot;LogicalResourceId&quot;: &quot;DemoStorage&quot;,<br>                &quot;ResourceType&quot;: &quot;AWS::S3::Bucket&quot;,<br>                &quot;Scope&quot;: [],<br>                &quot;Details&quot;: []<br>            }<br>        }<br>    ],<br>    &quot;ChangeSetName&quot;: &quot;awscli-cloudformation-package-deploy-1707149843&quot;,<br>    &quot;ChangeSetId&quot;: &quot;arn:aws:cloudformation:us-east-1:706933696988:changeSet/awscli-cloudformation-package-deploy-1707149843/fa8066ab-00ae-4004-af27-419c6eddd1c0&quot;,<br>    &quot;StackId&quot;: &quot;arn:aws:cloudformation:us-east-1:706933696988:stack/tf-vs-cloudformation/0b641ca0-c442-11ee-8712-12bde5a0d6ff&quot;,<br>    &quot;StackName&quot;: &quot;tf-vs-cloudformation&quot;,<br>    &quot;Description&quot;: &quot;Created by AWS CLI at 2024-02-05T16:17:23.098906 UTC&quot;,<br>    &quot;Parameters&quot;: null,<br>    &quot;CreationTime&quot;: &quot;2024-02-05T16:17:23.382000+00:00&quot;,<br>    &quot;ExecutionStatus&quot;: &quot;AVAILABLE&quot;,<br>    &quot;Status&quot;: &quot;CREATE_COMPLETE&quot;,<br>    &quot;StatusReason&quot;: null,<br>    &quot;NotificationARNs&quot;: [],<br>    &quot;RollbackConfiguration&quot;: {},<br>    &quot;Capabilities&quot;: [],<br>    &quot;Tags&quot;: null,<br>    &quot;ParentChangeSetId&quot;: null,<br>    &quot;IncludeNestedStacks&quot;: false,<br>    &quot;RootChangeSetId&quot;: null<br>}</pre><p>Once you’ve gone through this, you can now accept the changes to move on to the next stage.</p><h4>3. CloudFormation Deploy</h4><p>The second log to pay attention to is the actual deployment. Below is what it will look like.</p><pre>Cloudformation parameters: {}<br>&gt; awsv2 cloudformation deploy --stack-name tf-vs-cloudformation --template-file CloudFormationS3.yaml $ENV0_CF_CLI_ARGS_deploy<br><br>Waiting for changeset to be created..<br><br>Waiting for stack create/update to complete<br><br>Successfully created/updated stack - tf-vs-cloudformation</pre><p>The S3 bucket is created similarly to what happened with Terraform. CloudFormation adds some tags to the bucket, as shown in the AWS console Tags section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Jp_J0uMucmfbCQM2.png" /></figure><p>Below is a screenshot of the events from the AWS console for the CloudFormation stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xmga6PYhXfp8fPvM.png" /></figure><p>Finally, you can view the S3 bucket resource created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ITnzm7LdYBDRkGBf.png" /></figure><h4>4. Destroy the CloudFormation Stack</h4><p>To destroy the CloudFormation stack, simply click the red Destroy button in env0 inside the environment you would like to destroy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*14GN330mtvnPTYRj.png" /></figure><p><strong>CloudFormation List Stack Resources</strong></p><p>You will see env0 run the following command:</p><pre>&gt; awsv2 cloudformation list-stack-resources --stack-name env0e0d312 $ENV0_CF_CLI_ARGS_list_stack_resources<br>{<br>    &quot;StackResourceSummaries&quot;: [<br>        {<br>            &quot;LogicalResourceId&quot;: &quot;DemoStorage&quot;,<br>            &quot;PhysicalResourceId&quot;: &quot;env0-demo-cloudformation-storage&quot;,<br>            &quot;ResourceType&quot;: &quot;AWS::S3::Bucket&quot;,<br>            &quot;LastUpdatedTimestamp&quot;: &quot;2024-02-05T16:48:33.037000+00:00&quot;,<br>            &quot;ResourceStatus&quot;: &quot;CREATE_COMPLETE&quot;,<br>            &quot;DriftInformation&quot;: {<br>                &quot;StackResourceDriftStatus&quot;: &quot;NOT_CHECKED&quot;<br>            }<br>        }<br>    ]<br>}</pre><p><strong>CloudFormation Delete Stack</strong></p><p>Finally, env0 will delete the stack.</p><pre>&gt; awsv2 cloudformation delete-stack --stack-name env0e0d312 $ENV0_CF_CLI_ARGS_delete_stack<br>&gt; awsv2 cloudformation wait stack-delete-complete --stack-name env0e0d312</pre><h3>Conclusion</h3><p>Choosing between Terraform and CloudFormation depends largely on your specific needs and cloud strategy. If your environment spans across multiple cloud providers, Terraform offers the flexibility and ecosystem to support your projects. Conversely, for AWS-centric deployments, CloudFormation’s native integration and managed service benefits are hard to beat.</p><p>At env0, we understand that different teams have different preferences and requirements. That’s why the platform is designed to support all IaC frameworks — including both Terraform and CloudFormation, giving you the flexibility to choose the right tool for the job without compromising on functionality or efficiency.</p><p>Whether you’re leaning towards the open-source community of Terraform or the AWS-native capabilities of CloudFormation, env0 facilitates a collaborative and efficient infrastructure management process across your organization.</p><h3>Frequently Asked Questions</h3><h4>Q: Can Terraform and CloudFormation be used together?</h4><p>Yes. Although they serve similar purposes, some organizations use both to leverage Terraform’s multi-cloud capabilities and CloudFormation’s deep AWS integration.</p><h4>Q: Is Terraform more difficult to learn than CloudFormation?</h4><p>The learning curve for each tool depends on the user’s background. Terraform’s HCL is intuitive for those with coding experience, while CloudFormation’s template-based approach may be simpler for users familiar with JSON or YAML.</p><h4>Q: How do Terraform and CloudFormation handle state management?</h4><p>Terraform maintains state files to keep track of resource deployment, while CloudFormation relies on AWS to manage the entire infrastructure and the state of resources.</p><h4>Q: Are there any costs associated with using Terraform?</h4><p>While Terraform itself is free, users may incur costs from the cloud resources provisioned through Terraform. Additionally, third-party state backends or enhanced security features may involve extra costs.</p><h4>Q: How does CloudFormation integrate with other AWS services?</h4><p>CloudFormation integrates natively with almost all AWS services, allowing users to define a wide range of AWS resources and configurations within its templates.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38f901fb4984" width="1" height="1" alt=""><hr><p><a href="https://medium.com/env0/terraform-vs-aws-cloudformation-an-in-depth-comparison-38f901fb4984">Terraform vs AWS CloudFormation: An In-Depth Comparison</a> was originally published in <a href="https://medium.com/env0">env0</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Switch from Terraform Cloud in Minutes with Our New Migration Tool]]></title>
            <link>https://medium.com/env0/switch-from-terraform-cloud-in-minutes-with-our-new-migration-tool-b4eff494aaea?source=rss-9233b109305d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4eff494aaea</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[env zero Team]]></dc:creator>
            <pubDate>Tue, 12 Mar 2024 10:15:39 GMT</pubDate>
            <atom:updated>2024-03-12T10:15:39.385Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgyCc4eb6GpdK3usv6ld9g.png" /></figure><p>Vendor lock-in is an important consideration when evaluating any technology. It’s great when a tool or service is a perfect fit for your requirements, but over time product features, pricing models or your needs may change.</p><p>When that happens, you want to be sure that you can migrate to a new platform with minimal effort and zero impact. The newly released migration tool from env0 makes the migration process from <a href="https://www.env0.com/blog/terraform-cloud">Terraform Cloud</a> to env0 simple, quick, and convenient.</p><h3>Why migrate from Terraform Cloud?</h3><p><a href="https://www.env0.com/blog/terraform-cloud">Terraform Cloud</a> is a Terraform automation platform offered by HashiCorp. It’s an excellent service with a broad swath of happy users.</p><p>That being said, products and requirements change over time resulting in a mismatch of product and customer. Here are a few reasons we’ve heard of customers considering a migration:</p><ol><li>The Resources Under Management (RUM) pricing has driven up costs for the platform.</li><li>The <a href="https://www.env0.com/blog/hashicorp-license-change">BSL license change </a>caused uncertainty and some would like to stick with an open-source tool.</li><li>There are new business requirements that are not met by the platform.</li></ol><p>While it’s not necessarily the main decision factor, the most common reason at the moment is the new RUM pricing model.</p><p>While it may work out advantageously for some organizations, others are structured in a way where the new pricing model causes costs to balloon. You can find a detailed analysis of <a href="https://www.env0.com/blog/terraform-cloud-pricing-a-complete-guide">Terraform Cloud pricing here</a>.</p><p>Ultimately, if Terraform Cloud is working for you, then we are not suggesting that you migrate just for kicks. But if you find yourself looking to migrate off Terraform Cloud, the new env0 migration tool can make it easier for you and assist with moving your workspaces, including state and variables to env0.</p><p>If you have more than a handful of workspaces in Terraform Cloud, migrating them to another platform manually is a time-consuming and error-prone process.</p><p>At a minimum, you need to create workspaces on the destination platform, copy over the settings and input variable values, and migrate the state data. That’s a daunting task to perform at scale, and so the env0 team created a migration tool to simplify and automate the migration process, reducing what could be days of tedious work to a few minutes of running scripts.</p><h3>Getting started with the env0 migration tool</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F914333936%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F914333936&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1800849423-6a38924401d00241b29f3fdc378dd9ab21ba8811d05ace1a894c2617928bc8a3-d_1280&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="1920" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5414b31c5b844215cf123dfc04a0a0d/href">https://medium.com/media/b5414b31c5b844215cf123dfc04a0a0d/href</a></iframe><p>Born out of frequent customer requests, the migration tool simplifies and accelerates the transfer from Terraform Cloud to env0, at any scale.</p><p>The tool is an <a href="https://github.com/env0/env0-migration-tool/tree/main/TFC">open-source project available on GitHub</a>. It is intended to migrate the contents of a Terraform Cloud workspace to an environment in env0, including the following:</p><ul><li>Project placement</li><li>VCS repository settings</li><li>Terraform version value</li><li>Variable values</li><li>State data</li></ul><p>The tool currently supports version control system (VCS) backed workspaces and will select OpenTofu on env0 if the workspace Terraform version on Terraform Cloud is 1.6 or newer.</p><h3>Migration process</h3><p>The migration process consists of a few simple stages: preparing your local machine, exporting Terraform Cloud workspace settings, and creating environments in env0.</p><p>The tool follows the process outlined below:</p><ol><li>Prepare your local machine</li><li>Export Terraform Cloud workspace settings</li><li>Create environment in env0 with exported settings</li><li>Copy state data from workspace to environment</li></ol><p>You can migrate multiple Terraform Cloud workspaces at the same time and filter using tags. Let’s walk through the process with some example workspaces in Terraform Cloud!</p><p><strong>Note:</strong> The details of the migration process may change over time, refer to the <strong>README.md</strong> file in the GitHub repository for step-by-step instructions.</p><h3>Prepare for Migration</h3><p>On my local machine, I’ve cloned the GitHub repository containing the migration tool to a local directory. I’ve also procured API tokens from both <a href="https://app.terraform.io/app/settings/tokens">Terraform Cloud</a> and <a href="https://docs.env0.com/reference/authentication#creating-a-personal-api-key">env0</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lHO1zJlostwtleSu.png" /></figure><p>On Terraform Cloud, I have three workspaces in a project called env0-migration-example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pkhYFSqUVJ60wQck.png" /></figure><p>These are the workspaces we will be migrating to env0. Looking in the details of one of the workspaces, it is using the VCS workflow linked to a public GitHub repository named tfc-azure-example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nejWbA_QTPkfW9VW.png" /></figure><p>The workspace variables include a prefix value for naming and credentials for provisioning infrastructure in Azure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GpuIOQfVcGbog5R6.png" /></figure><p>The migration process will migrate these variable values, the state data, and the workspace to env0.</p><h3>Export Terraform Cloud Workspaces</h3><p>Our first step is to export the Terraform Cloud workspaces we want to migrate using the Terraform configuration stored in the <strong>TFC</strong> directory of the cloned repository.</p><pre>$ tree TFC<br>TFC<br>├── README.md<br>├── main.tf<br>├── migrate-state<br>│   ├── README.md<br>│   ├── env0_template<br>│   ├── migrate_single_workspace.sh<br>│   ├── migrate_workspaces.sh<br>│   ├── tfc_template<br>│   └── troubleshooting-guide.md<br>├── parse_projects.tf<br>├── parse_workspaces.tf<br>├── providers.tf<br>├── tfc_data.tf<br>└── variables.tf</pre><p>Before applying the configuration, we need to create a <strong>tfvars </strong>file with the following settings defined:</p><pre># exporter.tfvars<br>tfc_token = &quot;your-tfc-token&quot;<br>tfc_organization = &quot;your-tfc-organization&quot;<br>tfc_workspace_names = [&quot;shared-network-*&quot;]</pre><p>And set the environment variable <em>TFE_TOKEN</em> to our Terraform Cloud API token:</p><pre>$ export TFE_TOKEN=lHk3h0yEenY8WA.atlasv1.zgGLxGx0478VFyKkqQHi4MOvYoJ5oNHW8W1i8ba...</pre><p>Now we can initialize the Terraform configuration and apply it.</p><pre>$ terraform init</pre><pre>Initializing the backend...</pre><pre>Initializing provider plugins…</pre><pre>Terraform has been successfully initialized!</pre><pre>$ terraform apply -var-file=&quot;exporter.tfvars&quot;<br>...<br>Plan: 1 to add, 0 to change, 0 to destroy.</pre><pre>Do you want to perform these actions?<br>  Terraform will perform the actions described above.<br>  Only &#39;yes&#39; will be accepted to approve.<br>  Enter a value: yes</pre><pre>local_file.data: Creating...<br>local_file.data: Creation complete after 0s [id=430cf17b8fe387613802fdd5ecbd988c6af62]</pre><h3>Create environments in env0</h3><p>This step involves two processes.. First, we will use the Terraform code in the <strong>env0-resources-generator</strong> directory to create a new Terraform configuration with all necessary resources for creating environments in our env0 account.</p><p>Then we’ll use the newly created configuration to actually deploy the resources to env0.</p><h4>Create a Terraform configuration for env0</h4><p>From the <strong>env0-resources-generator</strong> directory, we will run terraform init and apply, pointing to the <strong>data.json</strong> file for input:</p><pre>$ terraform init<br>Initializing the backend...<br>Initializing provider plugins...<br>Terraform has been successfully initialized!</pre><pre>$ terraform apply -var-file=../TFC/out/data.json<br>...<br>Plan: 3 to add, 0 to change, 0 to destroy.<br>Do you want to perform these actions?<br>  Terraform will perform the actions described above.<br>  Only &#39;yes&#39; will be accepted to approve.</pre><pre>  Enter a value: yes</pre><pre>local_file.main: Creating...<br>local_file.projects: Creating...<br>local_file.environments: Creating...<br>...<br>Apply complete! Resources: 3 added, 0 changed, 0 destroyed.</pre><p>The result is a collection of files in the <strong>env0-resources-generator/out</strong> directory that make up a Terraform configuration to deploy the corresponding projects and environments in env0.</p><pre>$ tree<br>.<br>├── environments.tf<br>├── main.tf<br>└── projects.tf</pre><h4>Deploy the env0 resources</h4><p>Now that we have a configuration to deploy the necessary resources in env0, we can navigate to the <strong>out</strong> directory and deploy it.</p><p>Before we run <a href="https://www.env0.com/blog/terraform-apply-guide-command-options-and-examples"><em>terraform apply</em></a><em>,</em> we need to configure a couple environment variables to authenticate to env0:</p><pre>$ export ENV0_API_KEY=yqyox_b8rogfq<br>$ export ENV0_API_SECRET=bChV5uX1feH9SA4muesySOWRnN2iafJ</pre><p>With those environment variables set, it’s a simple matter of navigating into the <strong>out</strong> directory and deploying the Terraform configuration:</p><pre>$ cd out<br>$ terraform init<br>Initializing the backend...<br>Initializing provider plugins...<br>Terraform has been successfully initialized!<br>$ terraform apply -auto-approve<br>...<br>Plan: 4 to add, 0 to change, 0 to destroy.<br>env0_project.env0-migration-example: Creating...<br>env0_project.env0-migration-example: Creation complete after 4s [id=0915eb9d-88bd-4ea8-9734]<br>env0_environment.shared-network-dev: Creating...<br>env0_environment.shared-network-stage: Creating...<br>env0_environment.shared-network-prod: Creating...<br>env0_environment.shared-network-dev: Creation complete after 2s [id=3b680701-f145-478d]<br>env0_environment.shared-network-prod: Creation complete after 5s [id=9652b5b5-4ebc-4813]<br>env0_environment.shared-network-stage: Creation complete after 5s [id=303b19b4-bade-4279]<br><br>Apply complete! Resources: 4 added, 0 changed, 0 destroyed.</pre><p>When the deployment completes, we’ll now have a project with three environments deployed in env0 that mirrors our workspaces in Terraform Cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6tmbfNARi4fiQT3X.png" /></figure><p>Looking inside the ‘Variables’ section of the <em>shared-network-dev</em> environment shows that both the Terraform and Environment variables have been copied over.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FtRAj2XILzZtupn6.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qthG_dKn4gTo32Ma.png" /></figure><p>Since the <em>ARM_CLIENT_SECRET</em> was stored as sensitive in Terraform Cloud, the migration tool uses a placeholder value of <em>secret_value_from_terraform_cloud</em>, which we need to update to the actual value.</p><p>The migration tool does not copy sensitive values to help prevent possible leakage and exposure on your local workstation. (Honestly, we should be using OIDC authentication anyway!)</p><p>Before we update the <em>ARM_CLIENT_SECRET</em> variable value, we still need to migrate the state data for our workspaces as well.</p><h3>Copy state data from workspace to environment</h3><p>The state migration process uses the <strong>migrate_workspaces.sh </strong>bash script found in the <strong>TFC/migrate-state</strong> directory.</p><p>Before we run the script, we will need to set some additional environment variables:</p><pre>$ export ENV0_ORG_ID=111111-1111-1111-1111-11111111111<br>$ export TFC_ORG_NAME=your-tfc-org-name</pre><p>The script also needs us to log into the Terraform Cloud and env0 backends using the <em>terraform login</em> command. First, we’ll generate a base64 token based on our env0 API credentials and use that value to log into the env0 backend:</p><pre>$ echo -n $ENV0_API_KEY:$ENV0_API_SECRET | base64<br>eXF5b3hfYjhyb2dmcWZfZTpiQ2hWNXVYMWZlSDlTQTRtdWVzeVNPV1JuTjJpYWZKOA==<br>$ terraform login backend.api.env0.com</pre><p>Then log into Terraform Cloud using the token value stored in the <em>TFC_TOKEN</em> environment variable:</p><pre>$ terraform login</pre><p>Once those prerequisites are met, we can run the script from the <strong>migrate-state</strong> directory:</p><pre>./migrate_workspaces.sh<br>-------<br>Migrating state for workspace: shared-network-dev<br>-------<br>Initializing Terraform with TFC backend and pulling state<br>Initializing Terraform Cloud...<br>Initializing provider plugins...<br>- Finding latest version of hashicorp/azurerm...<br>- Installing hashicorp/azurerm v3.90.0...<br>- Installed hashicorp/azurerm v3.90.0 (signed by HashiCorp)<br>...<br><br>Terraform Cloud has been successfully initialized!<br>...<br>Pulled Terraform state from TFC<br>Initializing Terraform with env0 backend and pushing state<br>Initializing the backend...<br>Successfully configured the backend &quot;remote&quot;! Terraform will automatically<br>use this backend unless the backend configuration changes.<br>Initializing provider plugins...<br>Terraform has been successfully initialized!<br>Pushed Terraform state to env0</pre><p>The script will find the <strong>data.json</strong> file generated earlier and use its contents to migrate the state data for each workspace.</p><p>Looking at the State tab for the <em>shared-network-dev</em> environment, there is now an entry for the data we just copied over.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K_vzhN8RSDMlMLLh.png" /></figure><p>Our last step is to confirm the environment is set up and working properly.</p><h3>Test an Environment</h3><p>In the <em>shared-network-dev</em> environment, we’ll first update the <em>ARM_CLIENT_SECRET</em> environment variable with the correct value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fFuKrp2TiSnYYVoX.png" /></figure><p>And then kick off a Redeploy action to verify that the environment matches the actual infrastructure deployed in Azure. After a few minutes, the plan comes back that no changes are required, meaning that the infrastructure matches the configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aZSneBPW-_zHVl1f.png" /></figure><p>Success!</p><p>We have migrated our workspaces from Terraform Cloud to env0 without impacting the actual infrastructure!</p><h3>Key Points to Note for a Successful Migration</h3><p>Here are a few considerations and aspects to keep in mind for a smooth experience:</p><ul><li>You will need to be able to run a bash script for state migration.</li><li>Workspaces that have a VCS workflow enabled are supported.</li><li>Variable sets associated with a workspace or project are not exported.</li><li>Permissions assigned to projects and workspaces are not exported.</li><li>Modules stored in the private registry are not exported.</li><li>Policy sets associated with the workspaces are not exported.</li></ul><h3>Post-migration setup and features</h3><p>After completing the migration process, there are just a few tasks we recommend doing:</p><ul><li>Verify that your env0 account has access to the VCS repositories used by each workspace</li><li>Configure permissions on each workspace to match Terraform Cloud</li><li>Set up cloud provider credentials for each workspace if they were not part of the migrated variables</li></ul><p>While you’re at it, you can also take advantage of some excellent features of env0:</p><ul><li><a href="https://www.env0.com/blog/tutorial-achieving-auto-remediation-with-env0"><strong>Drift Detection</strong></a> — Enables you to stay one step ahead of all discrepancies between target environments and source infrastructure code, enabling you also to create scheduled checks for infrastructure drift and notify your teams when an environment is in a <em>drifted</em> state.</li><li><a href="https://www.env0.com/blog/finops-meets-iac-granular-cloud-cost-optimization-with-env0"><strong>Cost Monitoring</strong></a> — Continuously tracks your actual cost, using patented technology, augmented by the ability to granularly set budget thresholds and auto-notifications.</li><li><a href="https://www.env0.com/blog/opa-tutorial-leveraging-env0-for-advanced-cloud-policy-management"><strong>OPA Integration</strong> </a>— Flexible way to configure Policy-as-Code for your environments using the Open Policy Agent. If you’re already using OPA on Terraform Cloud, you can use the same policies with env0.</li></ul><h3>What else you should know about env0</h3><p>Since you’re already considering a migration to env0, here are a few important things you should know about the platform:</p><h3>It supports ALL the relevant frameworks</h3><p>env0 goes beyond Terraform and OpenTofu, integrating effortlessly with additional tools like CloudFormation, Pulumi, Kubernetes, and Helm.</p><p>This is useful, especially for cloud-native environments that make heavy use of Helm and Kubernetes, being able to use a single platform to manage all of your IaC real estate is a huge time saver and lowers administrative overhead.</p><h3>It’s designed to offer maximal flexibility and enhanced reliability</h3><p>env0 uses a hierarchy consisting of five layers, each of which can inherit settings and permissions from the parent scope. The five layers start at the organization, and then down through templates, projects, environments, and workflows.</p><p>Each layer can contain variable values to use in the workflow that is executed for an environment. Importantly, policies and permissions can also be applied at each scope, creating a robust management structure scaling well beyond a handful of environments.</p><p>This is especially helpful for organizations looking to expand IaC usage across different teams and promote managed self-service.</p><h3>It streamlines complex environment management</h3><p>Complex infrastructure architectures should be decoupled into separate configurations to simplify deployment and reduce the blast radius of changes. However, expressing dependencies across those configurations and sequencing the workflow can act as a barrier to adopting this practice.</p><p>env0 includes a multi-environment, tiered workflow option that allows you to express dependencies and deployment order of sub-environments using a declarative YAML file. And because env0 supports multiple frameworks, you can combine those frameworks in a single workflow to fully express your complex architecture.</p><h3>It accelerates development processes with rapid iteration</h3><p>env0’s remote backend supports running remote operations from the command line to test uncommitted changes while still taking advantage of the custom workflows defined for an environment.</p><p>Developers can rapidly iterate through IaC testing and validation using their local environment before formally promoting changes through VCS, improving developer productivity and streamlining the change process.</p><p>Even better, you are not required to store state data on env0’s remote backend to take advantage of remote operations.</p><p>Some customers must store state data in their own self-hosted backend, and we’re happy to provide the best of both worlds, flexible state data hosting and remote operations.</p><h3>Wrap up</h3><p>Infrastructure engineers should be able to pick the solution that meets their needs today and be able to shift to a different solution if the need arises. env0’s Terraform Cloud migration tool helps do just that, simplifying and automating the process of migrating your Terraform Cloud workspaces to the platform.</p><p>To learn more about this and other env0 features, <a href="https://www.env0.com/demo-request">schedule a demo </a>with a technical expert to see the platform in action.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4eff494aaea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/env0/switch-from-terraform-cloud-in-minutes-with-our-new-migration-tool-b4eff494aaea">Switch from Terraform Cloud in Minutes with Our New Migration Tool</a> was originally published in <a href="https://medium.com/env0">env0</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>