Skip to content

Commit db53750

Browse files
committed
Replace login_before_ready with startup_script_behavior
1 parent 547f1b6 commit db53750

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

docs/resources/agent.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ resource "kubernetes_pod" "dev" {
5050
- `connection_timeout` (Number) Time in seconds until the agent is marked as timed out when a connection with the server cannot be established. A value of zero never marks the agent as timed out.
5151
- `dir` (String) The starting directory when a user creates a shell session. Defaults to $HOME.
5252
- `env` (Map of String) A mapping of environment variables to set inside the workspace.
53-
- `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 startup_script is done and has exited. When enabled, users may see an incomplete workspace when logging in.
53+
- `login_before_ready` (Boolean, Deprecated) 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 startup_script is done and has exited. When enabled, users may see an incomplete workspace when logging in.
5454
- `metadata` (Block List) Each "metadata" block defines a single item consisting of a key/value pair. This feature is in alpha and may break in future releases. (see [below for nested schema](#nestedblock--metadata))
5555
- `motd_file` (String) The path to a file within the workspace containing a message to display to users when they login via SSH. A typical value would be /etc/motd.
5656
- `shutdown_script` (String) A script to run before the agent is stopped. The script should exit when it is done to signal that the workspace can be stopped.
5757
- `shutdown_script_timeout` (Number) Time in seconds until the agent lifecycle status is marked as timed out during shutdown, this happens when the shutdown script has not completed (exited) in the given time.
5858
- `startup_script` (String) A script to run after the agent starts. The script should exit when it is done to signal that the agent is ready.
59+
- `startup_script_behavior` (String) This option sets the behavior of the startup_script. When set to "blocking", the startup_script must exit before the workspace is ready. When set to "non-blocking", the startup_script may run in the background and the workspace will be ready immediately. Defaults to "non-blocking", although "blocking" is recommended.
5960
- `startup_script_timeout` (Number) Time in seconds until the agent lifecycle status is marked as timed out during start, this happens when the startup script has not completed (exited) in the given time.
6061
- `troubleshooting_url` (String) A URL to a document with instructions for troubleshooting problems with the agent.
6162

provider/agent.go

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,31 @@ import (
1616
func agentResource() *schema.Resource {
1717
return &schema.Resource{
1818
Description: "Use this resource to associate an agent.",
19-
CreateContext: func(c context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
19+
CreateContext: func(ctx context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
2020
// This should be a real authentication token!
2121
resourceData.SetId(uuid.NewString())
2222
err := resourceData.Set("token", uuid.NewString())
2323
if err != nil {
2424
return diag.FromErr(err)
2525
}
26+
err = updateStartupScriptBehaviorIfLoginBeforeReady(resourceData)
27+
if err != nil {
28+
return diag.FromErr(err)
29+
}
2630
return updateInitScript(resourceData, i)
2731
},
28-
ReadWithoutTimeout: func(c context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
32+
ReadWithoutTimeout: func(ctx context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
2933
err := resourceData.Set("token", uuid.NewString())
3034
if err != nil {
3135
return diag.FromErr(err)
3236
}
37+
err = updateStartupScriptBehaviorIfLoginBeforeReady(resourceData)
38+
if err != nil {
39+
return diag.FromErr(err)
40+
}
3341
return updateInitScript(resourceData, i)
3442
},
35-
DeleteContext: func(c context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
43+
DeleteContext: func(ctx context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
3644
return nil
3745
},
3846
Schema: map[string]*schema.Schema{
@@ -131,11 +139,27 @@ func agentResource() *schema.Resource {
131139
Description: "The path to a file within the workspace containing a message to display to users when they login via SSH. A typical value would be /etc/motd.",
132140
},
133141
"login_before_ready": {
134-
Type: schema.TypeBool,
135-
Default: true, // Change default value to false in a future release.
136-
ForceNew: true,
137-
Optional: true,
138-
Description: "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 startup_script is done and has exited. When enabled, users may see an incomplete workspace when logging in.",
142+
Type: schema.TypeBool,
143+
Default: true,
144+
ForceNew: true,
145+
Optional: true,
146+
Description: "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 startup_script is done and has exited. When enabled, users may see an incomplete workspace when logging in.",
147+
Deprecated: "Configure startup_script_behavior instead. This attribute will be removed in a future version of the provider.",
148+
ConflictsWith: []string{"startup_script_behavior"},
149+
},
150+
"startup_script_behavior": {
151+
// Note: Our default value is "non-blocking" but we do not set
152+
// it here because we want to be able to differentiate between
153+
// the user setting this or "login_before_ready". For all
154+
// intents and purposes, until deprecation, setting
155+
// "login_before_ready = false" is equivalent to setting
156+
// "startup_script_behavior = blocking".
157+
Type: schema.TypeString,
158+
ForceNew: true,
159+
Optional: true,
160+
Description: "This option sets the behavior of the startup_script. When set to \"blocking\", the startup_script must exit before the workspace is ready. When set to \"non-blocking\", the startup_script may run in the background and the workspace will be ready immediately. Default is \"non-blocking\", although \"blocking\" is recommended.",
161+
ValidateFunc: validation.StringInSlice([]string{"blocking", "non-blocking"}, false),
162+
ConflictsWith: []string{"login_before_ready"},
139163
},
140164
"metadata": {
141165
Type: schema.TypeList,
@@ -251,3 +275,19 @@ func updateInitScript(resourceData *schema.ResourceData, i interface{}) diag.Dia
251275
}
252276
return nil
253277
}
278+
279+
func updateStartupScriptBehaviorIfLoginBeforeReady(resourceData *schema.ResourceData) error {
280+
if rc := resourceData.GetRawConfig(); !rc.IsNull() {
281+
if attr := rc.GetAttr("login_before_ready"); !attr.IsNull() {
282+
behavior := "non-blocking"
283+
if attr.False() {
284+
behavior = "blocking"
285+
}
286+
err := resourceData.Set("startup_script_behavior", behavior)
287+
if err != nil {
288+
return err
289+
}
290+
}
291+
}
292+
return nil
293+
}

provider/agent_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestAgent(t *testing.T) {
3636
motd_file = "/etc/motd"
3737
shutdown_script = "echo bye bye"
3838
shutdown_script_timeout = 120
39-
login_before_ready = false
39+
startup_script_behavior = "blocking"
4040
}
4141
`,
4242
Check: func(state *terraform.State) error {
@@ -58,7 +58,7 @@ func TestAgent(t *testing.T) {
5858
"motd_file",
5959
"shutdown_script",
6060
"shutdown_script_timeout",
61-
"login_before_ready",
61+
"startup_script_behavior",
6262
} {
6363
value := resource.Primary.Attributes[key]
6464
t.Logf("%q = %q", key, value)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy