File tree Expand file tree Collapse file tree 4 files changed +105
-0
lines changed Expand file tree Collapse file tree 4 files changed +105
-0
lines changed Original file line number Diff line number Diff line change 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+ - ` agent_id ` (String) The ` id ` property of a ` coder_agent ` resource to associate with.
21+
22+ ### Read-Only
23+
24+ - ` id ` (String) The ID of this resource.
Original file line number Diff line number Diff line change 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+ "agent_id" : {
24+ Type : schema .TypeString ,
25+ Description : "The `id` property of a `coder_agent` resource to associate with." ,
26+ ForceNew : true ,
27+ Required : true ,
28+ },
29+ },
30+ }
31+ }
Original file line number Diff line number Diff line change 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_agent" "dev" {
26+ os = "linux"
27+ arch = "amd64"
28+ }
29+
30+ resource "coder_external_agent" "dev" {
31+ agent_id = coder_agent.dev.id
32+ }
33+ ` ,
34+ Check : func (state * terraform.State ) error {
35+ require .Len (t , state .Modules , 1 )
36+ require .Len (t , state .Modules [0 ].Resources , 2 )
37+
38+ agentResource := state .Modules [0 ].Resources ["coder_agent.dev" ]
39+ require .NotNil (t , agentResource )
40+ externalAgentResource := state .Modules [0 ].Resources ["coder_external_agent.dev" ]
41+ require .NotNil (t , externalAgentResource )
42+
43+ require .Equal (t , agentResource .Primary .Attributes ["id" ], externalAgentResource .Primary .Attributes ["agent_id" ])
44+ return nil
45+ },
46+ }},
47+ })
48+ })
49+ }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments