Terraform
Stacks overview
As your infrastructure grows, managing Terraform configurations becomes increasingly complex. Stacks are a powerful configuration layer in Terraform that simplifies managing your infrastructure modules and then repeating that infrastructure.
Public Beta: Stacks are in public beta. Once we generally release them, we do not guarantee backward compatibility support for the public beta. All APIs, workflows, and HCL syntax for Stacks are subject to change.
Stacks allow you to split your Terraform configuration into components and then deploy and manage those components across multiple environments. You can manage the lifecycle of each deployment separately, roll out configuration changes across your deployments, and manage your Stack as a unit in HCP Terraform.
Background
Stacks are an alternative way to organize your infrastructure and fundamentally differ from HCP Terraform workspaces. Stacks are not built on top of HCP Terraform workspaces, but can exist alongside them in the same project.
Hands-on: Try out the Deploy a Stack with HCP Terraform tutorial to get started with Stacks quickly.
Previously, those looking to deploy repeatable infrastructure using HCP Terraform would create separate workspaces and then use run triggers or other automation tools to coordinate changes between them. However, workspaces are not truly coupled to each other, hampering your ability to flexibly manage infrastructure as it scales. Stacks enable you to manage your infrastructure as a single unit, simplifying deploying and managing infrastructure at scale.
Workflow
Start by creating a Stack configuration file and filling it with component
blocks. Each component
block includes a Terraform module as its source, and you can configure a block further using input arguments. Your Stack components share a lifecycle, which you can repeatedly deploy together using HCP Terraform.
After configuring your stack’s components, you create a separate deployment configuration file to define how you want to repeat your Stack's infrastructure. Each deployment in a Stack represents a group of infrastructure that works together. You can define deployment
blocks for your development environments, cloud provider accounts, or regions.
Once ready to deploy, you can create a Stack in HCP Terraform to deploy your Stack’s defined infrastructure. In HCP Terraform, you can manage your stack, its configuration version, deployments, and deployment plans.
Primary workflow
The overall process for managing your infrastructure using Stacks consists of the following steps.
Write Stack configuration
Begin by designing your stack and codifying your infrastructure in a Stack configuration. To learn more, refer to Define configuration.
Define deployments
With your Stack configuration complete, the next step is to define how you want to deploy your Stack. In stacks, deployments allow you to replicate infrastructure across multiple environments, regions, or accounts. Refer to Define deployment configuration to learn more.
Deploy
After writing your Stack and deployment configurations, you can deploy your stack’s defined infrastructure using HCP Terraform.
In HCP Terraform, you can create stacks that live alongside your workspaces within a specified project. You can also reconfigure the settings of existing Stacks.
When you change your Stack configuration, you can fetch and review configuration versions before applying them to your deployments. Changes to your Stack deployment configuration create plans that you can review and apply like normal Terraform operations.
Guidance
Stacks are particularly useful when managing complex, multi-environment infrastructures where consistency and reusability are crucial. Refer to Stack use cases for inspiration and examples of how to use stacks.
Constraints, limitations, and troubleshooting
While Stacks provide exciting capabilities, there are some limitations to be aware of during this beta phase:
- Each Stack currently supports a maximum of 20 deployments, which may limit scalability for large environments.
- While in public beta, Stacks have a limit of 500 managed resources per HCP Terraform organization. If your organization exceeds this limit, you can no longer apply new resources until you reduce your resource count. If you need more resources, fill out our form to request a resource extension.
- Stacks are not available for users on legacy HCP Terraform team plans. Learn more about migrating to a current HCP Terraform plan.
Concurrency
Concurrency traditionally refers to the number of plan and apply operations that HCP Terraform can run simultaneously. However, HCP Terraform runs Stack operations in the same agent pool and queue as workspaces. For those using stacks, your maximum HCP Terraform concurrency is the combination of your workspace runs and your Stack operations.
Your HCP Terraform subscription plan limits your maximum concurrency.