Share Your Infrastructure Across Projects
What Is Shared Infrastructure?
StackGen allows you to share outputs from one appStack so they can be reused by other appStacks or projects. This is useful when you have separate stacks for networking, applications, or other infrastructure components, and need one appStack to reference resources from another.
Use this feature when:
- You’ve deployed an appStack (e.g., networking) and want other appStacks (e.g., application) to reuse its outputs such as
VPC IDs
,subnet IDs
, orsecurity group IDs
. - You want to make infrastructure outputs available to a specific Project in StackGen.
How It Works
When you click Share infra via appStack page:
- StackGen locates the Terraform state (
tfstate
) for the selected appStack. - The output values defined in that state file are extracted. For example,
VPC IDs
,Subnet IDs
,Load Balancer DNS names
,Security Group IDs
. - These outputs are published to the target project in StackGen.
- Any appStack in that project can reference these shared values in its own Terraform configuration without redeploying the original appStack.
- If the original appStack is updated and re-shared, dependent appStacks will receive the updated values on their next provision.
This allows different teams or environments to work independently while still reusing common infrastructure resources.
Example Scenarios
- Multiple Environment Profiles: If your appStack was provisioned with profiles like
dev
andprod
, sharing it will make all profile outputs available. - Remote Backend: If your remote backend is enabled, sharing will still provide Terraform state outputs to the target project automatically.
Let's see how you can share your infrastructure in multiple ways.
Steps to Share Your Infrastructure
Prerequisites
- The appStack you want to share must already be provisioned. You can use
terraform init
or StackGen CLI to provision your IaC.-
To provision your IaC using StackGen CLI, run the following command:
stackgen provision --apply --appstack-id=<appstackId> --project-id=<projectId> --var="region=<region>"
You will also see the appStack specific CLI when you click Share Infra via the appStack page.
-
- Ensure that you have the correct access permissions (DevOps or Admin) for sharing the appStack in the target project.
Share Your Infrastructure
You can share infrastructure that is provisioned or deployed in the following ways:
-
Provisioned or Deployed appStack: Provision or deploy an appStack using StackGen CLI or Terraform to share your infrastructure across projects.
-
StackGen CLI: You can create an appStack from scratch or import a
tfstate
file to StackGen. You can simply click Share Infra via the appStack page once provisioned. -
appStacks created using Cloud Asset Discovery: You can share infrastructure from appStack created using Cloud Asset Discovery.
-
appStacks provisioned with a remote backend: Share your infrastructure after provisioning or deploying an appStack with remote Backend enabled.
-
Coming soon: Share infrastructure after provisioning or deploying an appStack with environment profiles.
To share your Infrastructure across Projects, follow these steps:
-
From the StackGen Home page, navigate to appStacks > select your appStack > click the ellipses ⋮ icon.
-
Select Share Infra.
-
If you haven't provisioned your infrastructure, you will get a prompt to do the same, as shown below:
-
-
Assign the relevant Project from the drop-down and click Share Infra once done.
-
To stop sharing your infra with a particular Project, click the delete icon next to the listed projects.
-
Use Shared Infrastructure in Your appStack
Once you've shared your infrastructure with a Project, your Developers can use these values in their appStacks created within this Project.
Let's see how to do that.
-
Navigate to your Project and create an appStack.
-
While configuring resources, you'll notice a settings ⚙️ icon that appears next to the field with shared infrastructure values.
-
Select the value from the Available Shared Values drop-down and click Save.
-
You can now Download the
IaC.zip
. -
In your CLI, enter the
$path
where the.zip
file is stored and run the following commands:unzip <your zip file name>
terraform init
terraform plan
terraform apply
You have now deployed an appStack where the output is referenced to your shared infrastructure. This approach avoids duplication and maintains alignment with the pre-provisioned infrastructure.