Skip to content

feat: Add coder_provisioner resource for attributes from the host #36

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 2 commits into from
Aug 9, 2022
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
24 changes: 24 additions & 0 deletions docs/data-sources/provisioner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "coder_provisioner Data Source - terraform-provider-coder"
subcategory: ""
description: |-
Use this data source to get information about the Coder provisioner.
---

# coder_provisioner (Data Source)

Use this data source to get information about the Coder provisioner.



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

### Read-Only

- `arch` (String) The architecture of the host. This exposes `runtime.GOARCH` (see https://pkg.go.dev/runtime#pkg-constants).
- `id` (String) The ID of this resource.
- `os` (String) The operating system of the host. This exposes `runtime.GOOS` (see https://pkg.go.dev/runtime#pkg-constants).


23 changes: 23 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"
"os"
"reflect"
"runtime"
"strings"

"github.com/google/uuid"
Expand Down Expand Up @@ -150,6 +151,28 @@ func New() *schema.Provider {
},
},
},
"coder_provisioner": {
Description: "Use this data source to get information about the Coder provisioner.",
ReadContext: func(c context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
rd.SetId(uuid.NewString())
rd.Set("os", runtime.GOOS)
rd.Set("arch", runtime.GOARCH)

return nil
},
Schema: map[string]*schema.Schema{
"os": {
Type: schema.TypeString,
Computed: true,
Description: "The operating system of the host. This exposes `runtime.GOOS` (see https://pkg.go.dev/runtime#pkg-constants).",
},
"arch": {
Type: schema.TypeString,
Computed: true,
Description: "The architecture of the host. This exposes `runtime.GOARCH` (see https://pkg.go.dev/runtime#pkg-constants).",
},
},
},
},
ResourcesMap: map[string]*schema.Resource{
"coder_agent": {
Expand Down
28 changes: 28 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provider_test

import (
"runtime"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -52,6 +53,33 @@ func TestWorkspace(t *testing.T) {
})
}

func TestProvisioner(t *testing.T) {
resource.Test(t, resource.TestCase{
Providers: map[string]*schema.Provider{
"coder": provider.New(),
},
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: `
provider "coder" {
}
data "coder_provisioner" "me" {
}`,
Check: func(state *terraform.State) error {
require.Len(t, state.Modules, 1)
require.Len(t, state.Modules[0].Resources, 1)
resource := state.Modules[0].Resources["data.coder_provisioner.me"]
require.NotNil(t, resource)

attribs := resource.Primary.Attributes
require.Equal(t, runtime.GOOS, attribs["os"])
require.Equal(t, runtime.GOARCH, attribs["arch"])
return nil
},
}},
})
}

func TestAgent(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
Expand Down