Import a Resource
An imported resource is infrastructure that Massdriver did not provision, such as an existing VPC, database, or cloud credential, recorded so that instances can depend on it. Use one as an environment default or remote reference.
Imported resources have the origin IMPORTED and a UUID id. Unlike provisioned resources, they can be updated and deleted directly.
Prerequisites​
- A resource type for the resource. Use a Massdriver resource type, one from your organization, or a custom resource type.
resource:importon resources of that type. See GraphQL permissions.- A payload that matches the resource type's schema.
The examples use this resource type:
name: my-vpc
version: 1.0.0
label: My VPC
schema:
type: object
title: My VPC
required:
- infrastructure
properties:
infrastructure:
title: Infrastructure configuration
type: object
required:
- arn
- cidr
properties:
arn:
type: string
title: AWS ARN
cidr:
type: string
title: CIDR
aws:
type: object
properties:
region:
type: string
title: Region
And this payload:
{
"infrastructure": {
"arn": "arn:aws:ec2:us-west-2:123456789012:vpc/vpc-1234567890abcdef0",
"cidr": "10.0.0.0/16"
},
"aws": {
"region": "us-west-2"
}
}
UI​
On the Resources page, click Import Resource, choose the resource type, and fill in the form. The form is generated from the type's schema. The instructions panel shows the type's ui.instructions.
CLI​
mass resource create -n my-vpc-prod -t my-vpc -f resource.json
Creating resource my-vpc-prod of type my-vpc...
Resource my-vpc-prod created! (Resource ID: 12345678-1234-1234-1234-123456789012)
mass resource import is an alias. -t takes a resource type name, which uses the latest published version, or name@version.
API​
Use the createResource mutation:
mutation ImportVpc($organizationId: ID!, $resourceTypeId: ID!, $input: CreateResourceInput!) {
createResource(
organizationId: $organizationId
resourceTypeId: $resourceTypeId
input: $input
) {
successful
messages { field message }
result { id name origin }
}
}
{
"organizationId": "my-org",
"resourceTypeId": "my-vpc",
"input": {
"name": "my-vpc-prod",
"payload": {
"infrastructure": {
"arn": "arn:aws:ec2:us-west-2:123456789012:vpc/vpc-1234567890abcdef0",
"cidr": "10.0.0.0/16"
},
"aws": {
"region": "us-west-2"
}
}
}
}
resourceTypeId is a resource type name, for the latest published version, or name@version.
curl 'https://api.massdriver.cloud/api/v2' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer md_xxxxxxxxxxxxxxxxxxxxxxxx' \
--data @- <<'JSON'
{
"query": "mutation ImportVpc($organizationId: ID!, $resourceTypeId: ID!, $input: CreateResourceInput!) { createResource(organizationId: $organizationId, resourceTypeId: $resourceTypeId, input: $input) { successful messages { field message } result { id name origin } } }",
"variables": {
"organizationId": "my-org",
"resourceTypeId": "my-vpc",
"input": {
"name": "my-vpc-prod",
"payload": {
"infrastructure": { "arn": "arn:aws:ec2:us-west-2:123456789012:vpc/vpc-1234567890abcdef0", "cidr": "10.0.0.0/16" },
"aws": { "region": "us-west-2" }
}
}
}
}
JSON
Terraform​
The provider's massdriver_imported_resource manages an imported resource as code.
Next steps​
- Grant the resource to the environments that will use it.
- Set it as an environment default or remote reference.