Skip to content

Commit 07d7de3

Browse files
authored
feat: Add "coder_parameter" to expose richer parameter types (#57)
* Add parameter * add parameter package * Use mapstructure for parsing parameters * Remove unused lib * Change to mutable
1 parent 3778c63 commit 07d7de3

File tree

6 files changed

+731
-2
lines changed

6 files changed

+731
-2
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Terraform Provider Coder
1+
# terraform-provider-coder
22

3-
> This works with a closed-alpha of [Coder](https://coder.com). For access, contact [support@coder.com](mailto:support@coder.com).
3+
See [Coder](https://github.com/coder/coder).

Diff for: docs/data-sources/parameter.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "coder_parameter Data Source - terraform-provider-coder"
4+
subcategory: ""
5+
description: |-
6+
Use this data source to configure editable options for workspaces.
7+
---
8+
9+
# coder_parameter (Data Source)
10+
11+
Use this data source to configure editable options for workspaces.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `name` (String) The name of the parameter as it will appear in the interface. If this is changed, developers will be re-prompted for a new value.
21+
22+
### Optional
23+
24+
- `default` (String) A default value for the parameter.
25+
- `description` (String) Describe what this parameter does.
26+
- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icon. Use a built-in icon with `data.coder_workspace.me.access_url + "/icon/<path>"`.
27+
- `mutable` (Boolean) Whether this value can be changed after workspace creation. This can be destructive for values like region, so use with caution!
28+
- `option` (Block List, Max: 64) Each "option" block defines a value for a user to select from. (see [below for nested schema](#nestedblock--option))
29+
- `type` (String) The type of this parameter. Must be one of: "number", "string", or "bool".
30+
- `validation` (Block List, Max: 1) Validate the input of a parameter. (see [below for nested schema](#nestedblock--validation))
31+
32+
### Read-Only
33+
34+
- `id` (String) The ID of this resource.
35+
- `value` (String) The output value of the parameter.
36+
37+
<a id="nestedblock--option"></a>
38+
### Nested Schema for `option`
39+
40+
Required:
41+
42+
- `name` (String) The display name of this value in the UI.
43+
- `value` (String) The value of this option set on the parameter if selected.
44+
45+
Optional:
46+
47+
- `description` (String) Describe what selecting this value does.
48+
- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icon. Use a built-in icon with `data.coder_workspace.me.access_url + "/icon/<path>"`.
49+
50+
51+
<a id="nestedblock--validation"></a>
52+
### Nested Schema for `validation`
53+
54+
Optional:
55+
56+
- `max` (Number) The maximum of a number parameter.
57+
- `min` (Number) The minimum of a number parameter.
58+
- `regex` (String) A regex for the input parameter to match against.
59+
60+

Diff for: examples/resources/coder_parameter/resource.tf

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
data "coder_parameter" "example" {
2+
display_name = "Region"
3+
description = "Specify a region to place your workspace."
4+
immutable = true
5+
type = "string"
6+
option {
7+
value = "us-central1-a"
8+
label = "US Central"
9+
icon = "/icon/usa.svg"
10+
}
11+
option {
12+
value = "asia-central1-a"
13+
label = "Asia"
14+
icon = "/icon/asia.svg"
15+
}
16+
}
17+
18+
data "coder_parameter" "ami" {
19+
display_name = "Machine Image"
20+
option {
21+
value = "ami-xxxxxxxx"
22+
label = "Ubuntu"
23+
icon = "/icon/ubuntu.svg"
24+
}
25+
}
26+
27+
data "coder_parameter" "image" {
28+
display_name = "Docker Image"
29+
icon = "/icon/docker.svg"
30+
type = "bool"
31+
}
32+
33+
data "coder_parameter" "cores" {
34+
display_name = "CPU Cores"
35+
icon = "/icon/"
36+
}
37+
38+
data "coder_parameter" "disk_size" {
39+
display_name = "Disk Size"
40+
type = "number"
41+
validation {
42+
# This can apply to number and string types.
43+
min = 0
44+
max = 10
45+
}
46+
}

0 commit comments

Comments
 (0)