Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Add Exoscale instance type Module #88

Merged
merged 11 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .icons/exoscale.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .images/exoscale-instance-custom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .images/exoscale-instance-exclude.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .images/exoscale-instance-types.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions exoscale-instance-type/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
display_name: exoscale-instance-type
description: A parameter with human readable exoscale instance names
icon: ../.icons/exoscale.svg
maintainer_github: WhizUs
verified: false
tags: [helper, parameter, instances, exoscale]
---

# exoscale-instance-type

A parameter with all Exoscale instance types. This allows developers to select
their desired virtuell machine for the workspace.

Customize the preselected parameter value:

```hcl
module "exoscale-instance-type" {
source = "https://registry.coder.com/modules/exoscale-instance-type"
default = "standard.medium"
}

resource "exoscale_compute_instance" "instance" {
type = module.exoscale-instance-type.value
...
}

resource "coder_metadata" "workspace_info" {
item {
key = "instance type"
value = module.exoscale-instance-type.name
}
}
```

![Exoscale instance types](../.images/exoscale-instance-types.png)

## Examples

### Customize type

Change the display name a type using the corresponding maps:

```hcl
module "exoscale-instance-type" {
source = "https://registry.coder.com/modules/exoscale-instance-type"
default = "standard.medium"
custom_names = {
"standard.medium": "Mittlere Instanz" # German translation
}
custom_descriptions = {
"standard.medium": "4 GB Arbeitsspeicher, 2 Kerne, 10 - 400 GB Festplatte" # German translation
}
}

resource "exoscale_compute_instance" "instance" {
type = module.exoscale-instance-type.value
...
}

resource "coder_metadata" "workspace_info" {
item {
key = "instance type"
value = module.exoscale-instance-type.name
}
}
```

![Exoscale instance types Custom](../.images/exoscale-instance-custom.png)

### Use category and exlude type

Show only gpu1 types

```hcl
module "exoscale-instance-type" {
source = "https://registry.coder.com/modules/exoscale-instance-type"
default = "gpu.large"
type_category = ["gpu"]
exclude = [
"gpu2.small",
"gpu2.medium",
"gpu2.large",
"gpu2.huge",
"gpu3.small",
"gpu3.medium",
"gpu3.large",
"gpu3.huge"
]
}

resource "exoscale_compute_instance" "instance" {
type = module.exoscale-instance-type.value
...
}

resource "coder_metadata" "workspace_info" {
item {
key = "instance type"
value = module.exoscale-instance-type.name
}
}
```

![Exoscale instance types category and exclude](../.images/exoscale-instance-exclude.png)

## Related templates

A related exoscale template will be provided soon.
34 changes: 34 additions & 0 deletions exoscale-instance-type/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, it } from "bun:test";
import {
runTerraformApply,
runTerraformInit,
testRequiredVariables,
} from "../test";

describe("exoscale-instance-type", async () => {
await runTerraformInit(import.meta.dir);

testRequiredVariables(import.meta.dir, {});

it("default output", async () => {
const state = await runTerraformApply(import.meta.dir, {});
expect(state.outputs.value.value).toBe("");
});

it("customized default", async () => {
const state = await runTerraformApply(import.meta.dir, {
default: "gpu3.huge",
type_category: `["gpu", "cpu"]`,
});
expect(state.outputs.value.value).toBe("gpu3.huge");
});

it("fails because of wrong categroy definition", async () => {
expect(async () => {
await runTerraformApply(import.meta.dir, {
default: "gpu3.huge",
// type_category: ["standard"] is standard
});
}).toThrow('default value "gpu3.huge" must be defined as one of options');
});
});
Loading