Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/resources/external_agent.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_external_agent Resource - terraform-provider-coder"
subcategory: ""
description: |-
Define an external agent to be used in a workspace.
---

# coder_external_agent (Resource)

Define an external agent to be used in a workspace.



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

### Required

- `token` (String, Sensitive) Set the environment variable `CODER_AGENT_TOKEN` with this token to authenticate an agent.

### Read-Only

- `id` (String) The ID of this resource.
32 changes: 32 additions & 0 deletions provider/external_agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package provider

import (
"context"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func externalAgentResource() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,

Description: "Define an external agent to be used in a workspace.",
CreateContext: func(ctx context.Context, rd *schema.ResourceData, _ interface{}) diag.Diagnostics {
rd.SetId(uuid.NewString())
return nil
},
ReadContext: schema.NoopContext,
DeleteContext: schema.NoopContext,
Schema: map[string]*schema.Schema{
"token": {
ForceNew: true,
Required: true,
Sensitive: true,
Description: "Set the environment variable `CODER_AGENT_TOKEN` with this token to authenticate an agent.",
Type: schema.TypeString,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand linking these based on the token value rather than just the ID value of the agent. It seems like we'd want to be able to configure the auth type on the coder_agent and have that also apply here.

},
}
}
41 changes: 41 additions & 0 deletions provider/external_agent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package provider_test

import (
"testing"

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

func TestExternalAgent(t *testing.T) {
t.Parallel()

t.Run("OK", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also have a test that links this resource to a coder_agent.

t.Parallel()

resource.Test(t, resource.TestCase{
ProviderFactories: coderFactory(),
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: `
provider "coder" {
}

resource "coder_external_agent" "main" {
token = "token"
}
`,
Check: func(state *terraform.State) error {
require.Len(t, state.Modules, 1)
resource := state.Modules[0].Resources["coder_external_agent.main"]
require.NotNil(t, resource)
value := resource.Primary.Attributes["token"]
require.NotNil(t, value)
require.Greater(t, len(value), 0)
return nil
},
}},
})
})
}
1 change: 1 addition & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func New() *schema.Provider {
"coder_script": scriptResource(),
"coder_env": envResource(),
"coder_devcontainer": devcontainerResource(),
"coder_external_agent": externalAgentResource(),
},
}
}
Expand Down
Loading