Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9495777

Browse files
authored
feat: addcoder_script (#154)
* feat: add `coder_script`Seecoder/coder#9287I decided to drop the `agent` portion from the name. It seemed inconsistentwith `coder_app`.* Fix docs
1 parent233ea60 commit9495777

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

‎docs/resources/script.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title:"coder_script Resource - terraform-provider-coder"
4+
subcategory:""
5+
description:|-
6+
Use this resource to run a script from an agent.
7+
---
8+
9+
#coder_script (Resource)
10+
11+
Use this resource to run a script from an agent.
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+
-`display_name` (String) The display name of the script to display logs in the dashboard.
22+
-`script` (String) The script to run.
23+
24+
###Optional
25+
26+
-`cron` (String) The cron schedule to run the script on. This is a cron expression.
27+
-`icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here:https://github.com/coder/coder/tree/main/site/static/icon. Use a built-in icon with`data.coder_workspace.me.access_url + "/icon/<path>"`.
28+
-`log_path` (String) The path of a file to write the logs to. If relative, it will be appended to tmp.
29+
-`run_on_start` (Boolean) This option defines whether or not the script should run when the agent starts.
30+
-`run_on_stop` (Boolean) This option defines whether or not the script should run when the agent stops.
31+
-`start_blocks_login` (Boolean) This option defines whether or not the user can (by default) login to the workspace before this script completes running on start. When enabled, users may see an incomplete workspace when logging in.
32+
-`timeout` (Number) Time in seconds until the agent lifecycle status is marked as timed out, this happens when the script has not completed (exited) in the given time.
33+
34+
###Read-Only
35+
36+
-`id` (String) The ID of this resource.

‎provider/provider.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func New() *schema.Provider {
7878
"coder_agent_instance":agentInstanceResource(),
7979
"coder_app":appResource(),
8080
"coder_metadata":metadataResource(),
81+
"coder_script":scriptResource(),
8182
},
8283
}
8384
}

‎provider/script.go‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
10+
)
11+
12+
funcscriptResource()*schema.Resource {
13+
return&schema.Resource{
14+
Description:"Use this resource to run a script from an agent.",
15+
CreateContext:func(ctx context.Context,rd*schema.ResourceData,iinterface{}) diag.Diagnostics {
16+
rd.SetId(uuid.NewString())
17+
returnnil
18+
},
19+
ReadContext:schema.NoopContext,
20+
DeleteContext:schema.NoopContext,
21+
Schema:map[string]*schema.Schema{
22+
"agent_id": {
23+
Type:schema.TypeString,
24+
Description:`The "id" property of a "coder_agent" resource to associate with.`,
25+
ForceNew:true,
26+
Required:true,
27+
},
28+
"display_name": {
29+
Type:schema.TypeString,
30+
Description:"The display name of the script to display logs in the dashboard.",
31+
ForceNew:true,
32+
Required:true,
33+
},
34+
"log_path": {
35+
Type:schema.TypeString,
36+
Description:"The path of a file to write the logs to. If relative, it will be appended to tmp.",
37+
ForceNew:true,
38+
Optional:true,
39+
},
40+
"icon": {
41+
Type:schema.TypeString,
42+
ForceNew:true,
43+
Optional:true,
44+
Description:"A URL to an icon that will display in the dashboard. View built-in "+
45+
"icons here: https://github.com/coder/coder/tree/main/site/static/icon. Use a "+
46+
"built-in icon with `data.coder_workspace.me.access_url +\"/icon/<path>\"`.",
47+
},
48+
"script": {
49+
ForceNew:true,
50+
Type:schema.TypeString,
51+
Required:true,
52+
Description:"The script to run.",
53+
},
54+
"cron": {
55+
ForceNew:true,
56+
Type:schema.TypeString,
57+
Optional:true,
58+
Description:"The cron schedule to run the script on. This is a cron expression.",
59+
},
60+
"start_blocks_login": {
61+
Type:schema.TypeBool,
62+
Default:false,
63+
ForceNew:true,
64+
Optional:true,
65+
Description:"This option defines whether or not the user can (by default) login to the workspace before this script completes running on start. When enabled, users may see an incomplete workspace when logging in.",
66+
},
67+
"run_on_start": {
68+
Type:schema.TypeBool,
69+
Default:false,
70+
ForceNew:true,
71+
Optional:true,
72+
Description:"This option defines whether or not the script should run when the agent starts.",
73+
},
74+
"run_on_stop": {
75+
Type:schema.TypeBool,
76+
Default:false,
77+
ForceNew:true,
78+
Optional:true,
79+
Description:"This option defines whether or not the script should run when the agent stops.",
80+
},
81+
"timeout": {
82+
Type:schema.TypeInt,
83+
Default:0,
84+
ForceNew:true,
85+
Optional:true,
86+
Description:"Time in seconds until the agent lifecycle status is marked as timed out, this happens when the script has not completed (exited) in the given time.",
87+
ValidateFunc:validation.IntAtLeast(1),
88+
},
89+
},
90+
}
91+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp