-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateVM.ts
99 lines (93 loc) · 2.32 KB
/
createVM.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import * as pulumi from "@pulumi/pulumi";
import * as proxmox from "@muhlba91/pulumi-proxmoxve";
type VMConfiguration = {
name: string;
ipAddress: string;
vCpu: 1 | 2 | 3 | 4;
vmId?: number;
minMemory?: number;
maxMemory?: number;
onBoot?: boolean;
dataStore?: string;
diskSize?: number;
templateId?: number;
gateway?: string;
}
const config = new pulumi.Config();
const stack = pulumi.getStack();
let node = ''
stack === 'main' ? node = 'pve-main' : node = 'pve';
const provider = new proxmox.Provider('proxmox', {
virtualEnvironment: {
endpoint: config.require('PROXMOX_VE_ENDPOINT'),
insecure: config.requireBoolean('PROXMOX_VE_INSECURE'),
username: config.require('PROXMOX_VE_USERNAME'),
password: config.require('PROXMOX_VE_PASSWORD'),
}
});
export function createVM(configuration: VMConfiguration) {
const virtualMachine = new proxmox.vm.VirtualMachine(`${configuration.name.replace(/\s+/g, '-').toLowerCase()}`, {
nodeName: node,
vmId: configuration.vmId || undefined,
agent: {
enabled: true, // toggles checking for ip addresses through qemu-guest-agent
},
cpu: {
cores: configuration.vCpu,
sockets: 1,
},
clone: {
nodeName: node,
vmId: configuration.templateId || 900,
full: true,
},
disks: [
{
interface: 'scsi0',
datastoreId: configuration.dataStore || 'fast-storage',
size: configuration.diskSize || 45,
ssd: true,
discard: "on",
},
],
memory: {
dedicated: configuration.maxMemory || 1024,
floating: configuration.minMemory || 1024,
},
name: configuration.name,
vga: {
enabled: true,
type: "serial0"
},
networkDevices: [
{
bridge: 'vmbr0',
model: 'virtio',
},
],
onBoot: configuration.onBoot || false,
initialization: {
type: 'nocloud',
datastoreId: 'local-lvm',
ipConfigs: [
{
ipv4: {
address: configuration.ipAddress,
gateway: configuration.gateway || '10.10.1.1',
},
},
],
userAccount: {
username: 'agluck',
password: config.require('PASSWORD'),
keys: [
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILtnMgEAFNMutvv1/FnR6s4njCGB2RdXt3fD8QbCRLww andrew-macbook-pro',
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFpso6EJmgJLnJmCRCKs5HiAC0blLMiKVyGnhI3/Gktj Andrew Mobile'
]
},
},
},
{
provider:provider
});
}