MicroticaMicrotica

Environments (SDK)

Clone, deploy, wait on, and tear down Microtica environments and their resources with the SDK's envs namespace, plus config management.

The envs namespace manages environments — the deployable units that hold your infrastructure resources. (The API calls an environment a stage; the SDK namespace is envs.)

Every method takes a project id, usually as the second argument.

Methods

MethodReturns
envs.list(projectId)Environments in the project.
envs.get(envId, projectId)One environment's metadata (no resources).
envs.getDetails(envId, projectId)The environment with each resource's full configuration.
envs.getResource(envId, projectId, resourceName)One resource's configuration.
envs.clone(sourceEnvId, projectId, target)Clone an environment (resources only).
envs.deploy(envId, projectId, opts?)Trigger a deployment; returns immediately.
envs.waitForDeploy(envId, projectId, opts?)Poll until every resource settles.
envs.updateResourceConfig(envId, projectId, name, body, opts?)Update a resource's config (merges by default).
envs.addResource(envId, projectId, body)Add a component instance to the environment.
envs.removeResource(envId, projectId, name)Remove a resource from the spec.
envs.undeploy(envId, projectId)Destroy the environment's cloud resources.
envs.delete(envId, projectId)Remove the environment record.
envs.lastDeploy(resourceName, projectId, opts?)The most recent deploy of a resource.
envs.deploymentLogs(projectId, envId, deploymentId, opts?)A deployment log stream.

Deploy and wait

deploy returns as soon as the deployment is queued. Pair it with waitForDeploy to block until every resource reaches a terminal status.

TypeScript
await microtica.envs.deploy(envId, projectId);

const settled = await microtica.envs.waitForDeploy(envId, projectId, {
  timeoutMs: 30 * 60_000,
  pollIntervalMs: 10_000,
});

To deploy only some resources, pass partialResources. Omit a resource's version (or set it to "latest") to deploy its latest build, or pin an exact build id:

TypeScript
await microtica.envs.deploy(envId, projectId, {
  partialResources: [{ name: "VPC" }, { name: "Api", version: "4f3a9c21" }],
});

An empty version is rejected. A null or empty version override tells the engine to remove the resource from the cloud, so the SDK refuses it — a deploy never silently deletes a resource.

Clone an environment

clone copies resources and their configurations into a new environment; apps are not copied. The cloudProvider and infrastructureAsCodeTool values are normalized to lowercase for you, so the friendly forms work. Cloning is idempotent — an existing environment of the same name is returned with alreadyExisted: true.

TypeScript
const result = await microtica.envs.clone(sourceEnvId, projectId, {
  name: "Staging",
  description: "Staging stage",
  cloudProvider: "aws",
  infrastructureAsCodeTool: "terraform",
});
// { id: "Staging-G6q5rBbK5a", done: true, alreadyExisted: false }

Update a resource's config

updateResourceConfig merges by default: it fetches the resource's current configuration and folds your overrides on top, so you only pass what changes. Pass { merge: false } to replace the whole set. Configurations accept either the array form or a plain { key: value } map.

TypeScript
// Merge — change one key, keep the rest
await microtica.envs.updateResourceConfig(envId, projectId, "RDS", {
  configurations: { instance_class: "db.t3.medium" },
});

Add a resource

addResource instantiates a component as a new resource. Its configuration must satisfy the component's schema for that version — fetch it first with components.getSchema.

TypeScript
await microtica.envs.addResource(envId, projectId, {
  name: "my-db",
  componentId,
  componentVersion: "latest",
  configurations: { engine: "postgres" },
});

Tear down

undeploy destroys the environment's cloud resources but keeps the Microtica record; delete removes the record. Call undeploy first if resources are still up, or delete leaves orphans.

TypeScript
await microtica.envs.undeploy(envId, projectId);
await microtica.envs.waitForDeploy(envId, projectId);
await microtica.envs.delete(envId, projectId);

Find a resource's last deploy

lastDeploy returns one curated record for the most recent deploy of a resource within an environment, merging the environment run's timestamps with the resource's own commit and status. It returns undefined when nothing matches.

TypeScript
const last = await microtica.envs.lastDeploy("RDS", projectId, { envId });
// last?.envDeployId, last?.commitSha, last?.targetStatus, …

The envDeployId is the id you pass to envs.deploymentLogs to read that run's events.

Next steps

On this page