0

Create a VPC

by
Published Oct 17, 2025

Create a new VPC and optionally associated VPC Subnets.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Create a VPC
7
 * Create a new VPC and optionally associated VPC Subnets.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  body: {} & { subnets?: {} } & {
13
    created?: string;
14
    description?: string;
15
    id?: number;
16
    label?: string;
17
    region?: string;
18
    subnets?: {
19
      created?: string;
20
      id?: number;
21
      ipv4?: string;
22
      label?: string;
23
      linodes?: {
24
        id?: number;
25
        interfaces?: { active?: false | true; id?: number }[];
26
      }[];
27
      updated?: string;
28
    }[];
29
    updated?: string;
30
  },
31
) {
32
  const url = new URL(`https://api.linode.com/${apiVersion}/vpcs`);
33

34
  const response = await fetch(url, {
35
    method: "POST",
36
    headers: {
37
      "Content-Type": "application/json",
38
      Authorization: "Bearer " + auth.token,
39
    },
40
    body: JSON.stringify(body),
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48