<?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 Scalr on Medium]]></title>
        <description><![CDATA[Stories by Scalr on Medium]]></description>
        <link>https://medium.com/@scalr?source=rss-a6d3183ee598------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*azW1Gnh4D5YSvj1cViEc8w@2x.png</url>
            <title>Stories by Scalr on Medium</title>
            <link>https://medium.com/@scalr?source=rss-a6d3183ee598------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 01:16:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@scalr/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[Is Scalr Really a Drop-In Replacement for Terraform Cloud?]]></title>
            <link>https://medium.com/scalr/is-scalr-really-a-drop-in-replacement-for-terraform-cloud-215c5bdbbad7?source=rss-a6d3183ee598------2</link>
            <guid isPermaLink="false">https://medium.com/p/215c5bdbbad7</guid>
            <category><![CDATA[terraform-cloud]]></category>
            <dc:creator><![CDATA[Scalr]]></dc:creator>
            <pubDate>Wed, 08 Apr 2026 07:16:59 GMT</pubDate>
            <atom:updated>2026-04-08T14:21:12.099Z</atom:updated>
            <content:encoded><![CDATA[<h3>Let’s verify the claims that Scalr is a cost-effective, drop-in replacement with feature parity and better GitOps support.</h3><p>There are 4 separate claims being made here: that Scalr is cost-effective, that it’s a drop-in replacement, that it has feature parity, and that its GitOps support is better. Let’s dive into the details.</p><h3>Drop-In Means Drop-In</h3><p>Switching IaC platforms sounds like a multi-quarter migration project. It isn’t.</p><p>Scalr is fully compatible with the Terraform CLI and the TFC API. Your developers keep running terraform plan and terraform apply exactly the way they do today — same commands, same workflow, no retraining. The only thing that changes is where runs execute.</p><p><strong>TFC API compatibility</strong> means integrations you or third parties built against the TFC API work with Scalr. Tools like AWS Account Factory for Terraform (AFT), CI/CD pipelines calling the TFC API, custom scripts that manage workspaces programmatically — change the endpoint URL and they work. No rewrites.</p><p><strong>The migration assistant</strong> moves your workspaces, variables, and state files automatically. Teams with 500+ workspaces have migrated in under a week. The process:</p><ol><li>Point the migration assistant at your TFC organization</li><li>Select workspaces to migrate (or migrate all)</li><li>Scalr imports workspace configurations, variable sets, and state</li><li>Update your CLI configuration to point at Scalr</li><li>Done</li></ol><p><strong>Familiar organizational model.</strong> Scalr’s hierarchy — accounts, environments, workspaces — maps directly to how TFC organizes things. Your team doesn’t have to learn a new mental model. Environments provide the isolation TFC handles with workspace-level boundaries, but with inheritance: variables, provider configurations, and policies set at a higher scope cascade down automatically, which means less duplication and fewer configuration errors. For organizations managing multiple business units or subsidiaries, Control Tower federates management and billing across many Scalr accounts under a single parent — unified reporting without sacrificing isolation between teams.</p><h3>Cost-Effective: Run-Based vs. Resource-Based Pricing</h3><p>The core pricing difference is structural, not a matter of discounts.</p><p><strong>Terraform Cloud charges by Resources Under Management (RUM).</strong> Your bill grows with infrastructure size regardless of activity. Double your managed resources, double your bill — even if nobody touched them. And the moment you need governance features like drift detection, policy enforcement, or audit logging, you jump from the Essentials tier ($0.10/resource/month) to Standard ($0.47/resource/month) — a 4.7x price increase per resource. That’s where costs really accelerate: you’re paying nearly five times more per resource just to get the visibility and controls that platform teams need.</p><p><strong>Scalr charges by run.</strong> Costs scale linearly with how much you actually use Terraform, not how much infrastructure exists. A team that manages 1,000 resources but only runs 500 plans/month pays for 500 runs — period. If infrastructure grows to 5,000 resources but run volume stays at 500, the bill doesn’t change.</p><p>Beyond the pricing model, Scalr doesn’t gate core platform capabilities behind tier upgrades:</p><ul><li><strong>Governance included from day one.</strong> OPA policy enforcement, RBAC with 120+ custom permissions, drift detection, audit trails, cost estimation, and team management are available on the free and standard plans. On TFC, drift detection, audit logging, and teams require the Standard tier — which costs 4.7x more per resource than Essentials. Scalr reserves its Enterprise plan for features like advanced compliance and security controls, not for the governance basics your team needs on day one.</li><li><strong>Drift detection doesn’t cost extra.</strong> On TFC, drift detection (“health assessments”) requires upgrading to the Standard tier at $0.47/resource/month — and your bill is still growing with every resource whether it drifted or not. On Scalr, drift detection is included on every plan, including free, and drift checks don’t consume a billable run. That means you can schedule daily checks across all workspaces without watching the meter.</li><li><strong>Non-billable failure points.</strong> Runs that fail at pre-init, Checkov scanning, or pre-plan OPA policy checks don’t consume a billable run. You’re not paying for runs that were going to fail anyway.</li></ul><p>The result: most teams see 50%+ savings (calculated from a 100+ sample size). Teams with large, stable infrastructure (lots of resources, moderate run volume) save even more — up to 80% — because the RUM-to-run ratio is heavily in their favor.</p><h3>Feature Parity — and Then Some</h3><p>Scalr maintains feature parity with Terraform Cloud across basic capabilities, such as:</p><ul><li>Remote State Management</li><li>Remote Execution</li><li>VCS Integration</li><li>Policy as Code</li><li>RBAC and Team Management</li><li>Workspace-based Organization</li><li>Variable Management</li><li>Run Triggers</li><li>Private Registries</li></ul><p>Beyond parity, Scalr extends several of these capabilities with deeper governance, more flexible access control, and architectural choices that TFC doesn’t offer.</p><h4>Governance</h4><ul><li><strong>SCIM provisioning:</strong> Scalr supports the SCIM protocol for automated user provisioning and deprovisioning through Okta and Azure AD (Entra ID). When someone joins or leaves your org in your IdP, their Scalr access updates automatically — no manual invite/revoke cycle. TFC doesn’t offer native SCIM at any plan level; SSO is available, but it doesn’t automatically provision or deprovision users, so you’re left managing the user lifecycle manually or scripting against their API.</li><li><strong>RBAC:</strong> TFC supports custom permission sets at the workspace level, but Scalr’s RBAC is broader and more granular: 120+ individual permissions that you compose into custom roles at account, environment, or workspace scope. If you need a role that can trigger runs and view cost estimates but can’t approve applies or modify variables — you can build exactly that. TFC’s custom permissions are workspace-scoped only and don’t cover the same breadth of operations.</li><li><strong>Private Registries:</strong> Both platforms offer a private module registry, but Scalr adds a namespace layer on top. Namespaces let you organize modules into logical groups (by team, project, department — whatever fits), assign team ownership to each namespace, and control which environments can consume the modules within it. A platform team can publish shared infrastructure modules into an account-wide namespace, while an app team manages their own namespace scoped to just their environments. TFC’s registry is flat by comparison — modules are published per-organization without granular ownership or selective sharing across organizational boundaries.</li></ul><h4>State Management</h4><p>Choose where your state lives: Scalr-managed storage, or customer-managed (with OIDC) allowing you to store state in your own S3 buckets, GCS, or Azure storage. On TFC, state is HashiCorp-managed only. For teams with data sovereignty requirements or compliance mandates that state data stays within their cloud account, this is a significant difference.</p><h4>Terragrunt Support</h4><p>Scalr supports both Terraform and OpenTofu side by side, plus native Terragrunt support with run-all orchestration and dependency resolution. TFC supports Terraform only and has no Terragrunt support.</p><h3>Better GitOps</h3><p>This is where Scalr pulls ahead decisively. TFC’s VCS integration covers the basics — trigger a run from a commit, post a status check. Scalr provides you with the option to treat the pull request as the control plane for infrastructure changes.</p><h4>Apply-Before-Merge AND Merge-Before-Apply</h4><p>TFC only supports merge-before-apply: you merge your PR to main, then the apply runs against the main branch. That means untested infrastructure changes land in main before they’re applied — and if the apply fails, you’ve got a broken commit in your default branch.</p><p>Scalr supports merge-before-apply of course, making migration easy and painless, but also apply-before-merge as an additional option. The latter is often preferred by teams that want to ensure main branch always reflects successfully applied infrastructure. The workflow is: apply changes from a feature branch, verify they succeed, then merge a known-good PR.</p><h4>PR Comment Commands</h4><p>Manage the entire run lifecycle without leaving your pull request:</p><ul><li>/scalr plan — trigger a new plan</li><li>/scalr apply — apply the current plan</li><li>/scalr approve — approve a run awaiting approval</li><li>/scalr decline — decline a pending run</li><li>/scalr ai-explain — invoke the AI assistant for error explanation or plan summary</li></ul><p>TFC has no equivalent. Teams migrating from Atlantis will find this workflow immediately familiar.</p><h4>Rich PR Integration</h4><p>Plan and apply summaries post directly into the PR as comments and checks — not just basic commit status indicators. Reviewers see exactly what infrastructure changes a PR introduces, what they cost, and whether policies passed, all without navigating to an external UI.</p><h4>Branch-Aware State Protection</h4><p>Scalr tracks which branch generated the current state. If your run branch differs from the state-generating branch, Scalr warns and blocks auto-apply to prevent accidental state overwrites. TFC has no branch-aware state protection — it’s possible to accidentally apply a feature branch’s changes on top of state generated from a different branch.</p><h4>Noise Reduction</h4><p>Pull request workflows generate a lot of Terraform runs. Scalr gives you controls to cut the noise:</p><ul><li><strong>Configurable diff strategy</strong>: Choose between base-commit or previous-commit diff to avoid triggering plans on irrelevant changes. TFC has no equivalent.</li><li><strong>Draft PR detection</strong>: Skip run triggering on draft PRs so work-in-progress doesn’t generate unnecessary runs.</li><li><strong>Auto-merge from main</strong>: Scalr can auto-merge main into dev branches to keep them current with upstream, avoiding drift between your feature branch and the target branch.</li></ul><h4>Policy Impact Analysis</h4><p>Preview the effect of upcoming policy changes before they take effect across your workspaces. When you update your OPA policies in VCS, you can see which existing workspaces would be affected — before the new policies go live. TFC doesn’t support this.</p><h4>Azure DevOps Support</h4><p>Scalr supports Azure DevOps marketplace app installation and org-level tokens for least-privilege access. TFC only supports basic OAuth2 integration with Azure DevOps.</p><h3>Purpose-Built for Terraform and OpenTofu</h3><p>Scalr focuses exclusively on Terraform and OpenTofu. There’s no bolted-on support for Pulumi, CloudFormation, Ansible, or Kubernetes adding complexity to the platform. That focus means deeper native support for Terraform workflows, faster feature development for the IaC tools your team actually uses, and a UI and API designed around the Terraform operational model — not a lowest-common-denominator abstraction layer across five different tools.</p><p>If parts of your stack still use Pulumi, CloudFormation, or Ansible, the pragmatic move isn’t to find one platform that does everything poorly — it’s to standardize on Terraform for new work, get a purpose-built platform for it, and let the legacy tooling run where it is while you modernize. Scalr gives you the depth to make that Terraform investment pay off. The old stuff can migrate at its own pace.</p><h3>Trusted by Enterprise Teams and Scale-Ups</h3><p>Allianz, Samsung, Accenture, ExpressVPN, Peloton, and Hex run their infrastructure through Scalr. SOC 2 Type 2 certified, with SAML 2.0 SSO, SCIM provisioning, self-hosted agents for network isolation, and customer-managed state storage for data sovereignty.</p><h3>See It for Yourself</h3><p>The fastest way to evaluate Scalr is with your own workspaces. Book a demo and we’ll walk through the migration from your TFC organization, show you the GitOps workflow on a real PR, and calculate your projected savings.</p><p><a href="https://scalr.com/demo"><strong>Book a Demo →</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=215c5bdbbad7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scalr/is-scalr-really-a-drop-in-replacement-for-terraform-cloud-215c5bdbbad7">Is Scalr Really a Drop-In Replacement for Terraform Cloud?</a> was originally published in <a href="https://medium.com/scalr">scalr</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use the Terraform Datadog Provider]]></title>
            <link>https://medium.com/@scalr/how-to-use-the-terraform-datadog-provider-f0769fe52ea2?source=rss-a6d3183ee598------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0769fe52ea2</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[datadog]]></category>
            <dc:creator><![CDATA[Scalr]]></dc:creator>
            <pubDate>Tue, 24 Jun 2025 11:19:48 GMT</pubDate>
            <atom:updated>2025-07-18T10:34:11.466Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sCqQy0OfEJGKeqmzrs6qcA.png" /><figcaption>4 reasons to use the Terraform provider for Datadog</figcaption></figure><p>This guide provides an overview of how to define, version, and manage Datadog with Terraform, including setup and best practices.</p><h3>Why Use Terraform for Datadog?</h3><p>The value of managing Datadog as code goes beyond simple automation. It allows for:</p><ul><li><strong>Version Control &amp; Auditability:</strong> By storing configurations in Git, you get a complete, auditable history of every change. This is invaluable for compliance, security reviews, and incident post-mortems.</li><li><strong>Consistency &amp; Reliability:</strong> Automation eliminates the risk of human error from manual configuration. You can ensure that monitoring is applied consistently across all your environments, from development to production.</li><li><strong>Lifecycle Cohesion:</strong> You can bundle an application’s observability components with its infrastructure. When you deploy a new service, the same terraform apply can create the required servers, databases, <em>and</em> the corresponding Datadog monitors and dashboards.</li><li><strong>Drift Detection:</strong> terraform plan acts as a powerful safety net. It detects any manual changes made in the Datadog UI, allowing you to either revert them or bring them into code, preventing configuration drift.</li></ul><h3>Getting Started: Provider Setup</h3><p>Before you can manage any resources, you need to configure the Datadog provider.</p><p>First, declare the provider in your Terraform configuration. Pinning the version is a recommended best practice.</p><pre># main.tf terraform { required_providers { datadog = { source = &quot;DataDog/datadog&quot; version = &quot;~&gt; 3.66&quot; } } }</pre><p>Next, you need to authenticate. The provider requires an API key and an Application key from your Datadog account. The most secure method is to set these as environment variables, which the provider automatically uses:</p><p>Finally, configure the provider block. If you are not using the default Datadog US1 site, you must specify your site’s api_url.</p><pre># main.tf provider &quot;datadog&quot; { # The provider will automatically use the environment variables # for api_key and app_key. # Example for a user on the EU site api_url = &quot;https://api.datadoghq.eu/&quot; }</pre><h3>Practical Examples</h3><p>With the setup complete, you can start defining Datadog resources.</p><h4>Creating a Monitor</h4><p>Monitors are the foundation of your alerting strategy. Here is how you can define a standard metric alert for high CPU usage, complete with warning and critical thresholds, a contextual message, and tags for routing.</p><pre>resource &quot;datadog_monitor&quot; &quot;high_cpu_usage&quot; { name = &quot;High CPU Usage on {{host.name}}&quot; type = &quot;metric alert&quot; query = &quot;avg(last_5m):avg:system.cpu.user{*} by {host} &gt; 80&quot; message = &quot;CPU usage is critically high on host {{host.name}}. Please investigate. @pagerduty-platform-team&quot; monitor_thresholds { warning = 70 critical = 80 } notify_no_data = true no_data_timeframe = 20 tags = [&quot;service:core-api&quot;, &quot;env:prod&quot;, &quot;managed_by:terraform&quot;] }</pre><h4>Defining a Dashboard</h4><p>You can define entire dashboards in code. A common challenge, however, is dynamically generating widgets. The standard datadog_dashboard resource is not well-suited for this.</p><p>The solution is to use the datadog_dashboard_json resource, which accepts a JSON string. This allows you to use Terraform&#39;s for expressions to programmatically generate your widget definitions.</p><pre># variables.tf variable &quot;widget_configurations&quot; { type = map(object({ title = string query = string })) default = { &quot;cpu_usage&quot; = { title = &quot;CPU Usage&quot;, query = &quot;avg:system.cpu.user{*}&quot; }, &quot;memory_usage&quot; = { title = &quot;Memory Usage&quot;, query = &quot;avg:system.mem.used{*}&quot; } } } # main.tf resource &quot;datadog_dashboard_json&quot; &quot;programmatic_dashboard&quot; { dashboard = jsonencode({ title = &quot;Programmatically Generated Dashboard&quot; layout_type = &quot;ordered&quot; widgets = [ for key, config in var.widget_configurations : { definition = { type = &quot;timeseries&quot; title = config.title requests = [ { q = config.query } ] } } ] }) }</pre><h4>Defining a Service Level Objective (SLO)</h4><p>Codifying SLOs is a cornerstone of modern SRE. This example defines a 99.9% availability SLO based on the ratio of successful API requests to total requests.</p><pre>resource &quot;datadog_service_level_objective&quot; &quot;api_availability&quot; { name = &quot;API Request Availability&quot; type = &quot;metric&quot; description = &quot;99.9% of all API requests should be successful (non-5xx).&quot; query { numerator = &quot;sum:trace.http.request.hits{env:prod,service:core-api,!status_code:5xx}.as_count()&quot; denominator = &quot;sum:trace.http.request.hits{env:prod,service:core-api}.as_count()&quot; } thresholds { target = 99.9 timeframe = &quot;30d&quot; warning = 99.95 } tags = [&quot;service:core-api&quot;, &quot;env:prod&quot;, &quot;slo:availability&quot;] }</pre><h3>Best Practices</h3><p>As your usage grows, managing a single, monolithic Terraform configuration becomes a bottleneck. To manage Datadog at scale, consider these best practices:</p><ol><li><strong>Use Modules:</strong> Encapsulate common patterns into reusable modules. For example, create a “standard service” module that bundles monitors for latency, error rate, and saturation. This promotes consistency and reduces code duplication.</li><li><strong>Separate Environments:</strong> Use a directory-based structure to maintain separate state files for each environment (e.g., dev, staging, prod). This provides strong isolation and prevents changes in one environment from impacting another.</li><li><strong>Split Your State:</strong> The biggest challenge at scale is a slow, monolithic Terraform state file. Split your state into smaller, more manageable units. Common strategies include splitting by team, by service, or by Datadog resource type. This dramatically improves performance and reduces the blast radius of any single change.</li></ol><h3>Datadog Product to Terraform Resource Mapping</h3><p>The following table serves as a quick reference for mapping common Datadog products to their corresponding Terraform resource types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*zF9Hsg7Gu1b5ao1TUXkLfg.png" /><figcaption>Datadog products to their corresponding Terraform resource types</figcaption></figure><p>You might also be interested in <a href="https://scalr.com/learning-center/how-to-use-the-terraform-okta-provider/">how to use the Terraform Okta Provider</a>.</p><p><em>Originally published at </em><a href="https://scalr.com/learning-center/how-to-use-the-datadog-terraform-provider/"><em>https://scalr.com</em></a><em> on June 24, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0769fe52ea2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Terraform with GitLab]]></title>
            <link>https://medium.com/@scalr/using-terraform-with-gitlab-ca31a3962f44?source=rss-a6d3183ee598------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca31a3962f44</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[gitlab]]></category>
            <dc:creator><![CDATA[Scalr]]></dc:creator>
            <pubDate>Mon, 23 Jun 2025 15:03:48 GMT</pubDate>
            <atom:updated>2025-06-24T10:54:17.573Z</atom:updated>
            <content:encoded><![CDATA[<p>This guide describes how to use Terraform with GitLab, covering CI/CD, State, Modules, and Security.</p><p>Almost all GitLab Terraform integration features are covered, from pipelines to state management to private module registries and even managing GitLab itself using Terraform. We also cover best practices for maintainability and security.</p><p><strong>What We’ll Cover:</strong></p><ul><li>GitLab as a Version Control System (VCS) for your Terraform files.</li><li>Securely managing Terraform state files with GitLab’s built-in HTTP backend.</li><li>Building GitLab CI/CD pipelines for Terraform automation, including OIDC for cloud authentication.</li><li>Leveraging GitLab as a private Terraform Module Registry.</li><li>Using the GitLab Terraform Provider to manage GitLab resources.</li><li>7 security best practices for your Terraform and GitLab workflows.</li></ul><p>By the end of this post, you’ll understand how to transform your infrastructure management into a streamlined, automated, and secure operation.</p><h3>GitLab as a VCS for Terraform</h3><p>The absolute cornerstone of using GitLab with Terraform is version controlling your Terraform code. Storing your *.tf and *.tfvars files in a GitLab project provides numerous advantages:</p><ul><li><strong>Tracking Changes:</strong> Every modification to your infrastructure definition is tracked with Git commits, providing a clear audit trail of who changed what, when, and why.</li><li><strong>Collaboration:</strong> GitLab enables multiple developers and operations team members to work on the same Terraform configuration concurrently using feature branches.</li><li><strong>History and Rollback:</strong> Maintain a complete history of your infrastructure’s evolution. If issues arise, you can easily review past changes or roll back to a previous known-good state of your Terraform files.</li><li><strong>Branching and Merging:</strong> Use Git branching strategies (e.g., Gitflow, GitLab Flow) to manage new features, bug fixes, or environment-specific configurations. Merge requests provide a formal process for proposing and reviewing changes.</li><li><strong>Code Review:</strong> Facilitate peer reviews of your Terraform code before changes are applied, improving code quality and catching potential errors early. This is a good practice for any IaC setup.</li></ul><h3>Structuring Terraform Code in GitLab</h3><p>A common way to structure your Terraform code within a GitLab project involves:</p><ul><li>main.tf: Defines your primary set of Terraform resources.</li><li>variables.tf: Declares input variables.</li><li>outputs.tf: Defines outputs from your configuration.</li><li>versions.tf: Specifies Terraform version and provider plugins versions.</li><li>providers.tf: Configures Terraform providers (e.g., AWS, Azure, GCP, GitLab).</li><li>terraform.tfvars (often environment-specific, like dev.tfvars, prod.tfvars): Contains variable values. Ensure sensitive values are not committed here; use GitLab CI/CD variables instead.</li><li>.gitlab-ci.yml: Defines your GitLab CI/CD pipeline for Terraform automation.</li></ul><p>For multi-environment setups, you might use separate directories per environment or leverage Terraform workspaces (more on this in the CI/CD section).</p><p>More on <a href="https://scalr.com/learning-center/how-to-structure-terraform/">structuring Terraform code</a> here.</p><h3>Managing Terraform State in GitLab</h3><p>Terraform state files (terraform.tfstate) are critical. They store the mapping between your Terraform configuration and the real-world resources. Storing state locally on your local machine or in local storage is risky and unsuitable for team collaboration. This is where Terraform remote backends come into play, and GitLab offers a powerful, integrated solution: GitLab-Managed Terraform State.</p><h3>GitLab-Managed Terraform State (HTTP Backend)</h3><p>GitLab can act as a remote backend for your Terraform state files using its built-in Terraform HTTP backend. This offers several advantages:</p><ul><li><strong>Centralized Storage:</strong> State files are stored within your GitLab project, providing a single location for both your code and its corresponding state.</li><li><strong>Security:</strong> State files are encrypted at rest and in transit (via HTTPS).</li><li><strong>Versioning:</strong> GitLab automatically versions your state files, allowing you to track changes and potentially roll back if needed.</li><li><strong>State Locking:</strong> Automatic state lock prevents concurrent modifications, reducing the risk of state corruption.</li><li><strong>Integration:</strong> Seamlessly integrates with GitLab CI/CD and user permissions.</li></ul><h3>Setup and Configuration</h3><p><strong>1. Terraform Backend Configuration:</strong></p><p>In your Terraform project (e.g., in providers.tf or a dedicated backend.tf file), declare the HTTP backend:</p><pre>terraform {<br>  backend &quot;http&quot; {<br>    // Configuration will be provided during init<br>  }<br>}</pre><p><strong>2. Initializing the Backend (Local Machine):</strong></p><p>To initialize this backend from your local terminal for the first time or for local development against a GitLab-managed state:</p><pre># Ensure you have a GitLab Personal Access Token with &#39;api&#39; scope<br>export GITLAB_ACCESS_TOKEN=&quot;your_personal_access_token&quot;<br>export GITLAB_USERNAME=&quot;your_gitlab_username&quot;</pre><pre>terraform init \<br>  -backend-config=&quot;address=https://gitlab.com/api/v4/projects/&lt;YOUR_PROJECT_ID&gt;/terraform/state/&lt;YOUR_STATE_NAME&gt;&quot; \<br>  -backend-config=&quot;lock_address=https://gitlab.com/api/v4/projects/&lt;YOUR_PROJECT_ID&gt;/terraform/state/&lt;YOUR_STATE_NAME&gt;/lock&quot; \<br>  -backend-config=&quot;unlock_address=https://gitlab.com/api/v4/projects/&lt;YOUR_PROJECT_ID&gt;/terraform/state/&lt;YOUR_STATE_NAME&gt;/lock&quot; \<br>  -backend-config=&quot;username=${GITLAB_USERNAME}&quot; \<br>  -backend-config=&quot;password=${GITLAB_ACCESS_TOKEN}&quot; \<br>  -backend-config=&quot;lock_method=POST&quot; \<br>  -backend-config=&quot;unlock_method=DELETE&quot; \<br>  -backend-config=&quot;retry_wait_min=5&quot;</pre><p>Replace &lt;YOUR_PROJECT_ID&gt; with your GitLab project&#39;s ID and &lt;YOUR_STATE_NAME&gt; with a descriptive name for your state (e.g., production, vpc). The address is the URL of the remote state backend.</p><p><strong>3. Initializing the Backend (GitLab CI/CD):</strong></p><p>Within a GitLab CI job, initialization is simpler as GitLab provides necessary environment variables. The gitlab-terraform helper scripts (though templates are being deprecated, the underlying mechanism is similar) or direct terraform init commands can leverage CI_API_V4_URL, CI_PROJECT_ID, and CI_JOB_TOKEN.</p><p>A common setup in .gitlab-ci.yml using direct Terraform commands:</p><pre>variables:<br>  TF_STATE_NAME: &quot;default&quot; # Or make this dynamic per environment<br>  TF_ADDRESS: &quot;${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}&quot;</pre><pre># ... inside a script section for init job ...<br>terraform init \<br>  -backend-config=&quot;address=${TF_ADDRESS}&quot; \<br>  -backend-config=&quot;lock_address=${TF_ADDRESS}/lock&quot; \<br>  -backend-config=&quot;unlock_address=${TF_ADDRESS}/lock&quot; \<br>  -backend-config=&quot;username=gitlab-ci-token&quot; \<br>  -backend-config=&quot;password=${CI_JOB_TOKEN}&quot; \<br>  -backend-config=&quot;lock_method=POST&quot; \<br>  -backend-config=&quot;unlock_method=DELETE&quot; \<br>  -backend-config=&quot;retry_wait_min=5&quot;</pre><p>Here, CI_JOB_TOKEN is used for authentication, which is a secure, short-lived access token.</p><h3>Permissions and Roles</h3><p>GitLab uses its standard project roles for controlling access to the Terraform state:</p><ul><li><strong>Developer Role:</strong> Can read the state (e.g., for terraform plan -lock=false).</li><li><strong>Maintainer Role:</strong> Can write to the state (e.g., terraform apply) and manage locks.</li><li><strong>Guest Role:</strong> Importantly, if your project is public or internal, users with Guest access might be able to view job artifacts like Terraform plan outputs, which can contain sensitive information. We’ll address securing plan files later.</li></ul><h3>Self-Managed GitLab Considerations</h3><p>For self-managed GitLab instances, GitLab administrators need to configure Terraform state storage. This can be a local filesystem path on the GitLab server or an object storage service like Amazon S3 or Google Cloud Storage. Using object storage is recommended for clustered GitLab deployments to avoid split-brain scenarios.</p><h3>Migrating to GitLab-Managed State</h3><p>If you have an existing state file in a different state storage backend (e.g., local, S3 bucket) or want to change the state name or location, Terraform supports state migration.</p><ol><li>Ensure your current Terraform configuration is initialized with the old backend.</li><li>Update your backend &quot;http&quot; {} block if necessary, but primarily you&#39;ll provide the new configuration during the init command.</li><li>Run terraform init -migrate-state. Terraform will prompt you for the configuration of the new backend (your GitLab HTTP backend details) and ask for confirmation to copy the old state to the new location. This is useful if you&#39;re starting with an empty state in GitLab but want to bring in an existing setup.</li></ol><pre># Example: Migrating from a local state to GitLab-managed state<br># First, ensure your backend &quot;http&quot; {} block is in your .tf files.<br># Then, run init with the new GitLab backend config and the -migrate-state flag:<br>terraform init -migrate-state \<br>  -backend-config=&quot;address=https://gitlab.com/api/v4/projects/&lt;PROJECT_ID&gt;/terraform/state/&lt;NEW_STATE_NAME&gt;&quot; \<br>  # ... other backend-config parameters as shown before ...</pre><p>Terraform will detect the change and ask to copy the state.</p><h3>Accessing Remote State Across Configurations</h3><p>Often, you need to share outputs from one Terraform configuration (e.g., network setup) with another (e.g., application deployment). The terraform_remote_state Terraform data source allows this.</p><pre># variables.tf<br>variable &quot;network_state_address&quot; {<br>  description = &quot;URL of the network Terraform state in GitLab&quot;<br>  type        = string<br>}<br>variable &quot;gitlab_api_user&quot; {<br>  description = &quot;GitLab username for accessing remote state&quot;<br>  type        = string<br>}<br>variable &quot;gitlab_api_token&quot; {<br>  description = &quot;GitLab token (PAT or CI_JOB_TOKEN) for accessing remote state&quot;<br>  type        = string<br>  sensitive   = true<br>}</pre><pre># data.tf<br>data &quot;terraform_remote_state&quot; &quot;network&quot; {<br>  backend = &quot;http&quot;<br>  config = {<br>    address      = var.network_state_address # e.g., &quot;https://gitlab.com/api/v4/projects/YOUR_NET_PROJECT_ID/terraform/state/network&quot;<br>    username     = var.gitlab_api_user     # &quot;gitlab-ci-token&quot; if in CI, else your username<br>    password     = var.gitlab_api_token    # ${CI_JOB_TOKEN} if in CI, else your PAT<br>    lock_method  = &quot;POST&quot;<br>    unlock_method= &quot;DELETE&quot;<br>    retry_wait_min = 5<br>  }<br>}<br># main.tf<br>resource &quot;aws_instance&quot; &quot;app_server&quot; {<br>  # ... other configurations ...<br>  subnet_id = data.terraform_remote_state.network.outputs.app_subnet_id<br>}</pre><p>You would pass the variable values via .tfvars files (kept out of VCS if containing PATs) or GitLab CI/CD variables.</p><h3>Building GitLab Pipelines for Terraform, with OIDC</h3><p><strong>GitLab CI/CD</strong> is where the real power of automating your <strong>Terraform operations</strong> (1) shines. A well-structured <strong>CD pipeline</strong> (1) can lint, validate, plan, and apply your infrastructure changes securely and reliably.</p><h3>Core Pipeline Structure</h3><p>A typical GitLab pipeline (.gitlab-ci.yml) for Terraform includes several stages:</p><pre>stages:<br>  - validate<br>  - build # Often called &#39;plan&#39;<br>  - deploy<br>  - cleanup # Optional, for destroy operations</pre><pre>variables:<br>  TF_ROOT: ${CI_PROJECT_DIR}/terraform # Directory where Terraform files are<br>  TF_STATE_NAME: &quot;default&quot;<br>  TF_ADDRESS: &quot;${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}&quot;<br>  # For OIDC (example for AWS)<br>  # AWS_ROLE_ARN: &quot;arn:aws:iam::123456789012:role/GitLabCIRoleForTerraform&quot;<br>  # AWS_WEB_IDENTITY_TOKEN_FILE: &quot;${CI_PROJECT_DIR}/web_identity_token&quot; # For newer Terraform AWS provider versions<br>default:<br>  image:<br>    name: hashicorp/terraform:latest # Use a specific version in production<br>    entrypoint: [&quot;&quot;]<br>  before_script:<br>    - cd ${TF_ROOT}<br>    # OIDC Token setup for AWS (example, adjust for your cloud)<br>    # - echo &quot;${CI_JOB_JWT_V2}&quot; &gt; ${AWS_WEB_IDENTITY_TOKEN_FILE}<br>    # - export AWS_ROLE_SESSION_NAME=&quot;GitLabCI-${CI_PROJECT_ID}-${CI_PIPELINE_ID}&quot;<br>    # For GitLab HTTP Backend<br>    - export GITLAB_TF_ADDRESS=&quot;-backend-config=address=${TF_ADDRESS}&quot;<br>    - export GITLAB_TF_LOCK_ADDRESS=&quot;-backend-config=lock_address=${TF_ADDRESS}/lock&quot;<br>    - export GITLAB_TF_UNLOCK_ADDRESS=&quot;-backend-config=unlock_address=${TF_ADDRESS}/lock&quot;<br>    - export GITLAB_TF_USERNAME=&quot;-backend-config=username=gitlab-ci-token&quot;<br>    - export GITLAB_TF_PASSWORD=&quot;-backend-config=password=${CI_JOB_TOKEN}&quot;<br>    - export GITLAB_TF_LOCK_METHOD=&quot;-backend-config=lock_method=POST&quot;<br>    - export GITLAB_TF_UNLOCK_METHOD=&quot;-backend-config=unlock_method=DELETE&quot;<br>    - export GITLAB_TF_RETRY=&quot;-backend-config=retry_wait_min=5&quot;<br>    - terraform --version<br>    - terraform init -input=false ${GITLAB_TF_ADDRESS} ${GITLAB_TF_LOCK_ADDRESS} ${GITLAB_TF_UNLOCK_ADDRESS} ${GITLAB_TF_USERNAME} ${GITLAB_TF_PASSWORD} ${GITLAB_TF_LOCK_METHOD} ${GITLAB_TF_UNLOCK_METHOD} ${GITLAB_TF_RETRY}<br>validate:<br>  stage: validate<br>  script:<br>    - terraform validate -json<br>plan:<br>  stage: build # &#39;build&#39; stage often used for plan generation<br>  script:<br>    - terraform plan -out=tfplan.cache -input=false<br>    # Optionally, convert plan to JSON for further processing or MR comments<br>    - terraform show -json tfplan.cache &gt; tfplan.json<br>  artifacts:<br>    name: &quot;plan_artifacts_${CI_COMMIT_REF_SLUG}&quot;<br>    paths:<br>      - ${TF_ROOT}/tfplan.cache<br>      - ${TF_ROOT}/tfplan.json<br>    # By default, artifacts are public. Secure them!<br>    public: false # Restricts access to project members (Reporter+)<br>    # For more granular control (GitLab Premium+):<br>    # access: developer # Or maintainer<br>    expire_in: 1 week<br>apply:<br>  stage: deploy<br>  script:<br>    - terraform apply -input=false tfplan.cache<br>  dependencies:<br>    - plan # Ensures &#39;plan&#39; job artifacts are available<br>  rules:<br>    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Apply only on default branch<br>      when: manual # Manual trigger for production changes is a good practice<br>    - if: $CI_COMMIT_BRANCH =~ /^env\// # Example: auto-apply for &#39;env/*&#39; branches<br>      when: on_success<br>destroy: # Optional<br>  stage: cleanup<br>  script:<br>    - terraform destroy -auto-approve<br>  rules:<br>    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH &amp;&amp; $DESTROY_INFRA == &quot;true&quot; # Require explicit variable<br>      when: manual</pre><h3>Authenticating with OIDC</h3><p>Hardcoding static cloud provider access tokens or access keys in CI/CD variables is a security risk. OpenID Connect (OIDC) allows GitLab CI jobs to obtain short-lived, temporary credentials from cloud providers like AWS, GCP, and Azure, eliminating the need for long-lived sensitive data.</p><h3>How OIDC Works with GitLab CI</h3><ol><li><strong>GitLab CI Generates a JWT:</strong> For jobs configured to use OIDC, GitLab generates a JSON Web Token (CI_JOB_JWT_V2 or other specific ID tokens like GITLAB_OIDC_TOKEN).</li><li><strong>Cloud Provider Setup:</strong></li></ol><ul><li>Configure your cloud provider (e.g., AWS IAM, GCP Workload Identity Federation, Azure AD Federated Credentials) to trust GitLab as an OIDC identity provider.</li><li>Create an IAM Role (or equivalent) in your cloud provider that Terraform will assume.</li><li>Define a trust policy for this role that specifies conditions based on the JWT claims (e.g., GitLab project path, branch, tag) to enforce the principle of least privilege. This means a CI job from project_A/branch_dev can only assume roles meant for that context.</li></ul><ol><li><strong>Terraform Assumes Role:</strong> The Terraform provider in your CI job uses the JWT to request temporary credentials from the cloud provider by assuming the configured role.</li></ol><p>Example: OIDC for AWS in .gitlab-ci.yml and Terraform:</p><pre>variables:<br>  AWS_ROLE_ARN: &quot;arn:aws:iam::YOUR_ACCOUNT_ID:role/YourGitLabCIRole&quot;<br>  AWS_WEB_IDENTITY_TOKEN_FILE: &quot;${CI_PROJECT_DIR}/aws_oidc_token.json&quot; # Standard practice<br>  AWS_ROLE_SESSION_NAME: &quot;GitLabCI-${CI_JOB_ID}&quot;</pre><pre>default:<br>  id_tokens: # Request an OIDC token<br>    GITLAB_OIDC_TOKEN:<br>      aud: # Optional: specify audience if required by your IdP config in AWS<br>        - sts.amazonaws.com <br>        # - https://gitlab.com (if you configured GitLab instance as audience)<br>  before_script:<br>    - echo &quot;${GITLAB_OIDC_TOKEN}&quot; &gt; ${AWS_WEB_IDENTITY_TOKEN_FILE}<br>    # Terraform AWS provider will automatically pick up AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE</pre><p>No explicit provider configuration for credentials is needed if AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE are set as environment variables. The AWS provider SDK will handle the token exchange.</p><pre>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>  # No explicit access_key or secret_key needed!<br>}</pre><p>This significantly improves your security posture by avoiding static credentials for your AWS accounts or other cloud services.</p><h3>Managing Plan Artifacts</h3><p>The terraform plan -out=plan.cache command saves the execution plan. This plan file is a critical job artifact.</p><p><strong>Security Risks:</strong> Plan files can contain sensitive data from your configuration or existing state. By default, in GitLab, anyone with Guest role access to a public/internal project can download artifacts.</p><p><strong>Securing Plan Artifacts:</strong></p><ul><li>artifacts:public: false: In your .gitlab-ci.yml, set this on your plan artifact definition. This restricts download access to project members with at least Reporter access.</li><li><strong>artifacts:access: developer / </strong><strong>maintainer</strong>: For GitLab Premium/Ultimate, you can use this for more granular control.</li><li>Project Visibility: Keep projects with sensitive IaC private.</li><li>Disable Public Pipelines: If your project is public, restrict pipeline visibility.</li><li>Encryption (Advanced): For extremely sensitive data, consider encrypting the plan file itself using tools like gpg within your CI job before declaring it as an artifact, and decrypting it in the apply job. This adds complexity.</li></ul><h3>Handling Multiple Environments</h3><p>Managing different environments is crucial. Two common approaches:</p><p><strong>Terraform Workspaces:</strong></p><ul><li>Workspaces allow you to use the same Terraform code to manage multiple distinct sets of infrastructure resources, each with its own state file.</li><li>In GitLab CI, you can select a workspace using terraform workspace select &lt;name&gt; before running plan or apply.</li><li>The workspace name can be tied to the Git branch or a CI variable.</li><li>Use Case: Best when environments are very similar in configuration, differing mainly by variables (e.g., instance sizes, counts).</li></ul><pre>variables:<br>  TF_WORKSPACE: &quot;${CI_COMMIT_REF_NAME}&quot; # Use branch name as workspace</pre><pre>script:<br>  - terraform workspace select ${TF_WORKSPACE} || terraform workspace new ${TF_WORKSPACE}<br>  - terraform plan -out=tfplan.cache</pre><p><strong>Directory-Based Structure:</strong></p><ul><li>Create separate directories for each environment (e.g., environments/dev, environments/staging, environments/prod).</li><li>Each directory can have its own main.tf, variables.tf, and backend configuration (though ideally, the backend config points to different state names/paths within the same GitLab HTTP backend).</li><li>This allows for more significant differences in configuration between environments.</li><li>Your CI pipeline would cd into the appropriate directory based on the branch or target environment.</li><li><strong>Use Case:</strong> When environments have substantially different resource configurations or require different provider versions/configurations. This is a common way to achieve split state.</li></ul><h3>Provider Plugin Management</h3><p><strong>Caching:</strong> Terraform downloads provider plugins during terraform init. To speed up CI jobs:</p><ul><li>Set the TF_PLUGIN_CACHE_DIR environment variable in your .gitlab-ci.yml (e.g., TF_PLUGIN_CACHE_DIR: &quot;${CI_PROJECT_DIR}/.terraform-plugin-cache&quot;).</li><li>Configure GitLab CI caching for this directory, keyed by the .terraform.lock.hcl file:</li></ul><pre>cache:<br>  key:<br>    files:<br>      - ${TF_ROOT}/.terraform.lock.hcl<br>  paths:<br>    - ${TF_ROOT}/.terraform-plugin-cache<br>  policy: pull-push # Or pull for non-default branches</pre><p><strong>Custom Providers:</strong> For private or custom-built providers not in public registries, you can use Terraform’s filesystem mirror capabilities by placing the provider binary in a known location (e.g., ~/.terraform.d/plugins or a project subdirectory) and configuring provider_installation in a CLI configuration file or using the TF_CLI_PLUGIN_PATH environment variable.</p><h3>Integrating with Merge Requests</h3><ul><li>Configure CI jobs to run terraform plan automatically when a merge request is created or updated.</li><li>Use tools or scripts (e.g., gitlab-terraform helpers if still applicable, or custom scripts with jq and curl) to parse the JSON plan output and post a summary as a comment on the merge request. This allows reviewers to see the proposed changes directly in the MR.</li></ul><h3>Troubleshooting CI Jobs</h3><ul><li>Examine job logs in the GitLab UI carefully for error messages from Terraform or the runner.</li><li>Enable CI/CD debug logging in GitLab for more verbose output.</li><li>Common issues include authentication problems (OIDC setup, token permissions), incorrect paths in TF_ROOT, state locking conflicts (rare with GitLab backend if CI jobs are serialized correctly for applies), or syntax errors in Terraform code.</li></ul><p>Example: Provisioning a Virtual Machine with GitLab CI and OIDC (AWS EC2)</p><pre>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}</pre><pre>resource &quot;aws_instance&quot; &quot;example_vm&quot; {<br>  ami           = &quot;ami-0c55b31ad2c675a0a&quot; # Example: Amazon Linux 2 AMI (HVM)<br>  instance_type = &quot;t2.micro&quot;</pre><pre>  tags = {<br>    Name        = &quot;GitLab-CI-VM-Example&quot;<br>    Environment = &quot;Demo&quot;<br>  }<br>}</pre><pre>output &quot;instance_id&quot; {<br>  value = aws_instance.example_vm.id<br>}<br>output &quot;instance_public_ip&quot; {<br>  value = aws_instance.example_vm.public_ip<br>}</pre><pre>stages:<br>  - validate<br>  - plan<br>  - deploy</pre><pre>variables:<br>  TF_ROOT: ${CI_PROJECT_DIR}/terraform<br>  TF_STATE_NAME: &quot;vm-example&quot;<br>  TF_ADDRESS: &quot;${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}&quot;<br>  AWS_ROLE_ARN: &quot;arn:aws:iam::YOUR_ACCOUNT_ID:role/YourGitLabCIRoleForVMs&quot; # Set this in GitLab CI/CD variables<br>  AWS_WEB_IDENTITY_TOKEN_FILE: &quot;${CI_PROJECT_DIR}/aws_oidc_token.json&quot;<br>  AWS_DEFAULT_REGION: &quot;us-east-1&quot; # Or your desired region<br>  AWS_ROLE_SESSION_NAME: &quot;GitLabCI-VM-${CI_JOB_ID}&quot;</pre><pre>default:<br>  image: hashicorp/terraform:latest<br>  entrypoint: [&quot;&quot;]<br>  before_script:<br>    - cd ${TF_ROOT}<br>    - echo &quot;${CI_JOB_JWT_V2}&quot; &gt; ${AWS_WEB_IDENTITY_TOKEN_FILE} # Using CI_JOB_JWT_V2 for AWS<br>    - export GITLAB_TF_ADDRESS=&quot;-backend-config=address=${TF_ADDRESS}&quot;<br>    - export GITLAB_TF_LOCK_ADDRESS=&quot;-backend-config=lock_address=${TF_ADDRESS}/lock&quot;<br>    # ... other GITLAB_TF_ backend configs as shown previously ...<br>    - terraform init -input=false ${GITLAB_TF_ADDRESS} ${GITLAB_TF_LOCK_ADDRESS} # ... etc.</pre><pre>validate_vm:<br>  stage: validate<br>  script:<br>    - terraform validate</pre><pre>plan_vm:<br>  stage: plan<br>  script:<br>    - terraform plan -out=tfplan.cache<br>  artifacts:<br>    paths:<br>      - ${TF_ROOT}/tfplan.cache<br>    public: false</pre><pre>apply_vm:<br>  stage: deploy<br>  script:<br>    - terraform apply -input=false tfplan.cache<br>  dependencies:<br>    - plan_vm<br>  rules:<br>    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH<br>      when: manual</pre><p><em>(Ensure your AWS IAM Role </em><em>YourGitLabCIRoleForVMs has permissions to create EC2 instances and is configured to trust JWTs from your GitLab project/branch as per OIDC setup).</em></p><h3>Using GitLab’s Terraform Module Registry</h3><p>Terraform modules are essential for creating reusable, maintainable, and versioned components of your infrastructure. GitLab provides its own private Terraform Registry to host and share your custom modules within your organization.</p><h3>Publishing Modules</h3><p><strong>Via GitLab CI/CD (Recommended):</strong></p><p>Structure your module in a dedicated GitLab project.</p><p>Use a .gitlab-ci.yml file that triggers on Git tags (which should follow semantic versioning, e.g., v1.0.1).</p><p>The CI job will package your module (usually a .tgz archive) and use GitLab&#39;s API (with CI_JOB_TOKEN) to publish it to the registry.</p><p>GitLab provides CI/CD templates for this (e.g., Terraform-Module.gitlab-ci.yml), though with templates being deprecated, you might adapt this logic or use newer component-based approaches if available.</p><p><strong>Via API Manually:</strong></p><p>You can also use curl and the Packages API with a GitLab Personal Access Token, Project Access Token, or Deploy Token (with read_package_registry and write_package_registry scopes) to upload your packaged module.</p><p>Example: Referencing a Module from GitLab Registry in your Terraform code:</p><pre>module &quot;vpc&quot; {<br>  source  = &quot;gitlab.com/your-group/your-vpc-module/aws&quot; # Or gitlab.your-instance.com<br>  version = &quot;1.0.1&quot;</pre><pre>  # Module inputs<br>  vpc_cidr = &quot;10.0.0.0/16&quot;<br>  # ...<br>}</pre><h3>Authentication for Consuming Modules</h3><p>When terraform init runs, it needs to authenticate to your GitLab instance to download private modules.</p><p>Using ~/.terraformrc or terraform.rc: Create this file with credentials:</p><pre>credentials &quot;gitlab.com&quot; { // Or your self-managed instance hostname<br>  token = &quot;&lt;YOUR_GITLAB_PERSONAL_ACCESS_TOKEN_OR_DEPLOY_TOKEN&gt;&quot;<br>}</pre><p>Environment Variables (for CI/CD): Set TF_TOKEN_gitlab_com (replace gitlab_com with your instance, underscores for dots) with a suitable token. CI_JOB_TOKEN can often be used if the job has appropriate permissions.</p><h3>Managing GitLab with the GitLab Terraform Provider</h3><p>Beyond managing external cloud infrastructure, you can use Terraform to manage GitLab itself using the official GitLab Terraform Provider (gitlabhq/gitlab). This is IaC for your DevSecOps platform!</p><h3>Common Use Cases</h3><ul><li>Managing GitLab projects: create, configure settings (visibility, merge methods, CI/CD settings), project variables.</li><li>Managing GitLab groups and memberships.</li><li>Configuring users and their permissions.</li><li>Setting up CI/CD variables at project or group levels.</li><li>Managing repository files, branches, and branch protections.</li><li>Configuring deploy keys and deploy tokens.</li><li>Managing GitLab Runners (registering, enabling for projects).</li></ul><h3>Example: Creating a GitLab Project</h3><pre>provider &quot;gitlab&quot; {<br>  # token = var.gitlab_admin_token # Can be set via env var GITLAB_TOKEN<br>}</pre><pre>resource &quot;gitlab_project&quot; &quot;example_app&quot; {<br>  name                   = &quot;My Example App&quot;<br>  description            = &quot;An example application project managed by Terraform.&quot;<br>  visibility_level       = &quot;private&quot;<br>  default_branch         = &quot;main&quot;<br>  issues_enabled         = true<br>  merge_requests_enabled = true<br>  wiki_enabled           = false<br>  snippets_enabled       = false</pre><pre>  container_registry_enabled = true # Requires GitLab 13.6+ for provider to set<br>}</pre><pre>resource &quot;gitlab_project_variable&quot; &quot;app_env&quot; {<br>  project    = gitlab_project.example_app.id<br>  key        = &quot;APP_ENVIRONMENT&quot;<br>  value      = &quot;development&quot;<br>  protected  = false<br>  masked     = false<br>  environment_scope = &quot;*&quot; # All environments<br>}</pre><p>For an exhaustive list of resources and data sources, refer to the <a href="https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs">official GitLab Provider documentation on the Terraform Registry</a>.</p><h3>7 Security Best Practices for Terraform and GitLab</h3><p>Security should be paramount throughout your IaC lifecycle.</p><ol><li><strong>Secure State:</strong> Use GitLab-Managed Terraform State (HTTP backend) for its built-in encryption and access controls, and make sure you understand the role of db_key_base for self-managed instances.</li><li><strong>OIDC for Cloud Credentials:</strong> Prioritize OIDC over static cloud access tokens in GitLab CI. This is a cornerstone of modern, secure CI/CD.</li><li><strong>Secure Plan Artifacts:</strong> Control access to job artifacts (plan file) using artifacts:public: false or artifacts:access. Be mindful of project visibility settings and their impact on artifact and code visibility.</li><li><strong>Manage Sensitive Data:</strong> Use GitLab CI/CD variables (masked and protected) for secrets needed by Terraform that aren’t cloud credentials handled by OIDC. For more complex secret management, consider integrating HashiCorp Vault (though this adds another layer of infrastructure).</li><li><strong>Principle of Least Privilege (PoLP):</strong> Grant only necessary permissions to CI jobs via OIDC roles. Assign GitLab users the minimum required roles (developer role, maintainer role).</li><li><strong>Code Scanning (SAST for IaC):</strong> Integrate static analysis security testing (SAST) tools like tfsec, checkov, or GitLab&#39;s own SAST capabilities into your GitLab CI pipeline to catch misconfigurations and security vulnerabilities in your Terraform code before they reach production.</li><li><strong>Regular Review:</strong> Periodically review GitLab user permissions and CI/CD pipeline configurations. Keep Terraform, providers, and GitLab versions up-to-date.</li></ol><h3>Conclusion</h3><p>Combining Terraform’s powerful infrastructure provisioning capabilities with GitLab’s comprehensive DevSecOps platform creates a robust, secure, and efficient workflow for managing the entire lifecycle of your state of your infrastructure.</p><p>By leveraging GitLab for version control, adopting its secure HTTP backend for Terraform state files, building sophisticated GitLab CI/CD pipelines with OIDC, utilizing the private Terraform Module Registry, and even managing GitLab itself with the GitLab Terraform Provider, you can significantly enhance collaboration, automation, and security.</p><p>Embrace these best practices and GitLab Terraform integration features to ensure your team can confidently and rapidly evolve your cloud infrastructure, focusing on delivering value rather than wrestling with manual processes or security concerns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*EyTzOVDBS7qAorWm7Ky2BQ.png" /><figcaption>Post brought to you by Scalr.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca31a3962f44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guide to Terraform Cloud Alternatives]]></title>
            <link>https://medium.com/scalr/guide-to-terraform-cloud-alternatives-e49358140024?source=rss-a6d3183ee598------2</link>
            <guid isPermaLink="false">https://medium.com/p/e49358140024</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[terraform-cloud]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Scalr]]></dc:creator>
            <pubDate>Mon, 23 Jun 2025 13:27:28 GMT</pubDate>
            <atom:updated>2025-06-23T13:27:28.980Z</atom:updated>
            <content:encoded><![CDATA[<p>This guide covers the top alternatives to Terraform Cloud, pricing, features, and migration paths to help you make an informed renewal decision.</p><p>✅ Last Reviewed by <a href="http://scalr.com/learning-center/author/ryan-fee/">Ryan Fee</a> on June 12, 2025</p><h3>The Infrastructure as Code Landscape</h3><p>For teams managing infrastructure with Terraform, Terraform Cloud (TFC) has long been the default platform for collaboration and automation. However, two significant events have prompted many organizations to re-evaluate their subscriptions:</p><ul><li><strong>The RUM Pricing Model:</strong> TFC’s pricing is based on Resources Under Management (RUM). As infrastructure grows, this model can lead to unpredictable and rapidly escalating costs that are difficult to forecast.</li><li><strong>The BSL License Change:</strong> In August 2023, HashiCorp switched Terraform from a permissive open-source license (MPL 2.0) to the Business Source License (BSL). The BSL restricts using Terraform to build products that compete with HashiCorp’s offerings, raising community concerns about vendor lock-in and the future of open-source IaC.</li></ul><p>These factors, combined with a maturing market, have made exploring alternatives more compelling than ever. This guide provides a matter-of-fact overview of the leading contenders.</p><h3>OpenTofu’s Growing Popularity</h3><p>In response to the BSL license change, the Linux Foundation adopted <strong>OpenTofu</strong>, an open-source fork of the last MPL-licensed version of Terraform. It is a community-driven, drop-in replacement.</p><p>This is a critical development because it decouples the HCL syntax you write from HashiCorp’s commercial offerings. You can now use a genuinely open-source tool on a superior management platform. All major alternatives, including Spacelift, env0, and Scalr, immediately added support for OpenTofu.</p><h3>Summary of the Contenders</h3><p>This section provides a brief overview of the main alternatives. A detailed feature comparison follows in Section 4.</p><h4>Atlantis</h4><p>Atlantis is the leading open-source, self-hosted option. It works by listening for comments in pull requests, allowing you to run plan and apply directly from your Git provider. It&#39;s free but requires you to manage the infrastructure and lacks the advanced features of managed platforms.</p><h4>Scalr</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*EyTzOVDBS7qAorWm7Ky2BQ.png" /></figure><p>Scalr is positioned as the most direct, frictionless alternative to Terraform Cloud, addressing TFC’s major pain points without forcing a significant change in workflow. It is designed as a drop-in replacement with a focus on simple, predictable pricing and backend flexibility.</p><h4>env0</h4><p>env0’s primary focus is on enabling developer self-service while providing robust guardrails and, crucially, cost visibility. It allows platform teams to create templates for developers and can show the estimated cost of infrastructure changes directly in a pull request. For organizations where FinOps and budget control are major drivers, its features are highly attractive.</p><h4>Pulumi</h4><p>Pulumi represents a paradigm shift. It dispenses with HCL entirely, allowing you to define infrastructure using languages like Python, TypeScript, Go, or C#. It’s less an alternative to TFC and more an alternative to Terraform itself.</p><h4>Spacelift</h4><p>Spacelift treats IaC as a CI/CD problem, offering a powerful and highly flexible platform. Its native support for Open Policy Agent (OPA) and its ability to manage multiple IaC tools make it a strong choice for organizations with complex, heterogeneous environments.</p><h3>Strengths of Each</h3><h4>How Each Uses AI</h4><p>AI is emerging as a key feature to reduce toil and improve productivity. Platforms are integrating AI primarily to assist with code generation and error resolution.</p><ul><li><strong>Scalr:</strong> Similar to Spacelift, <strong>Scalr AI</strong> assists with troubleshooting. It uses the output from a failed run to provide context and recommend solutions, aiming to empower developers to solve their own issues without escalating to a platform team. The feature is disabled by default and included in the standard subscription.</li><li><strong>env0:</strong> AI features are less direct within env0 itself. The focus is on integrating with a broader ecosystem. For example, it integrates with Firefly, which has its own AI assistant for cloud asset management and IaC codification.</li><li><strong>Pulumi:</strong> A clear leader in AI integration, <strong>Pulumi AI</strong> allows you to generate complete IaC programs from natural language prompts (e.g., “create a VPC with three subnets and a load balancer”). It supports all of Pulumi’s languages and helps iterate on and debug code, significantly lowering the barrier to entry.</li><li><strong>Spacelift:</strong> Their <strong>Saturnhead AI</strong> feature focuses on diagnostics. When a run fails, it analyzes the logs and explains the failure in plain English, suggesting potential fixes. This reduces the time engineers spend deciphering complex error messages.</li></ul><h4>Pricing Models, Compared</h4><p>Pricing models are a major differentiator, moving away from TFC’s often-unpredictable RUM model.</p><h4>Concurrency Limits</h4><p>Concurrency — the ability to run multiple jobs at once — is critical for team productivity. Bottlenecks here can bring development to a halt.</p><ul><li><strong>Terraform Cloud:</strong> This is a major point of friction. Concurrency is strictly limited: <strong>1</strong> on the Free tier, <strong>3</strong> on the Standard tier, and only <strong>10</strong> on the expensive Plus tier. This can severely throttle teams during busy periods or incidents.</li><li><strong>env0:</strong> A key selling point is <strong>unlimited concurrent runs</strong> on all paid plans, completely eliminating this bottleneck.</li><li><strong>Spacelift:</strong> Concurrency is the basis of its pricing model. You pay for a certain number of concurrent “workers.” If you need more parallelism, you pay for more workers.</li><li><strong>Scalr:</strong> Offers a flexible and scalable model. Paid plans include <strong>5 concurrent runs</strong> on Scalr’s shared runners. However, you can deploy self-hosted agents, and <strong>each agent’s concurrency is independent of the platform limit</strong>. A single self-hosted agent can run up to 5 concurrent jobs. By deploying more agents, you can scale concurrency massively at no extra cost from Scalr.</li><li><strong>Pulumi:</strong> Tiers the limit. <strong>1</strong> concurrent deployment on the Free plan, <strong>5</strong> on Team, and <strong>25</strong> on Enterprise.</li></ul><h3>Migration Effort</h3><p>Vendors understand that migration risk is a major hurdle and have created tools to ease the process. The focus is always on the safe transfer of the Terraform state.</p><ul><li><strong>Scalr &amp; Spacelift:</strong> Both offer automated scripts (Python-based for Spacelift) to bulk-migrate workspaces, variables, and state files from TFC. Scalr also highlights the simple manual CLI-based process (terraform state pull/push) and offers free migration periods to prevent double-billing.</li><li><strong>env0:</strong> Supports the standard terraform init -migrate-state command and provides guides on reconfiguring TFC workspaces for local execution to facilitate the move.</li><li><strong>Pulumi:</strong> Migration is a two-step process. First, pulumi convert --from terraform translates HCL code into a language like Python or TypeScript. Second, Pulumi can import the state from your old .tfstate file. This is more involved as it requires a language shift.</li></ul><h3>Conclusion</h3><p>Your TFC renewal date is an opportunity to choose a platform that better fits your team’s workflow and budget. The market is now mature enough to offer real choice.</p><ul><li>For <strong>complex, multi-tool environments</strong>, Spacelift is a strong contender.</li><li>For teams focused on <strong>developer self-service and cloud cost control</strong>, env0 is purpose-built.</li><li>For teams that are <strong>happy with the Terraform workflow but want lower costs, predictable pricing, and less vendor lock-in</strong>, Scalr presents the path of least resistance for the most value. It directly solves the primary issues driving users away from TFC — cost and concurrency — with minimal disruption.</li></ul><p>Do not simply renew. Conduct a proof-of-concept. The results will likely speak for themselves.</p><h3>FAQ Part 1</h3><h3>What is the alternative to Terraform Cloud?</h3><p>There are numerous alternatives to Terraform Cloud, which fall into two main categories. The first is commercial Infrastructure as Code (IaC) management platforms that offer more features and flexibility. Leading alternatives like <strong>Spacelift</strong>, <strong>env0</strong>, and <strong>Scalr</strong> provide unified workflows for multiple IaC tools (not just Terraform, but also OpenTofu, Pulumi, and CloudFormation), more advanced policy-as-code using Open Policy Agent (OPA), and more predictable pricing models compared to Terraform Cloud’s resource-based pricing. Tools like <strong>Terrateam</strong> offer a lightweight, GitOps-native experience directly within GitHub.</p><p>The second category consists of open-source and self-hosted solutions. The most popular is <strong>Atlantis</strong>, which automates Terraform and OpenTofu through pull request comments, providing a collaborative workflow within your Git provider. A growing trend is to use general-purpose CI/CD platforms like <strong>GitHub Actions</strong> or <strong>GitLab CI</strong>. While this unifies pipelines, it requires manually handling complexities like state locking and plan readability. Emerging tools like Digger act as an orchestration layer within these CI/CD platforms to bridge that gap.</p><h3>What will replace Terraform?</h3><p>There will not be a single, universal replacement for Terraform. Instead, the market is shifting to a multi-paradigm future where the “best” tool depends on the organization’s specific needs. The most direct successor is <strong>OpenTofu</strong>, an open-source, drop-in replacement that was forked from Terraform after its license change. It’s governed by the Linux Foundation and is being adopted by major enterprises like Fidelity, making it the designated successor for teams wanting to continue using HCL.</p><p>Beyond a direct fork, Terraform is being replaced by different <em>types</em> of tools. Developer-centric teams are moving to <strong>Pulumi</strong> or <strong>AWS CDK</strong>, which allow infrastructure to be defined in general-purpose programming languages like Python or TypeScript. Organizations heavily invested in Kubernetes are adopting <strong>Crossplane</strong>, which turns Kubernetes into a universal control plane for all infrastructure. Ultimately, the long-term successor to the manual Terraform workflow is the <strong>Internal Developer Platform (IDP)</strong>, which abstracts the underlying IaC tool away from developers entirely.</p><h3>What is the AWS equivalent of Terraform?</h3><p>AWS offers two main equivalents to Terraform, each representing a different approach. The direct, declarative equivalent is <strong>AWS CloudFormation</strong>. It is a managed AWS service that allows you to define AWS infrastructure using YAML or JSON templates. Its primary advantages are its deep integration with the AWS ecosystem, automatic state management (which removes operational overhead), and day-one support for all new AWS services and features.</p><p>A more modern, developer-centric equivalent is the <strong>AWS Cloud Development Kit (CDK)</strong>. The CDK allows developers to define cloud infrastructure using familiar programming languages like TypeScript, Python, and Go. This code is then “synthesized” into a standard CloudFormation template for deployment. The CDK is favored for its superior developer experience and powerful abstractions (“Constructs”) that can create complex architectures with minimal code, making it an excellent choice for application development teams managing their own infrastructure.</p><h3>Which is better Terraform or CloudFormation?</h3><p>Neither tool is universally “better”; the choice represents a strategic trade-off. <strong>AWS CloudFormation</strong> is the better choice for organizations that are fully committed to the AWS ecosystem. Its key benefits are managed state, which simplifies operations, deep integration with AWS services, guaranteed day-one support for new features, and the ability to leverage official AWS Support for troubleshooting. This makes it a reliable and robust choice for AWS-only environments.</p><p><strong>Terraform</strong> is better for organizations with a multi-cloud strategy or those who prioritize avoiding vendor lock-in. Its main strength is providing a single, cloud-agnostic workflow and language (HCL) to manage resources across AWS, Azure, GCP, and more. While this requires the user to manage the state file and its locking mechanism, it offers portability and benefits from a vast and diverse open-source community, making it the superior choice for heterogeneous environments.</p><h3>What is the successor of Terraform?</h3><p>The most direct, community-driven successor to Terraform is <strong>OpenTofu</strong>. Created as an open-source fork after HashiCorp changed Terraform’s license, OpenTofu is designed as a drop-in replacement, ensuring that existing Terraform code, state, and providers work without modification. It is governed by the Linux Foundation to ensure it remains truly open-source and is rapidly gaining adoption from major companies, making it the official heir for users committed to the HCL language.</p><p>However, the broader “successor” is not a single tool but a shift towards a <strong>multi-paradigm approach</strong> to IaC. For developer-led teams, the successor is often <strong>Pulumi</strong> or <strong>AWS CDK</strong>, which use general-purpose programming languages. For Kubernetes-native shops, the successor is <strong>Crossplane</strong>. The ultimate successor to the manual IaC workflow itself is the concept of the <strong>Internal Developer Platform (IDP)</strong>, where a platform team provides infrastructure as a self-service product, hiding the complexity of the underlying tool.</p><h3>Is AWS CDK better than Terraform?</h3><p>Whether AWS CDK is “better” than Terraform depends entirely on the team and the use case. The <strong>AWS CDK</strong> is generally considered better for application development teams who are building and managing their own infrastructure on AWS. Its primary strength is its developer-centric experience (DevEx), allowing developers to use familiar programming languages (like TypeScript or Python), IDEs, and testing tools. Its high-level abstractions, called Constructs, dramatically improve productivity by reducing boilerplate code.</p><p>On the other hand, <strong>Terraform</strong> is better for central operations or platform teams, especially those managing multi-cloud or hybrid-cloud environments. Its declarative, cloud-agnostic nature provides a consistent workflow for managing resources across many different providers, which is something the AWS-only CDK cannot do. Therefore, the choice is between CDK’s superior developer experience within a single cloud and Terraform’s unparalleled multi-cloud provider ecosystem.</p><h3>FAQ Part 2</h3><p>This table summarizes the key characteristics of various Terraform alternatives, evaluating their suitability based on the detailed research analysis.</p><h4>Is there anything better than Terraform?</h4><p>There is no single tool that is objectively “better,” as the best choice depends on the specific context and goals of your organization.</p><ul><li><strong>For developer-centric teams, Pulumi is often better.</strong> It allows developers to use familiar programming languages (like Python or TypeScript), enabling them to apply robust software engineering practices like testing, abstraction, and advanced logic to their infrastructure.</li><li><strong>For Kubernetes-native environments, Crossplane is better.</strong> It transforms your Kubernetes cluster into a universal control plane, allowing you to manage cloud infrastructure using the same GitOps workflows you use for your applications.</li><li><strong>For single-cloud simplicity, AWS CloudFormation or Azure Bicep are better.</strong> They offer seamless integration, day-one support for new services, and managed state, which simplifies operations for teams fully committed to one cloud.</li><li><strong>For multi-cloud operations, Terraform/OpenTofu remains the best-in-class solution.</strong> Its mature, extensive provider ecosystem and simple declarative language (HCL) make it the most powerful and flexible tool for managing diverse infrastructure across multiple providers.</li></ul><h4>Who competes with Terraform?</h4><p>Terraform faces competition on several fronts:</p><ul><li><strong>Direct Engine Competitors:</strong> These are tools that also provision infrastructure but use a different approach. The main competitors are <strong>Pulumi</strong>, <strong>Crossplane</strong>, and native cloud tools like <strong>AWS CloudFormation</strong> and <strong>Azure Bicep</strong>.</li><li><strong>Open Source Successor:</strong> <strong>OpenTofu</strong> is a direct fork and community-governed successor that competes for users who prioritize a truly open-source license and community-driven development.</li><li><strong>Management Platform Competitors (for Terraform Cloud):</strong> These platforms don’t replace the Terraform engine but compete to manage its workflows at scale. The leading competitors are <strong>Spacelift</strong> and <strong>Scalr</strong>. <strong>GitLab</strong> also competes here with its integrated platform features.</li><li><strong>Adjacent Tools (Not Direct Competitors):</strong> <strong>Ansible</strong> and <strong>Salt</strong> are not direct competitors. They are configuration management tools used for tasks <em>after</em> infrastructure has been provisioned by a tool like Terraform.</li></ul><h4>What is the successor of Terraform?</h4><p>For the open-source community, the definitive successor is <strong>OpenTofu</strong>. Following HashiCorp’s switch to the Business Source License (BSL), a coalition of companies and community members created OpenTofu as a truly open-source (MPL 2.0), community-governed fork. It is managed by the Linux Foundation to ensure it remains open forever. As a drop-in replacement for Terraform, it is the intended successor for anyone who values a community-led project and a stable open-source license.</p><h4>Is Ansible better than Terraform?</h4><p>No, because they are designed for completely different jobs. It’s like asking if a hammer is better than a screwdriver.</p><ul><li><strong>Terraform is for provisioning (Day 0).</strong> Its job is to create, modify, and destroy core infrastructure resources like virtual machines, networks, and databases.</li><li><strong>Ansible is for configuration management (Day 1+).</strong> Its job is to install software, manage files, and configure services on infrastructure that already exists.</li></ul><p>They are complementary and are most powerful when used together. The most common pattern is to use <strong>Terraform</strong> to build the servers and then use <strong>Ansible</strong> to configure the software on them.</p><h4>Key Sources</h4><ol><li>Spacelift | Terraform Cloud Alternatives: <a href="https://spacelift.io/blog/terraform-cloud-alternatives">https://spacelift.io/blog/terraform-cloud-alternatives</a></li><li>env0 | Terraform Cloud Alternatives Guide: <a href="https://www.env0.com/blog/terraform-cloud-tfc-alternatives-comprehensive-buyers-guide">https://www.env0.com/blog/terraform-cloud-tfc-alternatives-comprehensive-buyers-guide</a></li><li>Scalr | Selecting a Terraform Cloud Alternative: <a href="https://scalr.com/blog/selecting-a-terraform-cloud-alternative">https://scalr.com/blog/selecting-a-terraform-cloud-alternative</a></li><li>OpenTofu Manifesto: <a href="https://opentofu.org/manifesto/">https://opentofu.org/manifesto/</a></li><li>HashiCorp’s BSL Announcement: <a href="https://www.hashicorp.com/blog/hashicorp-adopts-business-source-license">https://www.hashicorp.com/blog/hashicorp-adopts-business-source-license</a></li><li>Pulumi AI: <a href="https://www.pulumi.com/ai">https://www.pulumi.com/ai</a></li><li>Scalr AI FAQ: <a href="https://docs.scalr.io/docs/scalr-ai-faq">https://docs.scalr.io/docs/scalr-ai-faq</a></li><li>Pulumi Pricing: <a href="https://www.pulumi.com/pricing/">https://www.pulumi.com/pricing/</a></li><li>Scalr on Terraform Concurrency: <a href="https://scalr.com/blog/why-terraform-concurrency-matters">https://scalr.com/blog/why-terraform-concurrency-matters</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e49358140024" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scalr/guide-to-terraform-cloud-alternatives-e49358140024">Guide to Terraform Cloud Alternatives</a> was originally published in <a href="https://medium.com/scalr">scalr</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform Cloud Alternatives: Open Source & Github Action]]></title>
            <link>https://medium.com/@scalr/terraform-cloud-alternatives-open-source-github-action-5bf3268e1fe3?source=rss-a6d3183ee598------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bf3268e1fe3</guid>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Scalr]]></dc:creator>
            <pubDate>Wed, 18 Jun 2025 19:37:45 GMT</pubDate>
            <atom:updated>2025-07-18T10:19:36.853Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KpfSzuM7fksPyXWK.png" /></figure><p>There are 4 kinds of Terraform Cloud alternatives: Open Source, Github Actions, Terraform Atlantis, and drop-in replacements.</p><p>Many folks are looking for a way out of Terraform Cloud. Ever since the BSL license change in August 2023, organizations have been eyeing the exits. The reasons vary: the license, the cost, or simply the desire to run one’s own stack. Whatever the reason, a GitOps workflow for Terraform (or OpenTofu) is a common requirement, often with the goal of avoiding dependency on a single commercial vendor.</p><p>The desired workflow includes plan in PRs, approvals, a clean apply on merge, state locking, and security. This is all achievable without a TFC subscription, but each alternative comes with its own trade-offs.</p><p>The options boil down to four main paths. Some are straightforward, some are complex, and one is simply a maintenance trap.</p><h3>Using GitHub Actions</h3><p>This is a common first idea, easy to get started, but like with Jenkins, eventually gets harder and harder to maintain until a rewrite is required.</p><p>The rationale is to leverage existing CI systems like GitHub Actions. The process begins by setting up an S3 bucket for state, a DynamoDB table for locking, and writing YAML. A first terraform plan workflow looks simple enough:</p><pre># .github/workflows/terraform-plan.yml name: &#39;Terraform Plan&#39; on: pull_request: paths: - &#39;**.tf&#39; - &#39;**.tfvars&#39; jobs: terraform: name: &#39;Terraform Plan&#39; runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Terraform uses: hashicorp/setup-terraform@v3 with: terraform_version: 1.8.0 # Or an OpenTofu version - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: us-east-1 - name: Terraform Init, Validate &amp; Plan run: | terraform init terraform validate terraform plan -no-color</pre><p>For a single developer on a single project, this can be fine. For a week. Then comes the need to post the plan back to the PR, handle plan artifacts so the apply job uses the <em>exact</em> plan that was approved, manage multiple environments, and handle approvals. This often leads to drowning in a sea of unmaintainable YAML, and teams find they&#39;ve spent sprints building a fragile, half-baked version of a tool that already exists.</p><p>This is a maintenance trap. This approach should be avoided unless there is a very specific and compelling reason to choose it.</p><h3>Pull Request Automation with Atlantis</h3><p>Atlantis is the original open-source Terraform automation tool. It’s a self-hosted Go binary that listens for webhooks, runs plan when a PR is opened, and posts the output in a comment. To apply, an authorized user comments atlantis apply. Simple.</p><p>It defined what Terraform GitOps should feel like.</p><p>But its greatest strength-its simplicity-is now its greatest weakness. Atlantis is a single server that does everything. It runs the plans, holds the state locks, and holds cloud credentials. This is not ideal.</p><ul><li><strong>It doesn’t scale.</strong> Every job runs in a single thread. Busy teams will find themselves stuck in a queue.</li><li><strong>It’s a security bottleneck.</strong> That one server holds the keys to the kingdom. If it gets compromised, it’s a major incident.</li><li><strong>It’s stagnant.</strong> Development has slowed considerably. Advanced features like drift detection or modern policy checks are not expected.</li></ul><p><strong>The verdict?</strong> Atlantis is a fantastic tool for small teams or for getting started. But teams often outgrow it.</p><h3>Open Source Alternatives to Terraform Cloud</h3><p>This is where the landscape gets more interesting. A new generation of tools figured out how to fix the Atlantis problem.</p><p>They work by running a lightweight orchestrator that listens for PR comments, just like Atlantis. But instead of running the terraform commands itself, it triggers a job in the <em>user&#39;s existing CI system</em>. The plan runs in a standard GitHub Actions runner.</p><p>Why is this a game-changer?</p><ol><li><strong>Security.</strong> Cloud credentials never leave the CI environment. They are injected into the ephemeral runner, just like any other job. The orchestrator never sees them. The “keys to the kingdom” problem is gone.</li><li><strong>Scalability &amp; Cost.</strong> It scales with the CI provider. If more concurrent runs are needed, more GitHub Actions runners are used. This avoids the cost and maintenance of a separate compute fleet.</li></ol><ul><li><strong>Digger</strong> is the lean, open-source choice here. It focuses on doing one thing well: orchestrating CI. It’s easy to set up, secure by design, and gives the core GitOps workflow with modern features like OPA policy support and drift detection.</li><li><strong>Terrateam</strong> is the more enterprise-focused option. It’s built for platform teams managing many projects, with a more robust, scalable server architecture (it needs a Postgres DB), and native support for other tools like Pulumi and Terragrunt.</li></ul><h3>Drop-in Terraform Cloud Alternative (Scalr)</h3><p>For those who liked the Terraform Cloud experience but want a self-hosted option or a different security model, there’s Scalr.</p><p>Scalr’s main offering is a hybrid SaaS. The control plane-the UI, workspace management, policy logic-is managed SaaS. But the work happens on self-hosted agents that run in the user’s own cloud environment. Credentials and state files stay within the user’s network.</p><p>For organizations seeking the most direct, lowest-friction drop-in replacement for TFC/TFE, this is it. It provides an all-in-one platform experience.</p><h3>Quick Comparison</h3><p><a href="https://scalr.com/learning-center/terraform-cloud-alternatives-open-source-github-action/#quick-comparison">Summary table</a>.</p><h3>The Bottom Line: Which to Use?</h3><p>Here are some general guidelines:</p><ul><li><strong>For a solo dev or a small team just getting started,</strong> <strong>Atlantis</strong> is a solid choice. It’s easy to set up and provides the core workflow. Be aware that a migration may be needed within a year or two as the team scales.</li><li><strong>For a team of any size that already uses GitHub Actions and cares about security,</strong> <strong>Digger</strong> is often the best fit. It has a smart architecture, providing a secure, scalable workflow for almost no operational cost. For most teams, this is the sweet spot.</li><li><strong>For a large platform team managing dozens of projects and multiple IaC tools,</strong> <strong>Terrateam</strong> is worth investigating. It’s built for that kind of complexity, with the HA and RBAC features needed at scale.</li><li><strong>For teams that would be happy with Terraform Cloud,</strong> <strong>Scalr</strong> is the answer. It’s the most direct drop-in replacement and provides a familiar UI-driven experience with a great security model.</li></ul><p>Of course, pricing can be a factor too, so the following post may also help you:</p><p><em>Originally published at </em><a href="https://scalr.com/learning-center/terraform-cloud-alternatives-open-source-github-action/"><em>https://scalr.com</em></a><em> on June 18, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bf3268e1fe3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Azure aztfexport]]></title>
            <link>https://medium.com/@scalr/how-to-use-azure-aztfexport-3a601066ea87?source=rss-a6d3183ee598------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a601066ea87</guid>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Scalr]]></dc:creator>
            <pubDate>Mon, 02 Jun 2025 13:09:27 GMT</pubDate>
            <atom:updated>2025-07-07T12:11:12.468Z</atom:updated>
            <content:encoded><![CDATA[<p>Azure’s aztfexport is a utility for bringing existing Azure resources into Terraform management. Many organizations possess large Azure estates deployed over time using a mix of methods, including the Azure portal, ARM templates, and custom scripts. The task of migrating these &quot;brownfield&quot; environments to a unified Terraform workflow is substantial, requiring significant effort to inventory resources, author HCL, and import state.</p><p>Microsoft’s aztfexport tool is designed to address this initial challenge by automating the export process.</p><h3>What is Aztfexport?</h3><p>Azure Export for Terraform ( aztfexport), formerly known as aztfy, is an open-source command-line tool from Microsoft. Its purpose is to scan existing Azure resources, generate corresponding Terraform HCL code, and create a state file that maps to the live infrastructure. The objective is for an initial terraform plan to show no drift, confirming the exported code matches the existing resource state.</p><p>The tool supports both the azurerm and azapi Terraform providers. Support for the azapi provider is notable as it allows interaction with newer Azure services or preview features that may not yet be fully implemented in the more common azurerm provider.</p><h3>How Aztfexport Works</h3><p>The functionality of aztfexport is delivered by a set of underlying components:</p><ul><li><strong>aztft</strong>: A Go program that maps an Azure resource ID to its corresponding Terraform resource type.</li><li><strong>terraform import</strong>: The standard Terraform command is used to read the resource&#39;s current configuration from Azure and save it into the Terraform state file.</li><li><strong>tfadd</strong>: Another Go component that reads the data from the state file and generates the associated HCL code.</li></ul><p>The tool can be executed in two modes: an interactive mode for selective export and a non-interactive mode suitable for automation.</p><h3>Installation and Usage</h3><p>Prerequisites for using aztfexport include Terraform (v0.12+) and the Azure CLI. Both must be installed and configured.</p><h3>Installation Examples</h3><p>The tool can be installed via common package managers:</p><p><strong>Linux (</strong><strong>apt - Debian/Ubuntu):</strong></p><pre># Import Microsoft GPG key curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc &gt; /dev/null # Add Microsoft repository (example for Ubuntu 20.04) sudo apt-add-repository https://packages.microsoft.com/ubuntu/20.04/prod # Update package list and install aztfexport sudo apt-get update sudo apt-get install aztfexport</pre><p><strong>Linux/macOS (Homebrew):</strong></p><pre>brew install aztfexport</pre><p><strong>Windows (winget):</strong></p><pre>winget install aztfexport</pre><h3>Basic Commands</h3><p>aztfexport can target resources in several ways:</p><p><strong>Exporting with an Azure Resource Graph Query:</strong></p><pre>aztfexport query &quot;resourceGroup =~ &#39;myRG&#39; and type =~ &#39;microsoft.network/virtualnetworks&#39;&quot;</pre><p><strong>Exporting a Resource Group:</strong></p><pre>aztfexport resource-group myRG</pre><p>(The -n flag for non-interactive mode is recommended for large resource groups.)</p><p><strong>Exporting a Single Resource:</strong></p><pre>aztfexport resource /subscriptions/your-sub-id/resourceGroups/myRG/providers/Microsoft.Compute/virtualMachines/myVM</pre><p>The tool generates .tf files, a terraform.tfstate file, and a JSON mapping file ( aztfexportResourceMapping.json) that logs the association between Azure IDs and Terraform resource addresses.</p><h3>Primary Use Cases for Aztfexport</h3><p>The tool provides several practical benefits:</p><ul><li><strong>IaC Adoption Acceleration:</strong> It automates the initial, time-consuming task of importing existing resources and generating baseline HCL code.</li><li><strong>Migration Support:</strong> Exporting configurations provides a detailed snapshot of legacy resources, which can serve as a reference for migrations or re-platforming efforts.</li><li><strong>Configuration Auditing:</strong> The generated HCL acts as a point-in-time documentation of resource configurations, useful for identifying configuration drift.</li><li><strong>Learning Aid:</strong> For those new to Terraform for Azure, exporting known resources is a practical way to see how they are defined in HCL.</li></ul><h3>Limitations and Required Post-Export Refactoring</h3><p>It is important to note that Microsoft states the generated code is not intended to be fully reproducible from scratch. The goal is to match existing infrastructure, not to create a perfect, production-grade template for new deployments.</p><p>This is due to several factors:</p><ul><li>Some resource properties are not readable via ARM APIs or are not supported by the Terraform providers.</li><li>Nuanced configurations or default settings applied by Azure may not be captured.</li><li>Dependencies are often generated as explicit depends_on arguments rather than the preferred implicit HCL references.</li><li>Resource names can be generic, and Azure IDs are often hardcoded as static strings.</li></ul><p>Consequently, the output of aztfexport requires a mandatory and thorough manual review and refactoring phase. This process involves:</p><ul><li>Renaming logical resources to align with standards.</li><li>Replacing hardcoded IDs with dynamic references.</li><li>Introducing variables for parameterization.</li><li>Organizing the code into logical modules.</li><li>Securing any sensitive data that may have been exported.</li><li>Ensuring the final code complies with organizational security and coding standards.</li></ul><p>This refactoring stage is a critical step in transforming the raw export into a maintainable and scalable IaC codebase. It requires a solid understanding of Terraform best practices.</p><h3>Aztfexport vs Terraform Import</h3><p>The traditional terraform import command only populates the state file; the user must write all HCL code manually. aztfexport improves upon this by generating the HCL as well. While recent Terraform versions (1.5+) have introduced import blocks that can generate configuration, aztfexport provides a more streamlined workflow for bulk discovery of Azure resources.</p><p>Here is a handy table comparing them:</p><p>Compared to the multi-cloud tool Terraformer, aztfexport, as a Microsoft product, generally provides more reliable and up-to-date support for Azure-specific resources and services. Terraformer&#39;s Azure provider has been noted to lag at times.</p><p>More on <a href="https://scalr.com/learning-center/how-to-use-terraform-import/">Terraform import here</a>, and specifically on <a href="https://scalr.com/learning-center/terraform-import-blocks-youre-probably-using-them-wrong/">Terraform import blocks here</a>.</p><h3>Summary</h3><p>aztfexport is an effective utility for the first step in a brownfield-to-IaC migration: getting existing Azure resources and their state into a basic Terraform configuration. It successfully automates what would otherwise be a tedious and error-prone manual process.</p><p>However, the export is only the beginning. The output is a raw draft that must undergo significant refactoring and enhancement to become robust, maintainable, and secure Infrastructure as Code. An effective adoption strategy must account for this necessary second phase, which includes establishing code standards, modularizing configurations, implementing variables, and integrating the code into a CI/CD pipeline for testing and deployment. While aztfexport provides the initial assets, a disciplined engineering process is required to turn them into a fully managed IaC system.</p><p><em>Originally published at </em><a href="https://scalr.com/learning-center/how-to-use-azure-aztfexport-101-guide/"><em>https://scalr.com</em></a><em> on June 2, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a601066ea87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Product Updates April 2025: Flexible Storage Options, Federation, and GitOps Workflows]]></title>
            <link>https://medium.com/@scalr/product-april-march-2025-better-flexibility-federation-and-gitops-workflows-86219615d6e6?source=rss-a6d3183ee598------2</link>
            <guid isPermaLink="false">https://medium.com/p/86219615d6e6</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[opentofu]]></category>
            <category><![CDATA[open-policy-agent]]></category>
            <category><![CDATA[scalr]]></category>
            <dc:creator><![CDATA[Scalr]]></dc:creator>
            <pubDate>Thu, 08 May 2025 19:23:17 GMT</pubDate>
            <atom:updated>2025-05-08T19:55:22.122Z</atom:updated>
            <content:encoded><![CDATA[<p>In April, we rolled out new features aimed at improving flexibility in how teams manage state and workflows, enabling cross-environment operations, and expanding policy and GitOps capabilities.</p><h3>Storage Profiles</h3><p>Storage Profiles now support storing state, logs, and configuration files either in Scalr or in customer-managed buckets across AWS, Azure, or GCP. This gives administrators more flexibility and control over data residency, compliance, and cost management, while maintaining Scalr’s automation and governance benefits. More information can be found <a href="https://docs.scalr.io/docs/storage-profiles">here</a>.</p><figure><img alt="Screenshot of an example of Storage Profiles in Scalr screeshot" src="https://cdn-images-1.medium.com/max/1024/0*OLjSd3hSJ752GHI0.png" /><figcaption>Example of Storage Profiles in Scalr</figcaption></figure><h3>Cross-Environment Run Triggers and State Sharing</h3><p>We introduced federated environment access, making it possible for workspaces in different environments to share state and trigger runs across boundaries. Many organizations separate workspaces into different environments for governance or team structure reasons. This update makes it easier to automate workflows across those environments without manual coordination. More information can be found <a href="https://docs.scalr.io/docs/cross-environments-access">here</a>.</p><figure><img alt="Screenshot of a example of Scalr’s Federated Environments" src="https://cdn-images-1.medium.com/max/1024/0*_Balm-JY4Y26bUwz.png" /><figcaption>Example of Scalr’s Federated Environments</figcaption></figure><h3>Pull Request Dashboard</h3><p>A new dashboard now displays all pull requests linked to a workspace, along with their statuses. This gives teams better visibility into pending infrastructure changes and reduces the need to switch between tools when reviewing and managing changes.</p><figure><img alt="Screenshot of an example of the pull request dashboard in Scalr" src="https://cdn-images-1.medium.com/max/1024/0*zgU1AN0M1gHh-YcP.png" /><figcaption>Example of the pull request dashboard</figcaption></figure><h3>API Token Expiration Dates</h3><p>Administrators can now set expiration dates for API tokens. This enables enforced token rotation policies, improving security without adding manual processes.</p><h3>New OPA Input: Merge Error Attribute</h3><p>We added a new merge_error attribute to the policy input, capturing merge blocker statuses (like ‘dirty’, ‘blocked’, or ‘behind’) from GitHub pull requests. This allows teams to proactively enforce policies that prevent runs from executing against pull requests in a blocked or unstable state. An example OPA policy can be found <a href="https://docs.scalr.io/docs/examples-use-cases#prevent-an-apply-from-a-pr-that-cannot-be-merged">here</a>.</p><p>Thanks for getting this far… feel free to <a href="https://scalr.io/v2/signup/">sign up</a> and use Scalr to see how we can help you adopt grow and scale Terraform/ OpenTofu at your organization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86219615d6e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Product Updates March 2025: Hooks Registry, Tag Based Runs, Drift Actions, & More!]]></title>
            <link>https://medium.com/@scalr/product-updates-march-2025-hooks-registry-tag-based-runs-drift-actions-more-4310c71ee465?source=rss-a6d3183ee598------2</link>
            <guid isPermaLink="false">https://medium.com/p/4310c71ee465</guid>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[checkov]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[opentofu]]></category>
            <dc:creator><![CDATA[Scalr]]></dc:creator>
            <pubDate>Mon, 14 Apr 2025 19:16:31 GMT</pubDate>
            <atom:updated>2025-04-14T20:15:12.890Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s a quick look at what we shipped in March. A few improvements, a few new features, all aimed at making Scalr easier and more powerful for our customers.</p><h3>Custom Hooks Registry</h3><p>The hooks registry is a central location for storing and managing scripts for the <a href="https://docs.scalr.io/docs/custom-hooks">workspace’s custom hooks feature</a>. Hooks are stored in a VCS provider and pulled into Scalr. The hooks are applied to an environment and assigned a pipeline phase to run during, and all workspaces will automatically have them applied. See the docs <a href="https://docs.scalr.io/docs/hooks">here</a>.</p><figure><img alt="Custom Hooks Registry Screenshot of the Product" src="https://cdn-images-1.medium.com/max/1024/1*VFu3gigaDBJuzd8CbSE6Mg.png" /><figcaption>Custom Hooks Registry Example</figcaption></figure><h3>Tag-Based Run Triggers</h3><p>The new “Tag created” trigger event will create a run when a new tag matching the workspace version constraint is pushed. Version constraints can be defined as they are in the standard Terraform or OpenTofu configuration language. See the docs on this <a href="https://docs.scalr.io/docs/vcs">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WNqUKSXX5pwmMfFqUCVDJw.png" /><figcaption>Tag-Based Run Trigger Example</figcaption></figure><h3>Drift Actions</h3><p>Workspace owners can now address detected drift by syncing the state, reverting the infrastructure changes, or ignoring it and making updates manually. Learn more about the options <a href="https://docs.scalr.io/docs/drift-detector">here</a>.</p><figure><img alt="Screenshot of the drift detection remediation in Scalr" src="https://cdn-images-1.medium.com/max/1024/1*Zd-9DuKvEhBKurAW5nOR7g.png" /><figcaption>Drift detection remediation example</figcaption></figure><h3>Terragrunt Improvements</h3><ul><li><strong>OPA for Terragrunt run-all</strong>: Open Policy Agent policies can now be enforced in workspaces using the Terragrunt run-all command. OPA will review all units during run-all executions, ensuring compliant deployments.</li><li><strong>CLI Support for Remote Terragrunt Workspaces</strong>: Users can now manage remote Terragrunt workspaces via the CLI. This update enables running `terragrunt plan` and `terragrunt apply` directly from the CLI.</li><li><strong>Visual Plan:</strong> A new units tab has been added to the visual plan for Terragrunt run-all executions.</li></ul><p>Learn more <a href="https://docs.scalr.io/docs/terragrunt">here</a>.</p><h3>Custom Checkov Policies</h3><p>Scalr admins can now import custom policies for the Checkov integrations, giving them more flexibility in the vulnerabilities that are scanned for. The policies will be stored in your VCS provider, pulled into Scalr, and applied to environments. See more <a href="https://docs.scalr.io/docs/checkov#external-checkscustom-policies">here</a>.</p><figure><img alt="screenshot of an example custom Checkov policy in scalr" src="https://cdn-images-1.medium.com/max/1024/1*SvjwHSlpukoRmnTdS-aDeQ.png" /><figcaption>Example of a custom Checkov policy</figcaption></figure><p>Thanks for getting this far… feel free to <a href="https://scalr.io/v2/signup/">sign up</a> and use Scalr if you think we can help you adopt grow and scale Terraform/ OpenTofu at your organization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4310c71ee465" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Terraform Provider]]></title>
            <link>https://medium.com/@scalr/kubernetes-terraform-provider-6df2e7745778?source=rss-a6d3183ee598------2</link>
            <guid isPermaLink="false">https://medium.com/p/6df2e7745778</guid>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Scalr]]></dc:creator>
            <pubDate>Wed, 13 Nov 2024 19:41:26 GMT</pubDate>
            <atom:updated>2024-11-13T19:41:26.362Z</atom:updated>
            <content:encoded><![CDATA[<p>When it comes to deploying and managing the internals of a Kubernetes cluster in your environment there are many management options from a helm chart, raw manifests, kustomize and more. However from my experiences and best practices in mind if your organization is already using Terraform (or OpenTofu) then using Terraform to provide you with full lifecycle management of Kubernetes resources is the best option. Using the Terraform Kubernetes provider allows for a streamlined experience for not only your current team members but those coming into the organization. The HashiCorp configuration language (HCL) helps to provide that common language used to describe and build any service/resource/anything-you-can-dream-of in your organization.</p><p>In this post we will dive into configuring the official Kubernetes provider to build out Kubernetes services across your environment irrespective or the underlying cloud provider, as really that is one of the main selling points of Kubernetes.</p><h3>Provider Configuration</h3><p>The following link on the Terraform registry is where you can get the most up to date information about the <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs">Kubernetes Provider</a>. A unique aspect of the Kubernetes provider is its use of versioned resources and data sources, these versions are aligned to the API version with Kubernetes itself and allows for strong backwards compatibility. An example of this being the kubernetes secrets resources as per below:</p><pre>resource &quot;kubernetes_secret_v1&quot; &quot;versioned&quot; {}<br>resource &quot;kubernetes_secret&quot; &quot;unversioned&quot; {}</pre><p>Additional information can be found out about the Kubernetes API and its versions <a href="https://kubernetes.io/docs/reference/kubernetes-api/">here</a>.</p><p>The provider allows numerous ways to configure it, these can be grouped into two categories <em>explicit</em> and <em>implicit</em>. Where the former is done by supplying configuration arguments directly into the provider block and the latter utilizes environment variables. When configuring the provider it is <strong>essential</strong> to consider sensitive information such as keys and tokens in order to prevent a security issue. I would generally strongly encourage the sensitive details being passed in via the CLI or environment variables. With those two categories in mind lets walk through some examples of configuring the provider for authentication with the cluster:</p><ul><li>File configuration</li><li>Credential configuration</li><li>In-cluster configuration</li><li>Exec plugins</li></ul><h3>File configuration</h3><p>File configuration is a great way to configure the provider when working locally with Terraform as it simply takes a path to the Kubeconf which contains all relevant details, further to this you can constrain it to a given context or the default context will be used.</p><pre>provider &quot;kubernetes&quot; {  <br>	config_path    = &quot;~/.kube/config&quot;  <br>	config_context = &quot;azure-prod-cluster&quot;<br>}</pre><p>This would grab the relevant details from the Kubeconf to authenticate the provider with that particular cluster. Alternatively the environment variables KUBE_CONFIG_PATH and CONFIG_CONTEXT can be used.</p><h3>Credentials configuration</h3><p>This method of configuration allows for directly passing in the file contents for relevant authentication arguments, this approach can be very powerful when your Terraform orchestrator dynamically provides those files either for a single environment or different environments allowing you to have the same configuration sprayed across multiple clusters. Lets dive into those arguments:</p><pre>provider &quot;kubernetes&quot; {<br>  host = &quot;https://kubernetes.dev.example.com:26443&quot;<br>  client_certificate     = file(&quot;~/.kube/client-cert.pem&quot;)<br>  client_key             = file(&quot;~/.kube/client-key.pem&quot;)<br>  cluster_ca_certificate = file(&quot;~/.kube/cluster-ca-cert.pem&quot;)<br>}</pre><p>These arguments are very self-explanatory, in that they do what they say. We are passing in the paths to the file builtin function which ingests the contents as a UTF-8 encoded string. This configuration can additionally be done by using data sources within a given cloud platform allowing for truly dynamic configuration of this provider.</p><h3>In-cluster configuration</h3><p>If you’re running your Terraform commands within a Kubernetes cluster and it is that cluster you wish to execute on the the in-cluster configuration is perfect. This configuration is done via the KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT environment variables allowing Terraform to configure resources within the cluster.</p><h3>Exec plugins</h3><p>Cloud providers, when it comes to Kubernetes all give their consumers the ability to retrieve the Kubeconf from the managed clusters using CLI utilities. The Exec plugin type of configuration allows for exactly this scenario where you want to execute an external command to retrieve the correct details at runtime. The below example uses AWS’ EKS service.</p><pre>provider &quot;kubernetes&quot; {<br>  host                   = var.cluster_endpoint<br>  cluster_ca_certificate = base64decode(var.cluster_ca_cert)<br>  exec {<br>    api_version = &quot;client.authentication.k8s.io/v1beta1&quot;<br>    args        = [&quot;eks&quot;, &quot;get-token&quot;, &quot;--cluster-name&quot;, var.cluster_name]<br>    command     = &quot;aws&quot;<br>  }<br>}</pre><p>The contents of the exec block could easily be subbed out for the Azure variant:</p><pre>exec {<br>  api_version = &quot;client.authentication.k8s.io/v1beta1&quot;<br>  args        = [ &quot;aks&quot;, &quot;get-credentials&quot;, &quot;--resource-group&quot;, var.cluster_resource_group_name, &quot;--name&quot;, var.cluster_name ]<br>  command     = &quot;az&quot;<br>}</pre><p>This in my opinion is another unique feature of the Kubernetes Terraform provider and one I feel is extremely valuable, as it allows you to access external mechanisms to authenticate from within the provider declaration itself.</p><h3>Examples</h3><p>In the below example we are going to look at deploying a very simple service to its own namespace using Terraform.</p><pre>locals {<br>  labels = {<br>    app = &quot;example&quot;<br>    env = &quot;dev&quot;<br>  }<br>}<br>provider &quot;kubernetes&quot; {<br>  config_path    = &quot;~/.kube/config&quot;<br>  config_context = &quot;orbstack&quot;<br>}<br>resource &quot;kubernetes_namespace_v1&quot; &quot;this&quot; {<br>  metadata {<br>    name = &quot;example&quot;<br>  }<br>}<br>resource &quot;kubernetes_deployment_v1&quot; &quot;this&quot; {<br>  metadata {<br>    name      = &quot;example-deploy&quot;<br>    namespace = kubernetes_namespace_v1.this.metadata[0].name<br>    labels    = local.labels<br>  }<br>  spec {<br>    replicas = 3<br>    selector {<br>      match_labels = local.labels<br>    }<br>    template {<br>      metadata {<br>        name      = &quot;example&quot;<br>        namespace = kubernetes_namespace_v1.this.metadata[0].name<br>        labels    = local.labels<br>      }<br>      spec {<br>        container {<br>          name  = &quot;example&quot;<br>          image = &quot;karthequian/helloworld:latest&quot;<br>          port {<br>            container_port = 8080<br>          }<br>        }<br>      }<br>    }<br>  }<br>}<br>resource &quot;kubernetes_service_v1&quot; &quot;this&quot; {<br>  metadata {<br>    name      = &quot;example-service&quot;<br>    namespace = kubernetes_namespace_v1.this.metadata[0].name<br>    labels    = local.labels<br>  }<br>  spec {<br>    type = &quot;LoadBalancer&quot;<br>    port {<br>      port        = 80<br>      target_port = 8080<br>    }<br>    selector = local.labels<br>  }<br>}</pre><p>The above creates us a service distributing across our three pods created by the deployment as can be seen by the below diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1MUyvsFfsnpMoDZWbimZaA.png" /></figure><p>The advantage of using OpenTofu/Terraform for provisioning our Kubernetes services is that it is a common language that teams can understand irrespective of the service/infrastructure they’re trying to deploy at a given moment. It also means that we have access to the extremely powerful features of OpenTofu/Terraform and example of this above is reference the namespace rather than typing it out as well as the locals for our labels.</p><h3>Closing Out</h3><p>In this post we walked through the Kubernetes provider, how to set it up and configure it. There were four main ways for us to do this; File configuration, Credential configuration, In-cluster configuration, Exec plugins these give engineers the flexibility to configure Kubernetes in whatever way is required for a given situation. Finally we closed out by looking at an example of how we can use Terraform to deploy an instance of something to Kubernetes.</p><p>‍</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6df2e7745778" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform Random Provider]]></title>
            <link>https://medium.com/@scalr/terraform-random-provider-67b265de5cfa?source=rss-a6d3183ee598------2</link>
            <guid isPermaLink="false">https://medium.com/p/67b265de5cfa</guid>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[provider]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[opentofu]]></category>
            <dc:creator><![CDATA[Scalr]]></dc:creator>
            <pubDate>Thu, 03 Oct 2024 14:12:33 GMT</pubDate>
            <atom:updated>2024-10-03T14:12:33.283Z</atom:updated>
            <content:encoded><![CDATA[<p>The “random” Terraform provider, one of the more unique Terraform providers, is used to generate random values in your Terraform or OpenTofu configurations. It’s particularly useful when you need unique or arbitrary values in the Terraform configuration, but don’t want to hardcode them. Some use cases for using the random provider are:</p><ul><li>Creating unique names for resources</li><li>Generating random passwords or API keys</li><li>Selecting random elements from a list</li></ul><p>There are five resources that the random provider supports in the Terraform configuration:</p><ul><li>random_id: Generates a random identifier</li><li>random_integer: Produces a random integer within a specified range</li><li>random_string: Creates a random string of characters</li><li>random_password: Generates a random password</li><li>random_shuffle: Randomly shuffles a list of strings</li><li>random_pet: Randomly generate names</li><li>random_uuid : Randomly generates a UUID</li></ul><p>It’s important to note that the random values are generated during the plan phase and remain consistent across applies, unless explicitly set to regenerate through the keepers argument which is discussed later in the blog.</p><h3>Set the Provider</h3><p>Before doing anything, you always need to declare the provider to ensure you can pull the random resources into the Terraform run:</p><pre>terraform {<br>  required_providers {<br>    random = {<br>      source  = &quot;hashicorp/random&quot;<br>      version = &quot;~&gt; 3.0&quot;<br>    }<br>  }<br>}</pre><h3>Examples</h3><p>Once the Terraform provider is set, you can start testing out the various provider resources as seen below:</p><h3>random_id</h3><p>The main use case for the random_id resource is to create random resource IDs, such as appending an ID to a name. This will allow you to keep a consistent naming convention:</p><pre># Define variables<br>variable &quot;environment&quot; {<br>  type    = string<br>  default = &quot;stage&quot;<br>}<br>variable &quot;instance_type&quot; {<br>  type    = string<br>  default = &quot;t2.micro&quot;<br>}<br>variable &quot;ami_id&quot; {<br>  type    = string<br>  default = &quot;ami-09bd3f9be7c1b8217&quot; <br>}<br># Generate a random ID<br>resource &quot;random_id&quot; &quot;server_id&quot; {<br>  keepers = {<br>    # Generate a new id when these values change<br>    ami_id        = var.ami_id<br>    instance_type = var.instance_type<br>    environment   = var.environment<br>  }<br>  byte_length = 8<br>}<br># Create an EC2 instance<br>resource &quot;aws_instance&quot; &quot;example&quot; {<br>  ami           = var.ami_id<br>  instance_type = var.instance_type<br>  tags = {<br>    Name        = &quot;server-${var.environment}-${random_id.server_id.hex}&quot;<br>    Environment = var.environment<br>    some_tag    = &quot;tag123&quot;<br>  }<br>}</pre><h3>random_integer</h3><p>The main use case for the random_integer resource is to create a random integer for testing scenarios and simulations.</p><pre>resource &quot;random_integer&quot; &quot;min_size&quot; {<br>  min = 1<br>  max = 3<br>}<br>resource &quot;random_integer&quot; &quot;max_size&quot; {<br>  min = 4<br>  max = 6<br>}<br>resource &quot;random_shuffle&quot; &quot;az_list&quot; {<br>  input        = data.aws_subnets.default.ids<br>  result_count = 2<br>}<br>resource &quot;aws_autoscaling_group&quot; &quot;example&quot; {<br>  name                = &quot;example-asg&quot;<br>  vpc_zone_identifier = random_shuffle.az_list.result<br>  min_size            = random_integer.min_size.result<br>  max_size            = random_integer.max_size.result<br>  desired_capacity    = random_integer.min_size.result<br>}</pre><h3>random_string</h3><p>The main use case for the random_string resource is to generate random strings for input. This helps to create unique values for testing, especially useful for non-sensitive values. Sensitive values would be more appropriate for the random_password resource below.</p><pre>resource &quot;random_string&quot; &quot;bucket_suffix&quot; {<br>  length  = 8<br>  special = false<br>  upper   = false<br>}<br><br>resource &quot;aws_s3_bucket&quot; &quot;example&quot; {<br>  bucket = &quot;some-example-${random_string.bucket_suffix.result}&quot;<br>  tags = {<br>    Name        = &quot;My bucket&quot;<br>    Environment = &quot;Dev&quot;<br>  }<br>}</pre><h3>random_password</h3><p>The main use case for random_password is to generate random passwords or strings to improve security. Rather than relying on a human, this resource will create strong unique passwords based on the set of rules that are set:</p><pre>resource &quot;random_password&quot; &quot;db_password&quot; {<br>  length           = 16<br>  special          = true<br>  override_special = &quot;!#$%&amp;*()-_=+[]{}&lt;&gt;:?&quot;<br>}<br><br>resource &quot;aws_db_instance&quot; &quot;default&quot; {<br>  identifier        = &quot;mydb&quot;<br>  engine            = &quot;mysql&quot;<br>  engine_version    = &quot;5.7&quot;<br>  instance_class    = &quot;db.t3.micro&quot;<br>  allocated_storage = 20<br>  <br>  db_name  = &quot;mydb&quot;<br>  username = &quot;admin&quot;<br>  password = random_password.db_password.result<br>  skip_final_snapshot = true<br>  }<br>}</pre><h3>random_shuffle</h3><p>The main use case for random_shuffle is to randomly shuffle a list of inputs. A use case for this is distributing resources across different AZs for high availability:</p><pre>variable &quot;availability_zones&quot; {<br>  default = [&quot;us-west-2a&quot;, &quot;us-west-2b&quot;, &quot;us-west-2c&quot;, &quot;us-west-2d&quot;]<br>}<br><br>resource &quot;random_shuffle&quot; &quot;az_list&quot; {<br>  input        = var.availability_zones<br>  result_count = 2<br>}<br>resource &quot;aws_instance&quot; &quot;example&quot; {<br>  count             = 2<br>  ami               = &quot;ami-0c55b159cbfafe1f0&quot;  # Amazon Linux 2 AMI (HVM), SSD Volume Type<br>  instance_type     = &quot;t2.micro&quot;<br>  availability_zone = random_shuffle.az_list.result[count.index]<br>}</pre><h3>random_pet</h3><p>The main use case for this is to provide an easy way to generate unique, memorable names for resources without having to come up with them manually.</p><pre>resource &quot;random_pet&quot; &quot;bucket_name&quot; {<br>  prefix = &quot;my-unique-bucket&quot;<br>  length = 4<br>}<br><br>resource &quot;aws_s3_bucket&quot; &quot;example&quot; {<br>  bucket = random_pet.bucket_name.id<br>  tags = {<br>    Name        = &quot;My bucket&quot;<br>    Environment = &quot;Dev&quot;<br>  }<br>}</pre><h3>random_uuid</h3><p>Nothing else is needed besides the resource when using random_UUID, as it calls <a href="https://github.com/hashicorp/go-uuid">go-uuid</a> to generate the UUID:</p><pre>resource &quot;random_uuid&quot; &quot;test&quot; { <br>}</pre><h3>Keepers</h3><p>By design, the values generated as part of the random provider will remain the same during every new Terraform plan and apply, unless told otherwise by a “keeper” in the configuration file. Keepers reference an attribute in the Terraform code, that if changed, will change the random value. The goal is to make the value of the random resource predictable in how it behaves. For example, you might want the name of an ec2 instance to remain the same unless the AMI, instance type, or environment type changes:</p><pre># Define variables<br>variable &quot;environment&quot; {<br>  type    = string<br>  default = &quot;stage&quot;<br>}<br><br>variable &quot;instance_type&quot; {<br>  type    = string<br>  default = &quot;t2.micro&quot;<br>}<br>variable &quot;ami_id&quot; {<br>  type    = string<br>  default = &quot;ami-09bd3f9be7c1b8217&quot;<br>}<br># Generate a random ID<br>resource &quot;random_id&quot; &quot;server_id&quot; {<br>  keepers = {<br>    # Generate a new id when these values change<br>    ami_id        = var.ami_id<br>    instance_type = var.instance_type<br>    environment   = var.environment<br>  }<br>  byte_length = 8<br>}<br># Create an EC2 instance<br>resource &quot;aws_instance&quot; &quot;example&quot; {<br>  ami           = var.ami_id<br>  instance_type = var.instance_type<br>  tags = {<br>    Name        = &quot;server-${var.environment}-${random_id.server_id.hex}&quot;<br>    Environment = var.environment<br>    some_tag    = &quot;tag123&quot;<br>  }<br>}</pre><h3>Summary</h3><p>The random Terraform provider is a good resource to use when testing and simulation is needed. Rather than leaving it up to human error, the random provider can ensure proper values are generated based on rules. As you try out the random provider, it’s important to try out the keepers argument to see how resources change based on it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67b265de5cfa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>