Skip to content

Commit fbd5cd1

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

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
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: 43 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,22 @@ 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+
Type: schema.TypeString,
152+
Default: "non-blocking",
153+
ForceNew: true,
154+
Optional: true,
155+
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. Defaults to \"non-blocking\", although \"blocking\" is recommended.",
156+
ValidateFunc: validation.StringInSlice([]string{"blocking", "non-blocking"}, false),
157+
ConflictsWith: []string{"login_before_ready"},
139158
},
140159
"metadata": {
141160
Type: schema.TypeList,
@@ -251,3 +270,19 @@ func updateInitScript(resourceData *schema.ResourceData, i interface{}) diag.Dia
251270
}
252271
return nil
253272
}
273+
274+
func updateStartupScriptBehaviorIfLoginBeforeReady(resourceData *schema.ResourceData) error {
275+
if rc := resourceData.GetRawConfig(); !rc.IsNull() {
276+
if attr := rc.GetAttr("login_before_ready"); !attr.IsNull() {
277+
behavior := "non-blocking"
278+
if attr.False() {
279+
behavior = "blocking"
280+
}
281+
err := resourceData.Set("startup_script_behavior", behavior)
282+
if err != nil {
283+
return err
284+
}
285+
}
286+
}
287+
return nil
288+
}

provider/agent_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestAgent(t *testing.T) {
3737
shutdown_script = "echo bye bye"
3838
shutdown_script_timeout = 120
3939
login_before_ready = false
40+
# ^ should result in: startup_script_behavior = "blocking"
4041
}
4142
`,
4243
Check: func(state *terraform.State) error {
@@ -59,6 +60,7 @@ func TestAgent(t *testing.T) {
5960
"shutdown_script",
6061
"shutdown_script_timeout",
6162
"login_before_ready",
63+
"startup_script_behavior",
6264
} {
6365
value := resource.Primary.Attributes[key]
6466
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