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.
Stacks let you 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. To learn if a workspace or Stack is better for your use case, refer to Choose a workspace or Stack.
Hands-on: Try out the Deploy a Stack with HCP Terraform tutorial to get started with Stacks quickly.
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.
Workflow
Start by creating a component configuration file and filling it with component
blocks. Each component
block includes a Terraform module as its source, and you can configure each component 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 component 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 deployment runs that you can review and apply like normal Terraform operations.
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.
Permissions
Stacks and do not have separate permissions, but do inherit project permissions. Refer to project permissions to learn more about the available permissions.
Access variable sets
Stacks can access variable set values in deployments using the store
block. Your Stack must have access to the variable set you are targeting, meaning it must be globally available or assigned to the project containing your Stack or the Stack itself.
To learn how to assign and create variable sets, refer to Manage variables.
Pass data between Stacks
If you have multiple Stacks that reside in the same project and do not share a provisioning lifecycle, you can link Stacks together to export data from one Stack for another to consume. If the output value of a Stack changes after a run, HCP Terraform automatically triggers runs for any Stacks that depend on those outputs. To learn more, refer to Pass data from one Stack to another.
Constraints and limitations
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.
- Stack deployment groups currently support only one deployment per group.
- Each Stack supports up to 100 components.
- Each Stack supports up to 10,000 resources.
- Stacks can link to up to 20 other upstream Stacks. Learn more about passing data between Stacks.
- Stacks can expose values to up to 25 downstream Stacks. Learn more about passing data between Stacks.
- Stacks are not available for users on legacy HCP Terraform team plans. Learn more about migrating to a current HCP Terraform plan.