Skip to content

Commit e090e79

Browse files
author
masterwendu
authored
Add Exoscale instance type Module (coder#88)
1 parent 24bf54d commit e090e79

File tree

6 files changed

+422
-0
lines changed

6 files changed

+422
-0
lines changed

.images/exoscale-instance-custom.png

92.6 KB
Loading

.images/exoscale-instance-exclude.png

44.9 KB
Loading

.images/exoscale-instance-types.png

91.6 KB
Loading

exoscale-instance-type/README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
display_name: exoscale-instance-type
3+
description: A parameter with human readable exoscale instance names
4+
icon: ../.icons/exoscale.svg
5+
maintainer_github: WhizUs
6+
verified: false
7+
tags: [helper, parameter, instances, exoscale]
8+
---
9+
10+
# exoscale-instance-type
11+
12+
A parameter with all Exoscale instance types. This allows developers to select
13+
their desired virtuell machine for the workspace.
14+
15+
Customize the preselected parameter value:
16+
17+
```hcl
18+
module "exoscale-instance-type" {
19+
source = "https://registry.coder.com/modules/exoscale-instance-type"
20+
default = "standard.medium"
21+
}
22+
23+
resource "exoscale_compute_instance" "instance" {
24+
type = module.exoscale-instance-type.value
25+
...
26+
}
27+
28+
resource "coder_metadata" "workspace_info" {
29+
item {
30+
key = "instance type"
31+
value = module.exoscale-instance-type.name
32+
}
33+
}
34+
```
35+
36+
![Exoscale instance types](../.images/exoscale-instance-types.png)
37+
38+
## Examples
39+
40+
### Customize type
41+
42+
Change the display name a type using the corresponding maps:
43+
44+
```hcl
45+
module "exoscale-instance-type" {
46+
source = "https://registry.coder.com/modules/exoscale-instance-type"
47+
default = "standard.medium"
48+
custom_names = {
49+
"standard.medium": "Mittlere Instanz" # German translation
50+
}
51+
custom_descriptions = {
52+
"standard.medium": "4 GB Arbeitsspeicher, 2 Kerne, 10 - 400 GB Festplatte" # German translation
53+
}
54+
}
55+
56+
resource "exoscale_compute_instance" "instance" {
57+
type = module.exoscale-instance-type.value
58+
...
59+
}
60+
61+
resource "coder_metadata" "workspace_info" {
62+
item {
63+
key = "instance type"
64+
value = module.exoscale-instance-type.name
65+
}
66+
}
67+
```
68+
69+
![Exoscale instance types Custom](../.images/exoscale-instance-custom.png)
70+
71+
### Use category and exlude type
72+
73+
Show only gpu1 types
74+
75+
```hcl
76+
module "exoscale-instance-type" {
77+
source = "https://registry.coder.com/modules/exoscale-instance-type"
78+
default = "gpu.large"
79+
type_category = ["gpu"]
80+
exclude = [
81+
"gpu2.small",
82+
"gpu2.medium",
83+
"gpu2.large",
84+
"gpu2.huge",
85+
"gpu3.small",
86+
"gpu3.medium",
87+
"gpu3.large",
88+
"gpu3.huge"
89+
]
90+
}
91+
92+
resource "exoscale_compute_instance" "instance" {
93+
type = module.exoscale-instance-type.value
94+
...
95+
}
96+
97+
resource "coder_metadata" "workspace_info" {
98+
item {
99+
key = "instance type"
100+
value = module.exoscale-instance-type.name
101+
}
102+
}
103+
```
104+
105+
![Exoscale instance types category and exclude](../.images/exoscale-instance-exclude.png)
106+
107+
## Related templates
108+
109+
A related exoscale template will be provided soon.

exoscale-instance-type/main.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
runTerraformApply,
4+
runTerraformInit,
5+
testRequiredVariables,
6+
} from "../test";
7+
8+
describe("exoscale-instance-type", async () => {
9+
await runTerraformInit(import.meta.dir);
10+
11+
testRequiredVariables(import.meta.dir, {});
12+
13+
it("default output", async () => {
14+
const state = await runTerraformApply(import.meta.dir, {});
15+
expect(state.outputs.value.value).toBe("");
16+
});
17+
18+
it("customized default", async () => {
19+
const state = await runTerraformApply(import.meta.dir, {
20+
default: "gpu3.huge",
21+
type_category: `["gpu", "cpu"]`,
22+
});
23+
expect(state.outputs.value.value).toBe("gpu3.huge");
24+
});
25+
26+
it("fails because of wrong categroy definition", async () => {
27+
expect(async () => {
28+
await runTerraformApply(import.meta.dir, {
29+
default: "gpu3.huge",
30+
// type_category: ["standard"] is standard
31+
});
32+
}).toThrow('default value "gpu3.huge" must be defined as one of options');
33+
});
34+
});

0 commit comments

Comments
 (0)