Share Resources with Environments
A resource grant gives environments resource:export on a resource, such as a VPC, a Kubernetes cluster, or a database, so they can use it as a remote reference or environment default. Without a grant, an environment cannot use the resource, even if its members can see it in the resources list.
Grants match recipient environments by attribute. An environment's attributes include its own and those inherited from its project, so you can match by environment (md-environment), by project (md-project), or by a custom attribute on either.
Prerequisitesโ
resource:granton the resource. Provisioned resources inherit their instance's attributes, includingmd-project, so a group policy that allowsresource:granton a team's projects covers everything the team deploys. Organization admins have it everywhere.- To match by a tag such as
teamorpci, a custom attribute that applies to projects or environments.
1. Tag the recipient environmentsโ
In the environment's settings, set the attribute on the General tab, for example stage = nonprod. To cover every environment in a project, set the attribute on the project instead.
Prefer the CLI or Terraform?
- CLI
- Terraform
mass environment update ecomm-staging -a stage=nonprod
mass project update ecomm -a team=payments
-a replaces all of the custom attributes on the environment or project. Include the ones you want to keep.
resource "massdriver_project" "ecomm" {
identifier = "ecomm"
attributes = {
team = "payments"
}
}
resource "massdriver_environment" "staging" {
project_id = massdriver_project.ecomm.id
identifier = "staging"
attributes = {
stage = "nonprod"
}
}
attributes replaces all of the custom attributes on the environment or project. Include the ones you want to keep.
2. Create the grantโ
Open the resource from the owning instance or from the organization's Resources list. Open the Permissions tab, click Add permission, and set the recipient conditions. The action is resource:export.
Prefer the CLI or Terraform?
- CLI
- Terraform
mass resource grant create si-staging-eks.kubernetes_cluster --condition stage=nonprod
mass resource grant create si-staging-eks.kubernetes_cluster --all-environments
Repeat --condition with the same key to accept several values, or pass key=* to accept any value.
resource "massdriver_resource_grant" "eks_nonprod" {
resource_id = "si-staging-eks.kubernetes_cluster"
recipient_conditions = jsonencode({ stage = ["nonprod"] })
}
resource "massdriver_resource_grant" "eks_all_environments" {
resource_id = "si-staging-eks.kubernetes_cluster"
recipient_conditions = "*"
}
List several values in one key to accept any of them. An empty list accepts any value.
List the grants on the resource:
mass resource grant list si-staging-eks.kubernetes_cluster
Recipient conditionsโ
Each condition is a key and one or more values. An environment matches when it has every key with one of the listed values. More conditions narrow the match; more values widen it. * as the value matches any environment that has the key. Project attributes are inherited by environments, so project attributes work here too.
| Share with | Key | Values |
|---|---|---|
Every environment with the id staging in any project | md-environment | staging |
Every environment in the project with id ecomm | md-project | ecomm |
Every environment in projects with the custom attribute team equal to payments | team | payments |
Every environment with the custom attribute stage equal to nonprod | stage | nonprod |
| Prod and staging in PCI projects (two conditions) | md-environmentpci | prod stagingtrue |
| Every environment in the org | * | * |
Grants can also be managed with the createResourceGrant mutation and the Terraform provider's massdriver_resource_grant resource. Matching rules are in Access Control.
3. Consume the resourceโ
In a recipient environment, set the resource as an environment default or as a remote reference on an instance. An environment can use only resources whose grants match it.
Prefer the CLI?
# environment default
mass environment default ecomm-staging si-staging-eks.kubernetes_cluster
# remote reference on an instance's dependency field
mass instance remote-reference set ecomm-staging-api kubernetes_cluster si-staging-eks.kubernetes_cluster
If the resource is missing, check that:
- The environment's effective attributes match the grant's conditions.
- Your group has
resource:viewon the resource. Grants control use; group policies control who can see the resource.
Revokeโ
Grants are immutable. To change one, delete it from the resource's Permissions tab, or with mass resource grant delete <grant-id>, and create a new one.