import { Ctrlplane } from "@ctrlplane/node-sdk";
const client = new Ctrlplane({ apiKey: process.env.CTRLPLANE_API_KEY });
// Sync resources from your infrastructure
async function syncResources() {
const servers = await discoverServers(); // Your discovery logic
for (const server of servers) {
await client.resources.upsert({
workspaceId: "your-workspace-id",
identifier: server.id,
name: server.hostname,
kind: "Server",
version: "1.0.0",
metadata: {
environment: server.environment,
region: server.region,
team: server.team,
},
config: {
host: server.ip,
port: 22,
},
});
}
}
// Run on interval
setInterval(syncResources, 5 * 60 * 1000); // Every 5 minutes