Skip to content
betterstack-alchemyUnofficial

Cloud.PlacementGroup

Kind ResourceType id BetterStack.Cloud.PlacementGroupSource src/Cloud/PlacementGroup.tsLive test available A live lifecycle test exists: it runs against the offline mock by default and against the real API under bun run test:live. This records that the test exists, not a dated live run (see Compatibility). Test file: test/Cloud/PlacementGroup.test.ts.

A Better Stack Cloud placement group: decides how its servers are placed on physical hosts. spread puts each server on a different host so one hardware failure can’t take more than one of them down (replicas, HA pairs); compact packs them onto as few hosts as possible for the lowest latency between them. Both are best effort: when no host fits, the server is still created. Placement groups are free; a group holds up to 10 servers by default (a quota).

A server joins a group when it is created with the group’s id (the server’s placementGroupId); it can’t move in or out later. The group lists its members in serverIds.

name and metadata change in place; placementType, teamId and availabilityZone replace the group. Removing metadata from the config keeps the tags the group has; set metadata: {} to clear them. A group can only be deleted once it has no servers, so delete its servers first (Alchemy does, when they reference the group in the same stack).

Ownership. Every object the stack creates carries an alchemy entry in its metadata (<stack>/<stage>/<resource id>#<instance>), added on every write and left out of the attributes and of diffs; your own keys are untouched (it takes one of the 10 slots). A deploy that lost track of an object it created (a create that failed or was interrupted after the API accepted it) finds it by that marker and converges it instead of creating another; list (and so alchemy nuke) returns only Alchemy-created objects; an object that matches but carries no marker of this resource is taken over only with --adopt.

Spread replicas across hosts

const group = yield* BetterStack.Cloud.PlacementGroup("replicas", {
placementType: "spread",
});

Named, compact, with tags

yield* BetterStack.Cloud.PlacementGroup("workers", {
name: "workers",
placementType: "compact",
metadata: { role: "worker" },
});

Reference a group by name

const existing = BetterStack.Cloud.PlacementGroup.lookup({ name: "workers" });

placementType "compact" | "spread" | string required

How we place the group's servers. When there isn't room, the server is still created, on another host. Can't be changed after the group is created. - spread: We put each server on a different host when we can. - compact: We put the servers on as few hosts as we can.

availabilityZone string

Availability zone the resource lives in, such as us-west-2a. Defaults to the credentials' zone (BETTERSTACK_AVAILABILITY_ZONE, or the profile's). Changing it replaces the resource. A child of a resource in another zone (a firewall rule, a node pool, a snapshot of an instance outside the credentials' zone) must repeat the parent's availabilityZone: it receives only the parent's id, so its zone cannot be derived.

metadata CreatePlacementGroupRequestMetadataMap

Your own tags, as string keys and values. An update replaces all tags, so an empty object removes every tag.

name string

The group's name. Defaults to a unique name generated from the stack, stage and logical id. Changes in place.

teamId string

Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.

availabilityZone string always set

Availability zone the resource lives in, such as us-west-2a.

id string always set

The group's ID, a UUID.

createdAt string

When the group was created.

metadata PlacementGroupMetadataMap

Your own tags, as string keys and values. An update replaces all tags, so an empty object removes every tag.

name string

The group's name.

placementType "compact" | "spread"

How we place the group's servers. When there isn't room, the server is still created, on another host. Can't be changed after the group is created. - spread: We put each server on a different host when we can. - compact: We put the servers on as few hosts as we can.

serverIds string[]

The IDs of the servers in the group. A server joins the group when you create it with placement_group_id.

teamId string

The ID of the team that owns the group. betterstack team list shows it.

updatedAt string

When the group was last updated.

PlacementGroup.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.

availabilityZone string

Zone it lives in, such as us-west-2a. Defaults to the credentials' zone.