@puls-dev/hcloud 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/dist/api.d.ts +14 -0
- package/dist/api.js +211 -0
- package/dist/firewall.d.ts +27 -0
- package/dist/firewall.js +133 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +27 -0
- package/dist/list.d.ts +2 -0
- package/dist/list.js +45 -0
- package/dist/network.d.ts +20 -0
- package/dist/network.js +80 -0
- package/dist/plugin.d.ts +9 -0
- package/dist/plugin.js +43 -0
- package/dist/server.d.ts +41 -0
- package/dist/server.js +315 -0
- package/dist/server.test.d.ts +1 -0
- package/dist/server.test.js +263 -0
- package/dist/ssh_key.d.ts +21 -0
- package/dist/ssh_key.js +87 -0
- package/dist/types/hcloud.d.ts +31 -0
- package/dist/types/hcloud.js +31 -0
- package/package.json +19 -0
package/dist/ssh_key.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { BaseBuilder } from '@puls-dev/core';
|
|
2
|
+
import { Output } from '@puls-dev/core';
|
|
3
|
+
import { getHCloudApi } from './api.js';
|
|
4
|
+
export class SSHKeyBuilder extends BaseBuilder {
|
|
5
|
+
out = {
|
|
6
|
+
id: new Output(),
|
|
7
|
+
fingerprint: new Output(),
|
|
8
|
+
};
|
|
9
|
+
_publicKey;
|
|
10
|
+
keyId;
|
|
11
|
+
log(msg) {
|
|
12
|
+
console.log(` 🔑 [HCloud.SSHKey] ${msg}`);
|
|
13
|
+
}
|
|
14
|
+
constructor(name) {
|
|
15
|
+
super(name);
|
|
16
|
+
this.discoveryPromise = this.discoverKey(name);
|
|
17
|
+
}
|
|
18
|
+
async discoverKey(name) {
|
|
19
|
+
const api = getHCloudApi();
|
|
20
|
+
const data = await api.get('/ssh_keys');
|
|
21
|
+
const match = data.ssh_keys.find(k => k.name === name) ?? null;
|
|
22
|
+
if (match) {
|
|
23
|
+
this.keyId = match.id;
|
|
24
|
+
this.out.id.resolve(match.id);
|
|
25
|
+
this.out.fingerprint.resolve(match.fingerprint);
|
|
26
|
+
}
|
|
27
|
+
return match;
|
|
28
|
+
}
|
|
29
|
+
publicKey(key) {
|
|
30
|
+
this._publicKey = key.trim();
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
getDiff(existing) {
|
|
34
|
+
const diffs = [];
|
|
35
|
+
if (this._publicKey && existing && existing.public_key.trim() !== this._publicKey) {
|
|
36
|
+
diffs.push({ field: "publicKey", declared: this._publicKey, live: existing.public_key });
|
|
37
|
+
}
|
|
38
|
+
return diffs;
|
|
39
|
+
}
|
|
40
|
+
async deploy() {
|
|
41
|
+
const api = getHCloudApi();
|
|
42
|
+
const existing = await this.discoveryPromise;
|
|
43
|
+
if (!existing) {
|
|
44
|
+
if (!this._publicKey) {
|
|
45
|
+
throw new Error(`Cannot create SSH Key '${this.name}': publicKey must be specified.`);
|
|
46
|
+
}
|
|
47
|
+
this.log(`Creating SSH Key...`);
|
|
48
|
+
const res = await api.post('/ssh_keys', {
|
|
49
|
+
name: this.name,
|
|
50
|
+
public_key: this._publicKey,
|
|
51
|
+
});
|
|
52
|
+
this.keyId = res.ssh_key.id;
|
|
53
|
+
this.out.id.resolve(res.ssh_key.id);
|
|
54
|
+
this.out.fingerprint.resolve(res.ssh_key.fingerprint);
|
|
55
|
+
this.log(`Created SSH Key with ID ${this.keyId}`);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const diffs = this.getDiff(existing);
|
|
59
|
+
if (diffs.length > 0) {
|
|
60
|
+
this.log(`SSH Key public key has drifted. Re-creating...`);
|
|
61
|
+
await api.delete(`/ssh_keys/${this.keyId}`);
|
|
62
|
+
const res = await api.post('/ssh_keys', {
|
|
63
|
+
name: this.name,
|
|
64
|
+
public_key: this._publicKey,
|
|
65
|
+
});
|
|
66
|
+
this.keyId = res.ssh_key.id;
|
|
67
|
+
this.out.id.resolve(res.ssh_key.id);
|
|
68
|
+
this.out.fingerprint.resolve(res.ssh_key.fingerprint);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this.log(`SSH Key already exists and is up to date.`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async destroy() {
|
|
76
|
+
const existing = await this.discoveryPromise;
|
|
77
|
+
if (existing) {
|
|
78
|
+
this.log(`Deleting SSH Key...`);
|
|
79
|
+
const api = getHCloudApi();
|
|
80
|
+
await api.delete(`/ssh_keys/${this.keyId}`);
|
|
81
|
+
this.log(`Deleted SSH Key.`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.log(`SSH Key does not exist. Skipping deletion.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const OS_IMAGE: {
|
|
2
|
+
readonly UBUNTU_24_04: "ubuntu-24.04";
|
|
3
|
+
readonly UBUNTU_22_04: "ubuntu-22.04";
|
|
4
|
+
readonly DEBIAN_12: "debian-12";
|
|
5
|
+
readonly DEBIAN_11: "debian-11";
|
|
6
|
+
readonly ROCKY_9: "rocky-9";
|
|
7
|
+
readonly ALMALINUX_9: "almalinux-9";
|
|
8
|
+
};
|
|
9
|
+
export declare const LOCATION: {
|
|
10
|
+
readonly NBG1: "nbg1";
|
|
11
|
+
readonly FSN1: "fsn1";
|
|
12
|
+
readonly HEL1: "hel1";
|
|
13
|
+
readonly ASH: "ash";
|
|
14
|
+
readonly HIL: "hil";
|
|
15
|
+
};
|
|
16
|
+
export declare const SERVER_TYPE: {
|
|
17
|
+
readonly CX22: "cx22";
|
|
18
|
+
readonly CPX11: "cpx11";
|
|
19
|
+
readonly CPX21: "cpx21";
|
|
20
|
+
readonly CPX31: "cpx31";
|
|
21
|
+
readonly CPX41: "cpx41";
|
|
22
|
+
readonly CPX51: "cpx51";
|
|
23
|
+
readonly CAX11: "cax11";
|
|
24
|
+
readonly CAX21: "cax21";
|
|
25
|
+
readonly CAX31: "cax31";
|
|
26
|
+
readonly CAX41: "cax41";
|
|
27
|
+
};
|
|
28
|
+
export declare const NETWORK: {
|
|
29
|
+
readonly ANY: "0.0.0.0/0";
|
|
30
|
+
readonly ANY_V6: "::/0";
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const OS_IMAGE = {
|
|
2
|
+
UBUNTU_24_04: "ubuntu-24.04",
|
|
3
|
+
UBUNTU_22_04: "ubuntu-22.04",
|
|
4
|
+
DEBIAN_12: "debian-12",
|
|
5
|
+
DEBIAN_11: "debian-11",
|
|
6
|
+
ROCKY_9: "rocky-9",
|
|
7
|
+
ALMALINUX_9: "almalinux-9",
|
|
8
|
+
};
|
|
9
|
+
export const LOCATION = {
|
|
10
|
+
NBG1: "nbg1", // Nuremberg, Germany
|
|
11
|
+
FSN1: "fsn1", // Falkenstein, Germany
|
|
12
|
+
HEL1: "hel1", // Helsinki, Finland
|
|
13
|
+
ASH: "ash", // Ashburn, Virginia, USA
|
|
14
|
+
HIL: "hil", // Hillsboro, Oregon, USA
|
|
15
|
+
};
|
|
16
|
+
export const SERVER_TYPE = {
|
|
17
|
+
CX22: "cx22", // 2 vCPU, 4 GB RAM (Intel)
|
|
18
|
+
CPX11: "cpx11", // 2 vCPU, 2 GB RAM (AMD)
|
|
19
|
+
CPX21: "cpx21", // 3 vCPU, 4 GB RAM (AMD)
|
|
20
|
+
CPX31: "cpx31", // 4 vCPU, 8 GB RAM (AMD)
|
|
21
|
+
CPX41: "cpx41", // 8 vCPU, 16 GB RAM (AMD)
|
|
22
|
+
CPX51: "cpx51", // 16 vCPU, 32 GB RAM (AMD)
|
|
23
|
+
CAX11: "cax11", // 2 vCPU, 4 GB RAM (Ampere ARM)
|
|
24
|
+
CAX21: "cax21", // 4 vCPU, 8 GB RAM (Ampere ARM)
|
|
25
|
+
CAX31: "cax31", // 8 vCPU, 16 GB RAM (Ampere ARM)
|
|
26
|
+
CAX41: "cax41", // 16 vCPU, 32 GB RAM (Ampere ARM)
|
|
27
|
+
};
|
|
28
|
+
export const NETWORK = {
|
|
29
|
+
ANY: "0.0.0.0/0",
|
|
30
|
+
ANY_V6: "::/0",
|
|
31
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@puls-dev/hcloud",
|
|
3
|
+
"version": "0.5.3",
|
|
4
|
+
"description": "Hetzner Cloud (HCloud) Provider for Puls IaC",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"test": "find src -name '*.test.ts' | xargs tsx --test --test-concurrency=1"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@puls-dev/core": "*"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
]
|
|
19
|
+
}
|