diff --git a/docs/data-sources/provisioner.md b/docs/data-sources/provisioner.md new file mode 100644 index 00000000..47bdaf04 --- /dev/null +++ b/docs/data-sources/provisioner.md @@ -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 + +### 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). + + diff --git a/internal/provider/provider.go b/internal/provider/provider.go index ef6dc1fe..21227214 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -7,6 +7,7 @@ import ( "net/url" "os" "reflect" + "runtime" "strings" "github.com/google/uuid" @@ -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": { diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index e82c5ad7..40c659c8 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -1,6 +1,7 @@ package provider_test import ( + "runtime" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -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{