Skip to content

chore(docs): move coder_parameter example #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 25, 2024
3 changes: 1 addition & 2 deletions docs/data-sources/git_auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ Use this data source to require users to authenticate with a Git provider prior
## Example Usage

```terraform
provider "coder" {
}
provider "coder" {}

data "coder_git_auth" "github" {
# Matches the ID of the git auth provider in Coder.
Expand Down
122 changes: 121 additions & 1 deletion docs/data-sources/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,127 @@ description: |-

Use this data source to configure editable options for workspaces.


## Example Usage

```terraform
provider "coder" {}

data "coder_parameter" "example" {
name = "Region"
description = "Specify a region to place your workspace."
mutable = false
type = "string"
default = "asia-central1-a"
option {
value = "us-central1-a"
name = "US Central"
icon = "/icon/usa.svg"
}
option {
value = "asia-central1-a"
name = "Asia"
icon = "/icon/asia.svg"
}
}

data "coder_parameter" "ami" {
name = "Machine Image"
description = <<-EOT
# Provide the machine image
See the [registry](https://container.registry.blah/namespace) for options.
EOT
option {
value = "ami-xxxxxxxx"
name = "Ubuntu"
icon = "/icon/ubuntu.svg"
}
}

data "coder_parameter" "is_public_instance" {
name = "Is public instance?"
type = "bool"
icon = "/icon/docker.svg"
default = false
}

data "coder_parameter" "cores" {
name = "CPU Cores"
type = "number"
icon = "/icon/cpu.svg"
default = 3
order = 10
}

data "coder_parameter" "disk_size" {
name = "Disk Size"
type = "number"
default = "5"
order = 8
validation {
# This can apply to number.
min = 0
max = 10
monotonic = "increasing"
}
}

data "coder_parameter" "cat_lives" {
name = "Cat Lives"
type = "number"
default = "9"
validation {
# This can apply to number.
min = 0
max = 10
monotonic = "decreasing"
}
}

data "coder_parameter" "fairy_tale" {
name = "Fairy Tale"
type = "string"
mutable = true
default = "Hansel and Gretel"
ephemeral = true
}

data "coder_parameter" "users" {
name = "system_users"
display_name = "System users"
type = "list(string)"
default = jsonencode(["root", "user1", "user2"])
}

data "coder_parameter" "home_volume_size" {
name = "Home Volume Size"
description = <<-EOF
How large should your home volume be?
EOF
type = "number"
default = 30
mutable = true
order = 3

option {
name = "30GB"
value = 30
}

option {
name = "60GB"
value = 60
}

option {
name = "100GB"
value = 100
}

validation {
monotonic = "increasing"
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
53 changes: 53 additions & 0 deletions docs/data-sources/workspace_tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,60 @@ description: |-

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

## Example Usage

```terraform
provider "coder" {}

data "coder_parameter" "os_selector" {
name = "os_selector"
display_name = "Operating System"
mutable = false

default = "osx"

option {
icon = "/icons/linux.png"
name = "Linux"
value = "linux"
}
option {
icon = "/icons/osx.png"
name = "OSX"
value = "osx"
}
option {
icon = "/icons/windows.png"
name = "Windows"
value = "windows"
}
}

data "coder_parameter" "feature_cache_enabled" {
name = "feature_cache_enabled"
display_name = "Enable cache?"
type = "bool"

default = false
}

data "coder_parameter" "feature_debug_enabled" {
name = "feature_debug_enabled"
display_name = "Enable debug?"
type = "bool"

default = true
}

data "coder_workspace_tags" "custom_workspace_tags" {
tags = {
"cluster" = "developers"
"os" = data.coder_parameter.os_selector.value
"debug" = "${data.coder_parameter.feature_debug_enabled.value}+12345"
"cache" = data.coder_parameter.feature_cache_enabled.value == "true" ? "nix-with-cache" : "no-cache"
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
3 changes: 1 addition & 2 deletions examples/data-sources/coder_git_auth/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
provider "coder" {
}
provider "coder" {}

data "coder_git_auth" "github" {
# Matches the ID of the git auth provider in Coder.
Expand Down
24 changes: 14 additions & 10 deletions provider/examples_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package provider_test

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/require"

"github.com/coder/terraform-provider-coder/provider"
)

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

resource.Test(t, resource.TestCase{
Providers: map[string]*schema.Provider{
"coder": provider.New(),
},
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: mustReadFile(t, "../examples/resources/"+testDir+"/resource.tf"),
}},
})
resourceTest(t, testDir)
})
}
}

func resourceTest(t *testing.T, testDir string) {
resource.Test(t, resource.TestCase{
Providers: map[string]*schema.Provider{
"coder": provider.New(),
},
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: mustReadFile(t, fmt.Sprintf("../examples/data-sources/%s/data-source.tf", testDir)),
}},
})
}

func mustReadFile(t *testing.T, path string) string {
content, err := os.ReadFile(path)
require.NoError(t, err)
Expand Down
Loading