Skip to content

Commit 8eae93d

Browse files
committed
feat: add coder_script
See coder/coder#9287 I decided to drop the `agent` portion from the name. It seemed inconsistent with `coder_app`.
1 parent f0da725 commit 8eae93d

File tree

11 files changed

+125
-16
lines changed

11 files changed

+125
-16
lines changed

docs/data-sources/git_auth.md

-2
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,3 @@ EOF
4646
### Read-Only
4747

4848
- `access_token` (String) The access token returned by the git authentication provider. This can be used to pre-authenticate command-line tools.
49-
50-

docs/data-sources/parameter.md

-2
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,3 @@ Optional:
6161
- `min` (Number) The minimum of a number parameter.
6262
- `monotonic` (String) Number monotonicity, either increasing or decreasing.
6363
- `regex` (String) A regex for the input parameter to match against.
64-
65-

docs/data-sources/provisioner.md

-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,3 @@ Use this data source to get information about the Coder provisioner.
2020
- `arch` (String) The architecture of the host. This exposes `runtime.GOARCH` (see https://pkg.go.dev/runtime#pkg-constants).
2121
- `id` (String) The ID of this resource.
2222
- `os` (String) The operating system of the host. This exposes `runtime.GOOS` (see https://pkg.go.dev/runtime#pkg-constants).
23-
24-

docs/data-sources/workspace.md

-2
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,3 @@ resource "kubernetes_pod" "dev" {
3636
- `owner_oidc_access_token` (String) A valid OpenID Connect access token of the workspace owner. This is only available if the workspace owner authenticated with OpenID Connect. If a valid token cannot be obtained, this value will be an empty string.
3737
- `start_count` (Number) A computed count based on "transition" state. If "start", count will equal 1.
3838
- `transition` (String) Either "start" or "stop". Use this to start/stop resources with "count".
39-
40-

docs/resources/agent.md

-2
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,3 @@ resource "kubernetes_pod" "dev" {
6363
- `id` (String) The ID of this resource.
6464
- `init_script` (String) Run this script on startup of an instance to initialize the agent.
6565
- `token` (String, Sensitive) Set the environment variable "CODER_AGENT_TOKEN" with this token to authenticate an agent.
66-
67-

docs/resources/agent_instance.md

-2
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,3 @@ resource "coder_agent_instance" "dev" {
4040
### Read-Only
4141

4242
- `id` (String) The ID of this resource.
43-
44-

docs/resources/app.md

-2
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,3 @@ Required:
9090
- `interval` (Number) Duration in seconds to wait between healthcheck requests.
9191
- `threshold` (Number) Number of consecutive heathcheck failures before returning an unhealthy status.
9292
- `url` (String) HTTP address used determine the application readiness. A successful health check is a HTTP response code less than 500 returned before healthcheck.interval seconds.
93-
94-

docs/resources/metadata.md

-2
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,3 @@ Optional:
8080
Read-Only:
8181

8282
- `is_null` (Boolean)
83-
84-

docs/resources/script.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
- `script` (String) The script to run.
22+
23+
### Optional
24+
25+
- `login_before_ready` (Boolean) This option defines whether or not the user can (by default) login to the workspace before it is ready. Ready means that e.g. the script is done and has exited. When enabled, users may see an incomplete workspace when logging in.
26+
- `run_on_start` (Boolean) This option defines whether or not the script should run when the agent starts.
27+
- `run_on_stop` (Boolean) This option defines whether or not the script should run when the agent stops.
28+
- `schedule` (String) The schedule to run the script on. This is a cron expression.
29+
- `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.
30+
31+
### Read-Only
32+
33+
- `id` (String) The ID of this resource.

provider/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func New() *schema.Provider {
7676
"coder_agent_instance": agentInstanceResource(),
7777
"coder_app": appResource(),
7878
"coder_metadata": metadataResource(),
79+
"coder_script": scriptResource(),
7980
},
8081
}
8182
}

provider/script.go

+91
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+
func scriptResource() *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, i interface{}) diag.Diagnostics {
16+
rd.SetId(uuid.NewString())
17+
return nil
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+
"source": {
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)