Skip to content

Commit e0d039d

Browse files
authored
Add DialErrorLimit as parameter for remote command (#180)
Previously there was a hardcoded value of 10 attempts on dialing the remote host. If all 10 attempts returned an error then command execution would fail. This change enables to adjust the number of attempts when getting an error while dialing, or even to remove the limit to keep retrying until timeout.
1 parent 993baeb commit e0d039d

File tree

12 files changed

+160
-1
lines changed

12 files changed

+160
-1
lines changed

examples/ec2_remote/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ const connection: types.input.remote.ConnectionArgs = {
4141
privateKey: privateKey,
4242
};
4343

44+
const connectionNoDialRetry: types.input.remote.ConnectionArgs = {
45+
host: server.publicIp,
46+
user: "ec2-user",
47+
privateKey: privateKey,
48+
dialErrorLimit: -1,
49+
};
50+
4451
const hostname = new remote.Command("hostname", {
4552
connection,
4653
create: "hostname",
@@ -55,6 +62,12 @@ new remote.Command("remotePrivateIP", {
5562
delete: `rm private_ip.txt`,
5663
}, { deleteBeforeReplace: true });
5764

65+
new remote.Command("remoteWithNoDialRetryPrivateIP", {
66+
connection: connectionNoDialRetry,
67+
create: interpolate`echo ${server.privateIp} > private_ip_on_no_dial_retry.txt`,
68+
delete: `rm private_ip_on_no_dial_retry.txt`,
69+
}, { deleteBeforeReplace: true });
70+
5871
new local.Command("localPrivateIP", {
5972
create: interpolate`echo ${server.privateIp} > private_ip.txt`,
6073
delete: `rm private_ip.txt`,

provider/cmd/pulumi-resource-command/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@
471471
"description": "SSH Agent socket path. Default to environment variable SSH_AUTH_SOCK if present.",
472472
"type": "string"
473473
},
474+
"dialErrorLimit": {
475+
"default": 10,
476+
"description": "Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10",
477+
"type": "integer"
478+
},
474479
"host": {
475480
"description": "The address of the resource to connect to.",
476481
"type": "string"

provider/pkg/provider/remote/connection.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929

3030
const (
3131
sshAgentSocketEnvVar = "SSH_AUTH_SOCK"
32+
DialErrorDefault = 10
33+
DialErrorUnlimited = -1
3234
)
3335

3436
type Connection struct {
@@ -39,6 +41,7 @@ type Connection struct {
3941
PrivateKey *string `pulumi:"privateKey,optional"`
4042
PrivateKeyPassword *string `pulumi:"privateKeyPassword,optional"`
4143
AgentSocketPath *string `pulumi:"agentSocketPath,optional"`
44+
DialErrorLimit *int `pulumi:"dialErrorLimit,optional"`
4245
}
4346

4447
func (c *Connection) Annotate(a infer.Annotator) {
@@ -52,6 +55,8 @@ func (c *Connection) Annotate(a infer.Annotator) {
5255
a.Describe(&c.PrivateKey, "The contents of an SSH key to use for the connection. This takes preference over the password if provided.")
5356
a.Describe(&c.PrivateKeyPassword, "The password to use in case the private key is encrypted.")
5457
a.Describe(&c.AgentSocketPath, "SSH Agent socket path. Default to environment variable SSH_AUTH_SOCK if present.")
58+
a.Describe(&c.DialErrorLimit, "Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10")
59+
a.SetDefault(&c.DialErrorLimit, DialErrorDefault)
5560
}
5661

5762
func (con *Connection) SShConfig() (*ssh.ClientConfig, error) {
@@ -109,7 +114,9 @@ func (con *Connection) Dial(ctx p.Context, config *ssh.ClientConfig) (*ssh.Clien
109114
net.JoinHostPort(*con.Host, fmt.Sprintf("%.0f", *con.Port)),
110115
config)
111116
if err != nil {
112-
if try > 10 {
117+
// on each try we already made a dial
118+
dials := try + 1
119+
if *con.DialErrorLimit > DialErrorUnlimited && dials > *con.DialErrorLimit {
113120
return true, nil, err
114121
}
115122
return false, nil, nil

sdk/dotnet/Remote/Inputs/ConnectionArgs.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public sealed class ConnectionArgs : global::Pulumi.ResourceArgs
2121
[Input("agentSocketPath")]
2222
public Input<string>? AgentSocketPath { get; set; }
2323

24+
/// <summary>
25+
/// Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10
26+
/// </summary>
27+
[Input("dialErrorLimit")]
28+
public Input<int>? DialErrorLimit { get; set; }
29+
2430
/// <summary>
2531
/// The address of the resource to connect to.
2632
/// </summary>
@@ -59,6 +65,7 @@ public sealed class ConnectionArgs : global::Pulumi.ResourceArgs
5965

6066
public ConnectionArgs()
6167
{
68+
DialErrorLimit = 10;
6269
Port = 22;
6370
User = "root";
6471
}

sdk/dotnet/Remote/Outputs/Connection.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public sealed class Connection
2121
/// </summary>
2222
public readonly string? AgentSocketPath;
2323
/// <summary>
24+
/// Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10
25+
/// </summary>
26+
public readonly int? DialErrorLimit;
27+
/// <summary>
2428
/// The address of the resource to connect to.
2529
/// </summary>
2630
public readonly string Host;
@@ -49,6 +53,8 @@ public sealed class Connection
4953
private Connection(
5054
string? agentSocketPath,
5155

56+
int? dialErrorLimit,
57+
5258
string host,
5359

5460
string? password,
@@ -62,6 +68,7 @@ private Connection(
6268
string? user)
6369
{
6470
AgentSocketPath = agentSocketPath;
71+
DialErrorLimit = dialErrorLimit;
6572
Host = host;
6673
Password = password;
6774
Port = port;

sdk/go/command/remote/pulumiTypes.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/java/src/main/java/com/pulumi/command/remote/inputs/ConnectionArgs.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.pulumi.core.annotations.Import;
88
import com.pulumi.core.internal.Codegen;
99
import java.lang.Double;
10+
import java.lang.Integer;
1011
import java.lang.String;
1112
import java.util.Objects;
1213
import java.util.Optional;
@@ -36,6 +37,21 @@ public Optional<Output<String>> agentSocketPath() {
3637
return Optional.ofNullable(this.agentSocketPath);
3738
}
3839

40+
/**
41+
* Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10
42+
*
43+
*/
44+
@Import(name="dialErrorLimit")
45+
private @Nullable Output<Integer> dialErrorLimit;
46+
47+
/**
48+
* @return Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10
49+
*
50+
*/
51+
public Optional<Output<Integer>> dialErrorLimit() {
52+
return Optional.ofNullable(this.dialErrorLimit);
53+
}
54+
3955
/**
4056
* The address of the resource to connect to.
4157
*
@@ -130,6 +146,7 @@ private ConnectionArgs() {}
130146

131147
private ConnectionArgs(ConnectionArgs $) {
132148
this.agentSocketPath = $.agentSocketPath;
149+
this.dialErrorLimit = $.dialErrorLimit;
133150
this.host = $.host;
134151
this.password = $.password;
135152
this.port = $.port;
@@ -177,6 +194,27 @@ public Builder agentSocketPath(String agentSocketPath) {
177194
return agentSocketPath(Output.of(agentSocketPath));
178195
}
179196

197+
/**
198+
* @param dialErrorLimit Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10
199+
*
200+
* @return builder
201+
*
202+
*/
203+
public Builder dialErrorLimit(@Nullable Output<Integer> dialErrorLimit) {
204+
$.dialErrorLimit = dialErrorLimit;
205+
return this;
206+
}
207+
208+
/**
209+
* @param dialErrorLimit Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10
210+
*
211+
* @return builder
212+
*
213+
*/
214+
public Builder dialErrorLimit(Integer dialErrorLimit) {
215+
return dialErrorLimit(Output.of(dialErrorLimit));
216+
}
217+
180218
/**
181219
* @param host The address of the resource to connect to.
182220
*
@@ -304,6 +342,7 @@ public Builder user(String user) {
304342
}
305343

306344
public ConnectionArgs build() {
345+
$.dialErrorLimit = Codegen.integerProp("dialErrorLimit").output().arg($.dialErrorLimit).def(10).getNullable();
307346
$.host = Objects.requireNonNull($.host, "expected parameter 'host' to be non-null");
308347
$.port = Codegen.doubleProp("port").output().arg($.port).def(2.2e+01).getNullable();
309348
$.user = Codegen.stringProp("user").output().arg($.user).def("root").getNullable();

sdk/java/src/main/java/com/pulumi/command/remote/outputs/Connection.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.pulumi.core.annotations.CustomType;
77
import java.lang.Double;
8+
import java.lang.Integer;
89
import java.lang.String;
910
import java.util.Objects;
1011
import java.util.Optional;
@@ -17,6 +18,11 @@ public final class Connection {
1718
*
1819
*/
1920
private @Nullable String agentSocketPath;
21+
/**
22+
* @return Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10
23+
*
24+
*/
25+
private @Nullable Integer dialErrorLimit;
2026
/**
2127
* @return The address of the resource to connect to.
2228
*
@@ -56,6 +62,13 @@ private Connection() {}
5662
public Optional<String> agentSocketPath() {
5763
return Optional.ofNullable(this.agentSocketPath);
5864
}
65+
/**
66+
* @return Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10
67+
*
68+
*/
69+
public Optional<Integer> dialErrorLimit() {
70+
return Optional.ofNullable(this.dialErrorLimit);
71+
}
5972
/**
6073
* @return The address of the resource to connect to.
6174
*
@@ -109,6 +122,7 @@ public static Builder builder(Connection defaults) {
109122
@CustomType.Builder
110123
public static final class Builder {
111124
private @Nullable String agentSocketPath;
125+
private @Nullable Integer dialErrorLimit;
112126
private String host;
113127
private @Nullable String password;
114128
private @Nullable Double port;
@@ -119,6 +133,7 @@ public Builder() {}
119133
public Builder(Connection defaults) {
120134
Objects.requireNonNull(defaults);
121135
this.agentSocketPath = defaults.agentSocketPath;
136+
this.dialErrorLimit = defaults.dialErrorLimit;
122137
this.host = defaults.host;
123138
this.password = defaults.password;
124139
this.port = defaults.port;
@@ -133,6 +148,11 @@ public Builder agentSocketPath(@Nullable String agentSocketPath) {
133148
return this;
134149
}
135150
@CustomType.Setter
151+
public Builder dialErrorLimit(@Nullable Integer dialErrorLimit) {
152+
this.dialErrorLimit = dialErrorLimit;
153+
return this;
154+
}
155+
@CustomType.Setter
136156
public Builder host(String host) {
137157
this.host = Objects.requireNonNull(host);
138158
return this;
@@ -165,6 +185,7 @@ public Builder user(@Nullable String user) {
165185
public Connection build() {
166186
final var o = new Connection();
167187
o.agentSocketPath = agentSocketPath;
188+
o.dialErrorLimit = dialErrorLimit;
168189
o.host = host;
169190
o.password = password;
170191
o.port = port;

sdk/nodejs/types/input.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export namespace remote {
1616
* SSH Agent socket path. Default to environment variable SSH_AUTH_SOCK if present.
1717
*/
1818
agentSocketPath?: pulumi.Input<string>;
19+
/**
20+
* Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10
21+
*/
22+
dialErrorLimit?: pulumi.Input<number>;
1923
/**
2024
* The address of the resource to connect to.
2125
*/
@@ -47,6 +51,7 @@ export namespace remote {
4751
export function connectionArgsProvideDefaults(val: ConnectionArgs): ConnectionArgs {
4852
return {
4953
...val,
54+
dialErrorLimit: (val.dialErrorLimit) ?? 10,
5055
port: (val.port) ?? 22,
5156
user: (val.user) ?? "root",
5257
};

sdk/nodejs/types/output.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export namespace remote {
1616
* SSH Agent socket path. Default to environment variable SSH_AUTH_SOCK if present.
1717
*/
1818
agentSocketPath?: string;
19+
/**
20+
* Max allowed errors on trying to dial the remote host. -1 set count to unlimited. Default value is 10
21+
*/
22+
dialErrorLimit?: number;
1923
/**
2024
* The address of the resource to connect to.
2125
*/
@@ -47,6 +51,7 @@ export namespace remote {
4751
export function connectionProvideDefaults(val: Connection): Connection {
4852
return {
4953
...val,
54+
dialErrorLimit: (val.dialErrorLimit) ?? 10,
5055
port: (val.port) ?? 22,
5156
user: (val.user) ?? "root",
5257
};

0 commit comments

Comments
 (0)