Importing Resources
If you have existing Lagoon resources that were created outside of Pulumi, you can bring them under Pulumi management using pulumi import. This is non-destructive: Pulumi reads the current state from the Lagoon API and writes it to the stack state file without modifying the resource itself.
When to Import
Import is useful when:
- You are adopting Pulumi for an existing Lagoon installation
- A resource was created manually (e.g., via the Lagoon CLI or UI) and you want Pulumi to manage it going forward
- You need to reconcile drift between Pulumi state and the live Lagoon configuration
Import ID Reference
Each resource type uses a specific ID format for pulumi import. Use the table below to determine the correct ID for the resource you want to import.
| Resource | Import ID Format | Example |
|---|---|---|
lagoon:lagoon:Project |
{numeric_id} |
123 |
lagoon:lagoon:DeployTarget |
{numeric_id} |
1 |
lagoon:lagoon:Environment |
{project_id}:{env_name} |
123:main |
lagoon:lagoon:Variable |
{project_id}:{env_id}:{var_name} |
123:456:DATABASE_HOST |
lagoon:lagoon:Variable (project-level) |
{project_id}::{var_name} |
123::API_KEY |
lagoon:lagoon:DeployTargetConfig |
{project_id}:{config_id} |
123:5 |
lagoon:lagoon:NotificationSlack |
{name} |
deploy-alerts |
lagoon:lagoon:NotificationRocketChat |
{name} |
deploy-alerts |
lagoon:lagoon:NotificationEmail |
{name} |
deploy-alerts |
lagoon:lagoon:NotificationMicrosoftTeams |
{name} |
deploy-alerts |
lagoon:lagoon:ProjectNotification |
{project_name}:{type}:{notification_name} |
my-project:slack:deploy-alerts |
lagoon:lagoon:Task |
{numeric_id} |
456 |
lagoon:lagoon:Group |
{name} |
my-team |
lagoon:lagoon:Route |
{project_name}:{domain} |
my-project:example.com |
lagoon:lagoon:ProjectAutogeneratedRouteConfig |
{project_name} |
my-project |
lagoon:lagoon:EnvironmentAutogeneratedRouteConfig |
{project_name}:{env_name} |
my-project:main |
lagoon:lagoon:User |
{email} |
user@example.com |
lagoon:lagoon:UserGroupAssignment |
{email}:{group_name} |
user@example.com:my-team |
lagoon:lagoon:UserPlatformRole |
{email}:{role} |
user@example.com:OWNER |
Step-by-Step Import Workflow
1. Find the Resource ID
Look up the numeric ID or name of the resource in Lagoon. You can use the Lagoon CLI or query the GraphQL API directly. See Setting Up the Lagoon CLI for instructions on querying Lagoon for resource IDs.
2. Add the Resource to Your Pulumi Code
Write the resource declaration in your program before importing. The configuration must match what Lagoon currently has, or Pulumi will show a diff on the next pulumi up.
import pulumi_lagoon as lagoon
# Declare the resource you want to import
project = lagoon.Project("existing-site",
lagoon.ProjectArgs(
name="my-drupal-site",
git_url="git@github.com:org/repo.git",
deploytarget_id=1,
production_environment="main",
)
)
3. Run pulumi import
pulumi import lagoon:lagoon:Project existing-site 123
The general form is:
pulumi import <resource-type> <resource-name> <import-id>
Where <resource-name> matches the name you gave the resource in your code.
4. Verify the Import
After a successful import, run a preview to confirm there are no unexpected diffs:
pulumi preview
If Pulumi shows changes, update your code to match the imported state before running pulumi up.
Example: Importing Multiple Resources
To import a project and its environments in one pass, use the --file flag with a bulk import definition:
pulumi import --file import.json
import.json:
{
"resources": [
{
"type": "lagoon:lagoon:Project",
"name": "existing-site",
"id": "123"
},
{
"type": "lagoon:lagoon:Environment",
"name": "production",
"id": "123:main"
}
]
}
Use the Lagoon CLI (
lagoon list projects,lagoon list environments) to find numeric IDs. See the Lagoon CLI Setup guide for configuration instructions.