Skip to content

Commit b73066b

Browse files
stirbymtojek
andauthored
chore(docs): move coder_parameter example (#243)
* moved coder_parameter * swapped test target, renamed parameter example file * make gen * removed coder agent examples from test * attempting data source testing * added git auth to test * reverted git auth test * Refactor examples_test.go * took a stab at expanding example test * added provider to coder_ap * manually reverted test changes --------- Co-authored-by: Marcin Tojek <marcin@coder.com>
1 parent d51a4a7 commit b73066b

File tree

7 files changed

+190
-15
lines changed

7 files changed

+190
-15
lines changed

docs/data-sources/git_auth.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Use this data source to require users to authenticate with a Git provider prior
1313
## Example Usage
1414

1515
```terraform
16-
provider "coder" {
17-
}
16+
provider "coder" {}
1817
1918
data "coder_git_auth" "github" {
2019
# Matches the ID of the git auth provider in Coder.

docs/data-sources/parameter.md

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,127 @@ description: |-
1010

1111
Use this data source to configure editable options for workspaces.
1212

13-
13+
## Example Usage
14+
15+
```terraform
16+
provider "coder" {}
17+
18+
data "coder_parameter" "example" {
19+
name = "Region"
20+
description = "Specify a region to place your workspace."
21+
mutable = false
22+
type = "string"
23+
default = "asia-central1-a"
24+
option {
25+
value = "us-central1-a"
26+
name = "US Central"
27+
icon = "/icon/usa.svg"
28+
}
29+
option {
30+
value = "asia-central1-a"
31+
name = "Asia"
32+
icon = "/icon/asia.svg"
33+
}
34+
}
35+
36+
data "coder_parameter" "ami" {
37+
name = "Machine Image"
38+
description = <<-EOT
39+
# Provide the machine image
40+
See the [registry](https://container.registry.blah/namespace) for options.
41+
EOT
42+
option {
43+
value = "ami-xxxxxxxx"
44+
name = "Ubuntu"
45+
icon = "/icon/ubuntu.svg"
46+
}
47+
}
48+
49+
data "coder_parameter" "is_public_instance" {
50+
name = "Is public instance?"
51+
type = "bool"
52+
icon = "/icon/docker.svg"
53+
default = false
54+
}
55+
56+
data "coder_parameter" "cores" {
57+
name = "CPU Cores"
58+
type = "number"
59+
icon = "/icon/cpu.svg"
60+
default = 3
61+
order = 10
62+
}
63+
64+
data "coder_parameter" "disk_size" {
65+
name = "Disk Size"
66+
type = "number"
67+
default = "5"
68+
order = 8
69+
validation {
70+
# This can apply to number.
71+
min = 0
72+
max = 10
73+
monotonic = "increasing"
74+
}
75+
}
76+
77+
data "coder_parameter" "cat_lives" {
78+
name = "Cat Lives"
79+
type = "number"
80+
default = "9"
81+
validation {
82+
# This can apply to number.
83+
min = 0
84+
max = 10
85+
monotonic = "decreasing"
86+
}
87+
}
88+
89+
data "coder_parameter" "fairy_tale" {
90+
name = "Fairy Tale"
91+
type = "string"
92+
mutable = true
93+
default = "Hansel and Gretel"
94+
ephemeral = true
95+
}
96+
97+
data "coder_parameter" "users" {
98+
name = "system_users"
99+
display_name = "System users"
100+
type = "list(string)"
101+
default = jsonencode(["root", "user1", "user2"])
102+
}
103+
104+
data "coder_parameter" "home_volume_size" {
105+
name = "Home Volume Size"
106+
description = <<-EOF
107+
How large should your home volume be?
108+
EOF
109+
type = "number"
110+
default = 30
111+
mutable = true
112+
order = 3
113+
114+
option {
115+
name = "30GB"
116+
value = 30
117+
}
118+
119+
option {
120+
name = "60GB"
121+
value = 60
122+
}
123+
124+
option {
125+
name = "100GB"
126+
value = 100
127+
}
128+
129+
validation {
130+
monotonic = "increasing"
131+
}
132+
}
133+
```
14134

15135
<!-- schema generated by tfplugindocs -->
16136
## Schema

docs/data-sources/workspace_tags.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,60 @@ description: |-
1010

1111
Use this data source to configure workspace tags to select provisioners.
1212

13+
## Example Usage
1314

15+
```terraform
16+
provider "coder" {}
17+
18+
data "coder_parameter" "os_selector" {
19+
name = "os_selector"
20+
display_name = "Operating System"
21+
mutable = false
22+
23+
default = "osx"
24+
25+
option {
26+
icon = "/icons/linux.png"
27+
name = "Linux"
28+
value = "linux"
29+
}
30+
option {
31+
icon = "/icons/osx.png"
32+
name = "OSX"
33+
value = "osx"
34+
}
35+
option {
36+
icon = "/icons/windows.png"
37+
name = "Windows"
38+
value = "windows"
39+
}
40+
}
41+
42+
data "coder_parameter" "feature_cache_enabled" {
43+
name = "feature_cache_enabled"
44+
display_name = "Enable cache?"
45+
type = "bool"
46+
47+
default = false
48+
}
49+
50+
data "coder_parameter" "feature_debug_enabled" {
51+
name = "feature_debug_enabled"
52+
display_name = "Enable debug?"
53+
type = "bool"
54+
55+
default = true
56+
}
57+
58+
data "coder_workspace_tags" "custom_workspace_tags" {
59+
tags = {
60+
"cluster" = "developers"
61+
"os" = data.coder_parameter.os_selector.value
62+
"debug" = "${data.coder_parameter.feature_debug_enabled.value}+12345"
63+
"cache" = data.coder_parameter.feature_cache_enabled.value == "true" ? "nix-with-cache" : "no-cache"
64+
}
65+
}
66+
```
1467

1568
<!-- schema generated by tfplugindocs -->
1669
## Schema

examples/data-sources/coder_git_auth/data-source.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
provider "coder" {
2-
}
1+
provider "coder" {}
32

43
data "coder_git_auth" "github" {
54
# Matches the ID of the git auth provider in Coder.

provider/examples_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package provider_test
22

33
import (
4+
"fmt"
45
"os"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
"github.com/stretchr/testify/require"
10-
1111
"github.com/coder/terraform-provider-coder/provider"
1212
)
1313

@@ -22,19 +22,23 @@ func TestExamples(t *testing.T) {
2222
testDir := testDir
2323
t.Parallel()
2424

25-
resource.Test(t, resource.TestCase{
26-
Providers: map[string]*schema.Provider{
27-
"coder": provider.New(),
28-
},
29-
IsUnitTest: true,
30-
Steps: []resource.TestStep{{
31-
Config: mustReadFile(t, "../examples/resources/"+testDir+"/resource.tf"),
32-
}},
33-
})
25+
resourceTest(t, testDir)
3426
})
3527
}
3628
}
3729

30+
func resourceTest(t *testing.T, testDir string) {
31+
resource.Test(t, resource.TestCase{
32+
Providers: map[string]*schema.Provider{
33+
"coder": provider.New(),
34+
},
35+
IsUnitTest: true,
36+
Steps: []resource.TestStep{{
37+
Config: mustReadFile(t, fmt.Sprintf("../examples/data-sources/%s/data-source.tf", testDir)),
38+
}},
39+
})
40+
}
41+
3842
func mustReadFile(t *testing.T, path string) string {
3943
content, err := os.ReadFile(path)
4044
require.NoError(t, err)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy