|
| 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 | + "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