Part 2: Adopt the Default Network
Your console already has a default network on VLAN 1, with your own devices on it. In this part you’ll declare it in the Stack and adopt it, without changing anything about it.
Find its settings
Section titled “Find its settings”In the Network app, open Settings → Networks → Default. Note its name, gateway IP and subnet, DHCP range, lease time and domain name, and whether auto-scale and cellular backup are on.
Declare it
Section titled “Declare it”Add the default network with your console’s values. These are a new console’s:
import * as UnifiNetwork from "@alchemy-unifi/network";import * as Alchemy from "alchemy";import * as Effect from "effect/Effect";
export default Alchemy.Stack( "UnifiLab", { providers: UnifiNetwork.providers(), state: UnifiNetwork.state() }, Effect.gen(function* () { const lab = yield* UnifiNetwork.Network("lab", { management: "GATEWAY", name: "Lab", vlanId: 50, enabled: true, cellularBackupEnabled: false, internetAccessEnabled: true, isolationEnabled: false, zone: UnifiNetwork.FirewallZone.INTERNAL, ipv4Configuration: { autoScaleEnabled: false, hostIpAddress: "192.168.50.1", prefixLength: 24, dhcpConfiguration: { mode: "SERVER", ipAddressRange: { start: "192.168.50.100", stop: "192.168.50.250" }, leaseTimeSeconds: 86400, pingConflictDetectionEnabled: true, }, }, }); yield* UnifiNetwork.Network("default", { management: "GATEWAY", name: "Default", vlanId: 1, enabled: true, cellularBackupEnabled: true, internetAccessEnabled: true, isolationEnabled: false, zone: UnifiNetwork.FirewallZone.INTERNAL, ipv4Configuration: { autoScaleEnabled: true, hostIpAddress: "192.168.1.1", prefixLength: 24, dhcpConfiguration: { mode: "SERVER", ipAddressRange: { start: "192.168.1.6", stop: "192.168.1.254" }, leaseTimeSeconds: 86400, domainName: "localdomain", pingConflictDetectionEnabled: true, }, }, }); return { labNetworkId: lab.networkId }; }),);Keep it if you remove it
Section titled “Keep it if you remove it”Wrap it in RemovalPolicy.retain(), so removing it from the Stack, or destroying the Stack, never touches it:
import * as UnifiNetwork from "@alchemy-unifi/network";import * as Alchemy from "alchemy";import * as RemovalPolicy from "alchemy/RemovalPolicy";import * as Effect from "effect/Effect";
export default Alchemy.Stack( "UnifiLab", { providers: UnifiNetwork.providers(), state: UnifiNetwork.state() }, Effect.gen(function* () { const lab = yield* UnifiNetwork.Network("lab", { management: "GATEWAY", name: "Lab", vlanId: 50, enabled: true, cellularBackupEnabled: false, internetAccessEnabled: true, isolationEnabled: false, zone: UnifiNetwork.FirewallZone.INTERNAL, ipv4Configuration: { autoScaleEnabled: false, hostIpAddress: "192.168.50.1", prefixLength: 24, dhcpConfiguration: { mode: "SERVER", ipAddressRange: { start: "192.168.50.100", stop: "192.168.50.250" }, leaseTimeSeconds: 86400, pingConflictDetectionEnabled: true, }, }, }); yield* UnifiNetwork.Network("default", { management: "GATEWAY", name: "Default", vlanId: 1, enabled: true, cellularBackupEnabled: true, internetAccessEnabled: true, isolationEnabled: false, zone: UnifiNetwork.FirewallZone.INTERNAL, ipv4Configuration: { autoScaleEnabled: true, hostIpAddress: "192.168.1.1", prefixLength: 24, dhcpConfiguration: { mode: "SERVER", ipAddressRange: { start: "192.168.1.6", stop: "192.168.1.254" }, leaseTimeSeconds: 86400, domainName: "localdomain", pingConflictDetectionEnabled: true, }, }, }); }).pipe(RemovalPolicy.retain()); return { labNetworkId: lab.networkId }; }),);The default network is never deleted anyway, but retain() says so in the code, and works for anything else you adopt.
Plan the adoption
Section titled “Plan the adoption”npx alchemy plan --stage home --adoptpnpm exec alchemy plan --stage home --adoptyarn alchemy plan --stage home --adopt--adopt lets Alchemy take over an object that already exists, matched by its natural key: for a network, its VLAN ID. The plan shows the default network as adopted. If it also shows an update, your props differ from the console: fix them and plan again, until the default network has no update.
Adopt it
Section titled “Adopt it”npx alchemy deploy --stage home --adoptpnpm exec alchemy deploy --stage home --adoptyarn alchemy deploy --stage home --adoptWithout --adopt, a deploy stops rather than take over an existing object.
You adopted an existing network without changing it. The same steps work for Wi-Fi, zones and policies you made in the UI; see Adoption. Next, in Part 3, you’ll give the lab its own Wi-Fi.