Skip to main content

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:grant on the resource. Provisioned resources inherit their instance's attributes, including md-project, so a group policy that allows resource:grant on a team's projects covers everything the team deploys. Organization admins have it everywhere.
  • To match by a tag such as team or pci, 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?
shell
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.

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?
shell
mass resource grant create si-staging-eks.kubernetes_cluster --condition stage=nonprod
mass resource grant create si-staging-eks.kubernetes_cluster --all-environments
mass resource grant list si-staging-eks.kubernetes_cluster

Repeat --condition with the same key to accept several values, or pass key=* to accept any value.

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 withKeyValues
Every environment with the id staging in any projectmd-environmentstaging
Every environment in the project with id ecommmd-projectecomm
Every environment in projects with the custom attribute team equal to paymentsteampayments
Every environment with the custom attribute stage equal to nonprodstagenonprod
Prod and staging in PCI projects (two conditions)md-environment
pci
prod staging
true
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?
shell
# 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:view on 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.