Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit609d6e0

Browse files
committed
Replacelogin_before_ready withstartup_script_behavior
1 parent547f1b6 commit609d6e0

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. Default is "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
funcagentResource()*schema.Resource {
1717
return&schema.Resource{
1818
Description:"Use this resource to associate an agent.",
19-
CreateContext:func(c context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics {
19+
CreateContext:func(ctx context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics {
2020
// This should be a real authentication token!
2121
resourceData.SetId(uuid.NewString())
2222
err:=resourceData.Set("token",uuid.NewString())
2323
iferr!=nil {
2424
returndiag.FromErr(err)
2525
}
26+
err=updateStartupScriptBehaviorIfLoginBeforeReady(resourceData)
27+
iferr!=nil {
28+
returndiag.FromErr(err)
29+
}
2630
returnupdateInitScript(resourceData,i)
2731
},
28-
ReadWithoutTimeout:func(c context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics {
32+
ReadWithoutTimeout:func(ctx context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics {
2933
err:=resourceData.Set("token",uuid.NewString())
3034
iferr!=nil {
3135
returndiag.FromErr(err)
3236
}
37+
err=updateStartupScriptBehaviorIfLoginBeforeReady(resourceData)
38+
iferr!=nil {
39+
returndiag.FromErr(err)
40+
}
3341
returnupdateInitScript(resourceData,i)
3442
},
35-
DeleteContext:func(c context.Context,rd*schema.ResourceData,iinterface{}) diag.Diagnostics {
43+
DeleteContext:func(ctx context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics {
3644
returnnil
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
returnnil
253277
}
278+
279+
funcupdateStartupScriptBehaviorIfLoginBeforeReady(resourceData*schema.ResourceData)error {
280+
ifrc:=resourceData.GetRawConfig();!rc.IsNull() {
281+
ifattr:=rc.GetAttr("login_before_ready");!attr.IsNull() {
282+
behavior:="non-blocking"
283+
ifattr.False() {
284+
behavior="blocking"
285+
}
286+
err:=resourceData.Set("startup_script_behavior",behavior)
287+
iferr!=nil {
288+
returnerr
289+
}
290+
}
291+
}
292+
returnnil
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)

[8]ページ先頭

©2009-2025 Movatter.jp