Skip to content
betterstack-alchemyUnofficial

Cloud.LoadBalancerTarget

Kind ResourceType id BetterStack.Cloud.LoadBalancerTargetSource src/Cloud/LoadBalancerTarget.tsLive test gated Lifecycle test runs against the offline mock; a live run exists but is gated behind BETTERSTACK_TEST_CLOUD_BILLABLE=1 because it bills; live runs need the owner's go-ahead (test/Cloud/LoadBalancerTarget.test.ts).

A target of a Better Stack Cloud LoadBalancer: one server, or every server whose metadata matches a label selector. Each of the load balancer’s services sends traffic to every healthy target, on the service’s destinationPort.

A target has no update: changing any prop (type, serverId, selector, usePrivateIp, loadBalancerId) replaces it. A load balancer can have each server as a target once, so a replacement that keeps the same server (or the same selector) on the same load balancer deletes the old target before creating the new one: traffic to that server pauses for the moment in between. Targets are free; they go away with their load balancer.

selector is an object here, while the load balancer’s own targets attribute shows the same selector as JSON text on the wire; both LoadBalancer and this resource parse it back into an object.

Ownership. The API keeps no metadata for it and it has no generated name, so nothing marks it as this stack’s: list enumerates it under every parent, and a create interrupted before its state was saved is not recognised by the next deploy (which creates it again, or gets the API’s conflict when its identity is unique).

Zone. A child doesn’t take its zone from its parent: it uses its own availabilityZone, else the credentials’ zone. When the parent lives in another zone, pass the parent’s along (availabilityZone: parent.availabilityZone), or every call for it answers NotFound.

One server, over its private IP

const lb = yield* BetterStack.Cloud.LoadBalancer("edge", { type: "LB1" });
yield* BetterStack.Cloud.LoadBalancerTarget("web-1", {
loadBalancerId: lb.id,
type: "server",
serverId: server.id,
usePrivateIp: true,
});

Sending traffic to every server with a tag

Section titled “Sending traffic to every server with a tag”

A label selector

yield* BetterStack.Cloud.LoadBalancerTarget("web", {
loadBalancerId: lb.id,
type: "label_selector",
selector: { role: "web" },
});

By load balancer and id

const existing = BetterStack.Cloud.LoadBalancerTarget.lookup({ loadBalancerId: "42", id: "7" });

loadBalancerId string required

The ID of the parent this load balancer belongs to.

type "server" | "label_selector" | string required

What the target points at. - server: One server. Send server_id and leave out selector. - label_selector: Every server whose metadata matches selector. Send selector and leave out server_id.

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.

selector LoadBalancerTargetSelector

The tags a server must have to receive traffic, as string pairs (a server must have every pair), for type: "label_selector". Leave it out for type: "server". Changing it replaces the target.

serverId string

The ID of the server to send traffic to. The server must be in the load balancer's team. A load balancer can have each server as a target once.

usePrivateIp boolean

Whether to send traffic to the servers' private IP on a network they share with the load balancer, instead of their public IP.

availabilityZone string always set

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

id string always set

The target's ID.

loadBalancerId string always set

The load balancer the target belongs to.

createdAt string

When the target was added.

selector string | LoadBalancerTargetSelector | null

The label selector of a label_selector target, as an object; null or absent for a server target. Should the API ever answer text that is not a JSON object, that text is kept as is.

serverId string | null

The ID of the server to send traffic to. The server must be in the load balancer's team. A load balancer can have each server as a target once.

type "server" | "label_selector"

What the target points at. - server: One server. Send server_id and leave out selector. - label_selector: Every server whose metadata matches selector. Send selector and leave out server_id.

updatedAt string

When the target was last updated.

usePrivateIp boolean

Whether to send traffic to the servers' private IP on a network they share with the load balancer, instead of their public IP.

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

id string required

The target's ID.

loadBalancerId string required

The load balancer the target belongs to.

availabilityZone string

Zone the load balancer lives in. Defaults to the credentials' zone.