| name | maintainx-multi-env-setup |
| description | Configure multiple MaintainX environments (dev, staging, production).
Use when setting up environment-specific configurations,
managing multiple MaintainX accounts, or implementing environment promotion.
Trigger with phrases like "maintainx environments", "maintainx staging",
"maintainx dev prod", "maintainx multi-environment", "maintainx config".
|
| allowed-tools | Read, Write, Edit, Bash(npm:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
MaintainX Multi-Environment Setup
Overview
Configure and manage multiple MaintainX environments for development, staging, and production workflows.
Prerequisites
- Multiple MaintainX accounts or organizations
- Secret management solution
- CI/CD pipeline configured
Environment Strategy
┌─────────────────────────────────────────────────────────────────────┐
│ Environment Promotion Flow │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ DEV │ ───▶ │ STAGING │ ───▶ │ PROD │ │
│ │ │ │ │ │ │ │
│ │ sandbox │ │ testing │ │ live │ │
│ │ data │ │ data │ │ data │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ dev- │ │ staging-│ │ prod- │ │
│ │ api-key │ │ api-key │ │ api-key │ │
│ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────────────┘
Instructions
Step 1: Environment Configuration
type Environment = 'development' | 'staging' | 'production';
interface EnvironmentConfig {
name: Environment;
maintainx: {
apiKey: string;
orgId?: string;
baseUrl: string;
};
features: {
caching: boolean;
rateLimit: number;
webhooksEnabled: boolean;
};
logging: {
level: string;
redactPII: boolean;
};
}
const environments: Record<Environment, () => EnvironmentConfig> = {
development: () => ({
name: 'development',
maintainx: {
apiKey: process.env.MAINTAINX_API_KEY_DEV!,
orgId: process.env.MAINTAINX_ORG_ID_DEV,
baseUrl: 'https://api.getmaintainx.com/v1',
},
features: {
caching: false,
: ,
: ,
},
: {
: ,
: ,
},
}),
: ({
: ,
: {
: process..!,
: process..,
: ,
},
: {
: ,
: ,
: ,
},
: {
: ,
: ,
},
}),
: ({
: ,
: {
: process..!,
: process..,
: ,
},
: {
: ,
: ,
: ,
},
: {
: ,
: ,
},
}),
};
(): {
env = process.. ;
(![, , ].(env)) {
;
}
env;
}
(): {
env = ();
environments[env]();
}
{ getConfig, getEnvironment, , };
Step 2: Environment-Aware Client Factory
import { getConfig } from '../config/environments';
class MaintainXClientFactory {
private static clients: Map<string, MaintainXClient> = new Map();
static getClient(environment?: Environment): MaintainXClient {
const config = environment
? environments[environment]()
: getConfig();
const cacheKey = config.name;
if (!this.clients.has(cacheKey)) {
const client = new MaintainXClient({
apiKey: config.maintainx.apiKey,
orgId: config.maintainx.orgId,
baseUrl: config.maintainx.baseUrl,
});
if (config.features.caching) {
}
this.clients.set(cacheKey, client);
}
return ..(cacheKey)!;
}
(: ): {
.(env);
}
(): {
..();
}
}
{ };
Step 3: Environment Variables Template
MAINTAINX_API_KEY_DEV=mx_dev_xxxxx
MAINTAINX_ORG_ID_DEV=org_dev_xxxxx
MAINTAINX_API_KEY_STAGING=mx_staging_xxxxx
MAINTAINX_ORG_ID_STAGING=org_staging_xxxxx
MAINTAINX_API_KEY_PROD=mx_prod_xxxxx
MAINTAINX_ORG_ID_PROD=org_prod_xxxxx
NODE_ENV=development
version: '3.8'
services:
app:
environment:
- NODE_ENV=development
- MAINTAINX_API_KEY=${MAINTAINX_API_KEY_DEV}
- MAINTAINX_ORG_ID=${MAINTAINX_ORG_ID_DEV}
Step 4: Secret Management Integration
import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
interface SecretConfig {
apiKey: string;
orgId?: string;
}
class SecretLoader {
private client: SecretManagerServiceClient;
private projectId: string;
constructor() {
this.client = new SecretManagerServiceClient();
this.projectId = process.env.GCP_PROJECT_ID!;
}
async loadEnvironmentSecrets(env: Environment): Promise<SecretConfig> {
const apiKeyName = `maintainx-api-key-${env}`;
const orgIdName = `maintainx-org-id-${env}`;
const apiKey = await this.getSecret(apiKeyName);
const orgId = await this.getSecret(orgIdName).catch( );
{ apiKey, orgId };
}
(: ): <> {
[version] = ..({
: ,
});
version.?.?.() || ;
}
}
(): {
basePath = ;
{
: fs.(, ).(),
: fs.()
? fs.(, ).()
: ,
};
}
Step 5: Environment Promotion Tools
import { MaintainXClientFactory } from '../src/api/client-factory';
interface PromotionResult {
success: boolean;
itemsPromoted: number;
errors: string[];
}
async function promoteConfiguration(
sourceEnv: Environment,
targetEnv: Environment
): Promise<PromotionResult> {
const result: PromotionResult = {
success: true,
itemsPromoted: 0,
errors: [],
};
const sourceClient = MaintainXClientFactory.getClientForEnvironment(sourceEnv);
const targetClient = MaintainXClientFactory.getClientForEnvironment(targetEnv);
console.log(`Promoting from ${sourceEnv} to ${targetEnv}...`);
.();
.();
(result.. > ) {
.(, result.);
}
result;
}
(): <> {
.();
{
client = .(env);
client.({ : });
.();
client.({ : });
.();
client.({ : });
.();
;
} (: ) {
.();
;
}
}
() {
args = process..();
command = args[];
(command) {
:
env = args[] || ;
valid = (env);
process.(valid ? : );
;
:
source = args[] ;
target = args[] ;
(!source || !target) {
.();
process.();
}
(source, target);
;
:
.();
}
}
().(.);
Step 6: CI/CD Environment Matrix
name: Deploy
on:
push:
branches:
- develop
- main
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
type: choice
options:
- staging
- production
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- branch: develop
environment: staging
- branch: main
environment: production
environment: ${{ matrix.environment }}
steps:
- uses: actions/checkout@v4
- name: Validate
Output
- Environment-specific configurations
- Secret management integration
- Client factory for multi-environment
- Promotion tools for config sync
- CI/CD environment matrix
Best Practices
- Isolate environments: Use separate MaintainX organizations per environment
- Never share API keys: Each environment gets unique credentials
- Validate before promote: Always test configuration in lower environments
- Document differences: Track what varies between environments
- Audit access: Log which environment is being accessed
Resources
Next Steps
For observability setup, see maintainx-observability.