Skip to main content

Sharing Infrastructure between Projects and Environments

A resource provisioned in one project, such as a VPC or a Kubernetes cluster, can be used by instances in other projects. One team owns and configures the resource; other teams deploy onto it without being able to change it.

Common uses:

  • A platform team runs shared networks and clusters in one project, and application teams deploy onto them.
  • Preview and staging environments share one cluster, while production runs its own.
  • A database or service that Massdriver does not manage is imported and used by instances that Massdriver deploys.
  • Two VPCs are peered by a third project.

There are two ways to use a shared resource:

Environment defaultRemote reference
ScopeEvery instance in the environment that depends on the resource typeOne dependency field on one instance
LimitOne default per resource type per environmentOne remote reference per instance field
Takes priority over—The blueprint link and the environment default

Either way, the resource needs a resource grant that matches the consuming environment.

Set up the shared project​

  1. On the projects page, create a project, for example Project Name Shared Infra and Project ID si.

  2. Create an environment, for example Environment Name Staging and Environment ID staging.

  3. Open the Bundles drawer on the canvas and add a component for each shared resource, for example aws-vpc and aws-eks-cluster. The Component ID is the last segment of each instance id: component vpc in environment staging of project si is instance si-staging-vpc.

  4. Deploy the instances, then grant their resources to the environments that will use them.

Add more environments, such as production or a second region, the same way.

Use shared infrastructure​

Create the consuming project and environment the same way, for example project ecomm with environment staging, and add the components that need the shared resources, for example aws-aurora-postgresql and an application bundle. Before they can deploy, their network and cluster dependencies must be filled by environment defaults or remote references.

Using Environment Defaults​

An environment default fills a resource type for every instance in the environment that depends on it. It is not drawn on the canvas.

Open Set environment defaults at the top of the canvas, choose a resource type, then choose the resource. From an instance's Dependencies tab, Set environment default… on an unfulfilled dependency does the same.

Set the environment's network

Set the Kubernetes cluster

Any resource type, including a custom resource type, can be an environment default.

From the CLI:

shell
mass environment default ecomm-staging si-staging-vpc.vpc

Using Remote References​

A remote reference fills one dependency field on one instance with a resource from another project or an imported resource. It overrides the blueprint link and the environment default for that field. Removing it restores them. It is not drawn on the canvas.

Use a remote reference when environments of the same project need different sources. For example, production runs the team's own Kubernetes cluster from a component on the canvas, while preview environments point that dependency at the shared cluster.

On the instance, open the Dependencies tab, open the menu on the dependency, choose Use a remote reference…, and pick the resource. The list shows resources of the dependency's type that are granted to the environment.

A remote reference can be set or removed at any time. It takes effect on the instance's next deployment.

From the CLI:

shell
mass instance remote-reference set ecomm-staging-app kubernetes_cluster si-staging-eks.kubernetes_cluster

Adopting existing infrastructure​

To start with Massdriver without moving a database you already run, import it as a resource and point the dependent instance's dependency at it with a remote reference. Massdriver deploys the instance against the database without managing the database.

To migrate the database later, see Upgrading PostgreSQL Versions with Minimal Downtime. The approach also works across clouds.

Peering networks​

Create a separate project for peering. Add two aws-vpc components and one aws-vpc-peering-connection component, and link each VPC to the peering component. Configure each VPC's region and CIDR on its Config tab. The peering bundle manages the route tables once both VPCs are provisioned. To peer VPCs that live in other projects, point the peering instance's dependencies at them with remote references.