Skip to content

Commit 234129b

Browse files
committed
add coder_external_agent resource
1 parent e6d58d0 commit 234129b

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

docs/resources/external_agent.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "coder_external_agent Resource - terraform-provider-coder"
4+
subcategory: ""
5+
description: |-
6+
Define an external agent to be used in a workspace.
7+
---
8+
9+
# coder_external_agent (Resource)
10+
11+
Define an external agent to be used in a workspace.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `token` (String, Sensitive) Set the environment variable `CODER_AGENT_TOKEN` with this token to authenticate an agent.
21+
22+
### Read-Only
23+
24+
- `id` (String) The ID of this resource.

provider/external_agent.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
6+
"github.com/google/uuid"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
)
10+
11+
func externalAgentResource() *schema.Resource {
12+
return &schema.Resource{
13+
SchemaVersion: 1,
14+
15+
Description: "Define an external agent to be used in a workspace.",
16+
CreateContext: func(ctx context.Context, rd *schema.ResourceData, _ interface{}) diag.Diagnostics {
17+
rd.SetId(uuid.NewString())
18+
return nil
19+
},
20+
ReadContext: schema.NoopContext,
21+
DeleteContext: schema.NoopContext,
22+
Schema: map[string]*schema.Schema{
23+
"token": {
24+
ForceNew: true,
25+
Required: true,
26+
Sensitive: true,
27+
Description: "Set the environment variable `CODER_AGENT_TOKEN` with this token to authenticate an agent.",
28+
Type: schema.TypeString,
29+
},
30+
},
31+
}
32+
}

provider/external_agent_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package provider_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestExternalAgent(t *testing.T) {
12+
t.Parallel()
13+
14+
t.Run("OK", func(t *testing.T) {
15+
t.Parallel()
16+
17+
resource.Test(t, resource.TestCase{
18+
ProviderFactories: coderFactory(),
19+
IsUnitTest: true,
20+
Steps: []resource.TestStep{{
21+
Config: `
22+
provider "coder" {
23+
}
24+
25+
resource "coder_external_agent" "main" {
26+
token = "token"
27+
}
28+
`,
29+
Check: func(state *terraform.State) error {
30+
require.Len(t, state.Modules, 1)
31+
resource := state.Modules[0].Resources["coder_external_agent.main"]
32+
require.NotNil(t, resource)
33+
value := resource.Primary.Attributes["token"]
34+
require.NotNil(t, value)
35+
require.Greater(t, len(value), 0)
36+
return nil
37+
},
38+
}},
39+
})
40+
})
41+
}

provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func New() *schema.Provider {
7474
"coder_script": scriptResource(),
7575
"coder_env": envResource(),
7676
"coder_devcontainer": devcontainerResource(),
77+
"coder_external_agent": externalAgentResource(),
7778
},
7879
}
7980
}

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