diff --git a/docs/data-sources/git_auth.md b/docs/data-sources/git_auth.md index 5573993d..53e01981 100644 --- a/docs/data-sources/git_auth.md +++ b/docs/data-sources/git_auth.md @@ -46,5 +46,3 @@ EOF ### Read-Only - `access_token` (String) The access token returned by the git authentication provider. This can be used to pre-authenticate command-line tools. - - diff --git a/docs/data-sources/parameter.md b/docs/data-sources/parameter.md index 7483c9d0..43a10c36 100644 --- a/docs/data-sources/parameter.md +++ b/docs/data-sources/parameter.md @@ -61,5 +61,3 @@ Optional: - `min` (Number) The minimum of a number parameter. - `monotonic` (String) Number monotonicity, either increasing or decreasing. - `regex` (String) A regex for the input parameter to match against. - - diff --git a/docs/data-sources/provisioner.md b/docs/data-sources/provisioner.md index 47bdaf04..4316aeea 100644 --- a/docs/data-sources/provisioner.md +++ b/docs/data-sources/provisioner.md @@ -20,5 +20,3 @@ Use this data source to get information about the Coder provisioner. - `arch` (String) The architecture of the host. This exposes `runtime.GOARCH` (see https://pkg.go.dev/runtime#pkg-constants). - `id` (String) The ID of this resource. - `os` (String) The operating system of the host. This exposes `runtime.GOOS` (see https://pkg.go.dev/runtime#pkg-constants). - - diff --git a/docs/data-sources/workspace.md b/docs/data-sources/workspace.md index 865a2d98..d7cd4cab 100644 --- a/docs/data-sources/workspace.md +++ b/docs/data-sources/workspace.md @@ -36,5 +36,3 @@ resource "kubernetes_pod" "dev" { - `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. - `start_count` (Number) A computed count based on "transition" state. If "start", count will equal 1. - `transition` (String) Either "start" or "stop". Use this to start/stop resources with "count". - - diff --git a/docs/resources/agent.md b/docs/resources/agent.md index 1333d5bb..3e757440 100644 --- a/docs/resources/agent.md +++ b/docs/resources/agent.md @@ -63,5 +63,3 @@ resource "kubernetes_pod" "dev" { - `id` (String) The ID of this resource. - `init_script` (String) Run this script on startup of an instance to initialize the agent. - `token` (String, Sensitive) Set the environment variable "CODER_AGENT_TOKEN" with this token to authenticate an agent. - - diff --git a/docs/resources/agent_instance.md b/docs/resources/agent_instance.md index 7eab0dde..fa8574fa 100644 --- a/docs/resources/agent_instance.md +++ b/docs/resources/agent_instance.md @@ -40,5 +40,3 @@ resource "coder_agent_instance" "dev" { ### Read-Only - `id` (String) The ID of this resource. - - diff --git a/docs/resources/app.md b/docs/resources/app.md index e120f658..7b70bf6a 100644 --- a/docs/resources/app.md +++ b/docs/resources/app.md @@ -90,5 +90,3 @@ Required: - `interval` (Number) Duration in seconds to wait between healthcheck requests. - `threshold` (Number) Number of consecutive heathcheck failures before returning an unhealthy status. - `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. - - diff --git a/docs/resources/metadata.md b/docs/resources/metadata.md index 6edcd1d0..2d67e526 100644 --- a/docs/resources/metadata.md +++ b/docs/resources/metadata.md @@ -80,5 +80,3 @@ Optional: Read-Only: - `is_null` (Boolean) - - diff --git a/docs/resources/script.md b/docs/resources/script.md new file mode 100644 index 00000000..d698af24 --- /dev/null +++ b/docs/resources/script.md @@ -0,0 +1,33 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "coder_script Resource - terraform-provider-coder" +subcategory: "" +description: |- + Use this resource to run a script from an agent. +--- + +# coder_script (Resource) + +Use this resource to run a script from an agent. + + + + +## Schema + +### Required + +- `agent_id` (String) The "id" property of a "coder_agent" resource to associate with. +- `script` (String) The script to run. + +### Optional + +- `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. +- `run_on_start` (Boolean) This option defines whether or not the script should run when the agent starts. +- `run_on_stop` (Boolean) This option defines whether or not the script should run when the agent stops. +- `schedule` (String) The schedule to run the script on. This is a cron expression. +- `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. + +### Read-Only + +- `id` (String) The ID of this resource. diff --git a/provider/provider.go b/provider/provider.go index a77774cd..907aef6f 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -76,6 +76,7 @@ func New() *schema.Provider { "coder_agent_instance": agentInstanceResource(), "coder_app": appResource(), "coder_metadata": metadataResource(), + "coder_script": scriptResource(), }, } } diff --git a/provider/script.go b/provider/script.go new file mode 100644 index 00000000..2903e144 --- /dev/null +++ b/provider/script.go @@ -0,0 +1,91 @@ +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" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func scriptResource() *schema.Resource { + return &schema.Resource{ + Description: "Use this resource to run a script from an agent.", + CreateContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics { + rd.SetId(uuid.NewString()) + return nil + }, + ReadContext: schema.NoopContext, + DeleteContext: schema.NoopContext, + Schema: map[string]*schema.Schema{ + "agent_id": { + Type: schema.TypeString, + Description: `The "id" property of a "coder_agent" resource to associate with.`, + ForceNew: true, + Required: true, + }, + "display_name": { + Type: schema.TypeString, + Description: "The display name of the script to display logs in the dashboard.", + ForceNew: true, + Required: true, + }, + "log_path": { + Type: schema.TypeString, + Description: "The path of a file to write the logs to. If relative, it will be appended to tmp.", + ForceNew: true, + Optional: true, + }, + "icon": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + Description: "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/\"`.", + }, + "source": { + ForceNew: true, + Type: schema.TypeString, + Required: true, + Description: "The script to run.", + }, + "cron": { + ForceNew: true, + Type: schema.TypeString, + Optional: true, + Description: "The cron schedule to run the script on. This is a cron expression.", + }, + "start_blocks_login": { + Type: schema.TypeBool, + Default: false, + ForceNew: true, + Optional: true, + 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.", + }, + "run_on_start": { + Type: schema.TypeBool, + Default: false, + ForceNew: true, + Optional: true, + Description: "This option defines whether or not the script should run when the agent starts.", + }, + "run_on_stop": { + Type: schema.TypeBool, + Default: false, + ForceNew: true, + Optional: true, + Description: "This option defines whether or not the script should run when the agent stops.", + }, + "timeout": { + Type: schema.TypeInt, + Default: 0, + ForceNew: true, + Optional: true, + 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.", + ValidateFunc: validation.IntAtLeast(1), + }, + }, + } +}