Skip to main content
⏳ Estimated read time: 6 min read

StackGen-HCP Terraform Integration

Overview

StackGen integrates with HashiCorp Cloud Platform (HCP Terraform) to combine StackGen's visual infrastructure design with Terraform’s remote state, policy enforcement, and governance. With this integration, you design infrastructure visually in StackGen, generate production-ready Terraform HCL, and deploy it through HCP Terraform.

StackGen makes it easier to create secure, validated infrastructure blueprints, while HCP Terraform provides remote state management, policy enforcement, and audit trails.

Key Features

The integration combines the simplicity of StackGen with the governance of HCP Terraform. Together, they deliver the following capabilities:

  • Visual canvas to design appStacks (infrastructure blueprints),
  • Automatic generation of Terraform HCL with HCP backend configuration,
  • Built-in security and compliance validation during design,
  • Remote state, locking, and run management in HCP Terraform,
  • Supports multi-region and multi-environment setups via workspaces.
  • Supports import of existing .tfstate file and generation of IaC.
  • Supports adding custom modules through drag and drop.
  • Configure best practice policy and scanning through StackGen before deployment. Check out Custom Policies and Compliance documentation to learn more.

Benefits

By using StackGen with HCP Terraform, your platform teams and developers gain several advantages:

  • Faster delivery: Skip manual Terraform coding with visual design and auto-generated HCL.
  • Governance included: Leverage HCP Terraform for policies, state, locking, and audit logs.
  • Security first: Design-time checks reduce misconfigurations before deploy.
  • Scale across teams: Use standardized appStacks and workspaces for consistent infra management.

Understanding the Technical Architecture

Loose Coupling for Maximum Flexibility: The integration follows a loosely coupled architecture that preserves flexibility.

Visual Flow

Key architectural principles

  • Standard Code Generation: StackGen generates standard Terraform HCL that can be version controlled, modified, and deployed independently.

  • Multi-Environment Support: Different AppStacks can target different HCP Terraform workspaces for environment separation.

  • Regional Deployment: Support for multiple regions through separate workspace configurations.

    Architechture

How It Works

At a high level, the integration follows this flow from design to deployment:

  1. Design your infrastructure in StackGen with the drag-and-drop canvas.
  2. Connect the appStack to your HCP Terraform workspace.
  3. Generate your Terraform HCL with backend configuration.
  4. Deploy via Terraform CLI, CI/CD, or HCP Terraform runs.
  5. Manage state, policies, and audit trails in HCP Terraform.

Let's learn how to do use this integration in detail.

Step-by-Step Guide

Prerequisites

Click to view

Before you begin, make sure you have the following in place:

  • A StackGen account.
  • An HCP Terraform account with at least one organization and workspace configuration.
  • Cloud provider credentials (AWS, Azure, or GCP).
  • Optional: Terraform CLI or a CI/CD pipeline, if you prefer to run deployments outside the HCP UI.

Set Up Your HCP Terraform Workspace

Click to view
  1. Log in to your HCP Terraform account.
  2. Create or select a workspace.
  3. Configure the following Workspace settings:
    • Terraform version
    • Execution mode (Remote or Local): We recommend that you use Remote.
    • Environment variables or secrets for your cloud provider credentials.
  4. Ensure you set permissions for your user or service account.

Design Your IaC in StackGen

Click to view
  1. Log into your StackGen account.

  2. From the StackGen Home page, navigate to appStacks > + New appStack.

  3. Create a new appStack from scratch and select your target cloud provider.

  4. You can either Add resources (e.g., VPC, subnets, load balancer, database, S3) to the Topology canvas. Or, you import resources from an existing .tfstate file.

    import IaC

  5. Configure your Resources and resolve any validation warnings.

    AppStack HC

Connect to HCP Terraform

Click to view
  1. From your appStack Topology canvas, click the settings icon ⚙️ to configure your storage backend.

  2. Turn on the Enable Storage Backend toggle.

  3. From the Select the backend type drop-down, select Cloud (Terraform) as the backend.

  4. Enter the following information:

    • Hostname (app.terraform.io or EU variant)
    • Organization name
    • Project
    • Workspace name

    AppStack HC

  5. Once done, click Save.

Generate and Deploy IaC

Click to view
  1. From your appStack Topology canvas, click the Download IaC icon to export your Terraform files.

    download iac

  2. Your backend config will look like the sample config below:

    terraform {
    cloud {
    organization = "your-org"

    workspaces {
    name = "your-workspace"
    }
    }
    }
  3. Deploy your infrastructure, using one of the following methods:

    • Local CLI: HCP Terraform runs in CLI push your code directly to your HCP workspace.

      Run the following commands via CLI:

      terraform init
      terraform plan
      terraform apply

      StackGen-HC

    • CI/CD pipeline: Commit generated IaC by clicking Push to Git button. Your PR will trigger the Terraform plan Actions workflow. Check out how you can Automate Terraform with GitHub Actions.

Manage and Evolve

Click to view

With the StackGen - Hasicorp Terraform integration, you can:

  • Monitor runs, logs, and audit trails in HCP Terraform.

    Monitor

  • Update your infrastructure designs in StackGen, regenerate the IaC, and redeploy your infrastructure.

  • Use multiple workspaces for different regions or environments (dev, staging, prod).