Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow opt-out of adding stdout/stderr env variables for remote command #451

Merged
merged 13 commits into from
Jun 17, 2024
8 changes: 8 additions & 0 deletions provider/cmd/pulumi-resource-command/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@
"command:remote:Command": {
"description": "A command to run on a remote host.\nThe connection is established via ssh.",
"properties": {
"addPreviousOutputInEnv": {
"type": "boolean",
"description": "If the previous command's stdout and stderr (as generated by the prior create/update) is\ninjected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.\nDefaults to true."
},
"connection": {
"$ref": "#/types/command:remote:Connection",
"description": "The parameters with which to connect to the remote host.",
Expand Down Expand Up @@ -424,6 +428,10 @@
"stdout"
],
"inputProperties": {
"addPreviousOutputInEnv": {
"type": "boolean",
"description": "If the previous command's stdout and stderr (as generated by the prior create/update) is\ninjected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.\nDefaults to true."
},
"connection": {
"$ref": "#/types/command:remote:Connection",
"description": "The parameters with which to connect to the remote host.",
Expand Down
13 changes: 9 additions & 4 deletions provider/pkg/provider/remote/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ type CommandInputs struct {
// pulumi:"optional" specifies that a field is optional. This must be a pointer.
// provider:"replaceOnChanges" specifies that the resource will be replaced if the field changes.
// provider:"secret" specifies that a field should be marked secret.
Stdin *string `pulumi:"stdin,optional"`
Logging *Logging `pulumi:"logging,optional"`
Connection *Connection `pulumi:"connection" provider:"secret"`
Environment map[string]string `pulumi:"environment,optional"`
Stdin *string `pulumi:"stdin,optional"`
Logging *Logging `pulumi:"logging,optional"`
Connection *Connection `pulumi:"connection" provider:"secret"`
Environment map[string]string `pulumi:"environment,optional"`
AddPreviousOutputInEnv *bool `pulumi:"addPreviousOutputInEnv,optional"`
}

// Implementing Annotate lets you provide descriptions and default values for arguments and they will
Expand All @@ -55,6 +56,10 @@ outputs as secret via 'additionalSecretOutputs'. Defaults to logging both stdout
Note that this only works if the SSH server is configured to accept these variables via AcceptEnv.
Alternatively, if a Bash-like shell runs the command on the remote host, you could prefix the command itself
with the variables in the form 'VAR=value command'.`)
a.Describe(&c.AddPreviousOutputInEnv,
`If the previous command's stdout and stderr (as generated by the prior create/update) is
injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
Defaults to true.`)
}
julsemaan marked this conversation as resolved.
Show resolved Hide resolved

// The properties for a remote Command resource.
Expand Down
34 changes: 18 additions & 16 deletions provider/pkg/provider/remote/commandOutputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,25 @@ func (c *CommandOutputs) run(ctx context.Context, cmd string, logging *Logging)
}
}

// Set remote Stdout and Stderr environment variables optimistically, but log and continue if they fail.
if c.Stdout != "" {
err := session.Setenv(util.PULUMI_COMMAND_STDOUT, c.Stdout)
if err != nil {
// Set remote Stdout var optimistically, but warn and continue on failure.
//
//nolint:errcheck
logAndWrapSetenvErr(diag.Warning, util.PULUMI_COMMAND_STDOUT, ctx, err)
if c.AddPreviousOutputInEnv == nil || *c.AddPreviousOutputInEnv {
// Set remote Stdout and Stderr environment variables optimistically, but log and continue if they fail.
if c.Stdout != "" {
err := session.Setenv(util.PULUMI_COMMAND_STDOUT, c.Stdout)
if err != nil {
// Set remote Stdout var optimistically, but warn and continue on failure.
//
//nolint:errcheck
logAndWrapSetenvErr(diag.Warning, util.PULUMI_COMMAND_STDOUT, ctx, err)
}
}
}
if c.Stderr != "" {
err := session.Setenv(util.PULUMI_COMMAND_STDERR, c.Stderr)
if err != nil {
// Set remote STDERR var optimistically, but warn and continue on failure.
//
//nolint:errcheck
logAndWrapSetenvErr(diag.Warning, util.PULUMI_COMMAND_STDERR, ctx, err)
if c.Stderr != "" {
err := session.Setenv(util.PULUMI_COMMAND_STDERR, c.Stderr)
if err != nil {
// Set remote STDERR var optimistically, but warn and continue on failure.
//
//nolint:errcheck
logAndWrapSetenvErr(diag.Warning, util.PULUMI_COMMAND_STDERR, ctx, err)
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions sdk/dotnet/Remote/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ namespace Pulumi.Command.Remote
[CommandResourceType("command:remote:Command")]
public partial class Command : global::Pulumi.CustomResource
{
/// <summary>
/// If the previous command's stdout and stderr (as generated by the prior create/update) is
/// injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
/// Defaults to true.
/// </summary>
[Output("addPreviousOutputInEnv")]
public Output<bool?> AddPreviousOutputInEnv { get; private set; } = null!;

/// <summary>
/// The parameters with which to connect to the remote host.
/// </summary>
Expand Down Expand Up @@ -139,6 +147,14 @@ public static Command Get(string name, Input<string> id, CustomResourceOptions?

public sealed class CommandArgs : global::Pulumi.ResourceArgs
{
/// <summary>
/// If the previous command's stdout and stderr (as generated by the prior create/update) is
/// injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
/// Defaults to true.
/// </summary>
[Input("addPreviousOutputInEnv")]
public Input<bool>? AddPreviousOutputInEnv { get; set; }

[Input("connection", required: true)]
private Input<Inputs.ConnectionArgs>? _connection;

Expand Down
19 changes: 19 additions & 0 deletions sdk/go/command/remote/command.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions sdk/java/src/main/java/com/pulumi/command/remote/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.pulumi.core.annotations.Export;
import com.pulumi.core.annotations.ResourceType;
import com.pulumi.core.internal.Codegen;
import java.lang.Boolean;
import java.lang.Object;
import java.lang.String;
import java.util.List;
Expand All @@ -25,6 +26,24 @@
*/
@ResourceType(type="command:remote:Command")
public class Command extends com.pulumi.resources.CustomResource {
/**
* If the previous command&#39;s stdout and stderr (as generated by the prior create/update) is
* injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
* Defaults to true.
*
*/
@Export(name="addPreviousOutputInEnv", refs={Boolean.class}, tree="[0]")
private Output</* @Nullable */ Boolean> addPreviousOutputInEnv;

/**
* @return If the previous command&#39;s stdout and stderr (as generated by the prior create/update) is
* injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
* Defaults to true.
*
*/
public Output<Optional<Boolean>> addPreviousOutputInEnv() {
return Codegen.optional(this.addPreviousOutputInEnv);
}
/**
* The parameters with which to connect to the remote host.
*
Expand Down
46 changes: 46 additions & 0 deletions sdk/java/src/main/java/com/pulumi/command/remote/CommandArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.pulumi.core.Output;
import com.pulumi.core.annotations.Import;
import com.pulumi.exceptions.MissingRequiredPropertyException;
import java.lang.Boolean;
import java.lang.Object;
import java.lang.String;
import java.util.List;
Expand All @@ -21,6 +22,25 @@ public final class CommandArgs extends com.pulumi.resources.ResourceArgs {

public static final CommandArgs Empty = new CommandArgs();

/**
* If the previous command&#39;s stdout and stderr (as generated by the prior create/update) is
* injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
* Defaults to true.
*
*/
@Import(name="addPreviousOutputInEnv")
private @Nullable Output<Boolean> addPreviousOutputInEnv;

/**
* @return If the previous command&#39;s stdout and stderr (as generated by the prior create/update) is
* injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
* Defaults to true.
*
*/
public Optional<Output<Boolean>> addPreviousOutputInEnv() {
return Optional.ofNullable(this.addPreviousOutputInEnv);
}

/**
* The parameters with which to connect to the remote host.
*
Expand Down Expand Up @@ -164,6 +184,7 @@ public Optional<Output<String>> update() {
private CommandArgs() {}

private CommandArgs(CommandArgs $) {
this.addPreviousOutputInEnv = $.addPreviousOutputInEnv;
this.connection = $.connection;
this.create = $.create;
this.delete = $.delete;
Expand Down Expand Up @@ -192,6 +213,31 @@ public Builder(CommandArgs defaults) {
$ = new CommandArgs(Objects.requireNonNull(defaults));
}

/**
* @param addPreviousOutputInEnv If the previous command&#39;s stdout and stderr (as generated by the prior create/update) is
* injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
* Defaults to true.
*
* @return builder
*
*/
public Builder addPreviousOutputInEnv(@Nullable Output<Boolean> addPreviousOutputInEnv) {
$.addPreviousOutputInEnv = addPreviousOutputInEnv;
return this;
}

/**
* @param addPreviousOutputInEnv If the previous command&#39;s stdout and stderr (as generated by the prior create/update) is
* injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
* Defaults to true.
*
* @return builder
*
*/
public Builder addPreviousOutputInEnv(Boolean addPreviousOutputInEnv) {
return addPreviousOutputInEnv(Output.of(addPreviousOutputInEnv));
}

/**
* @param connection The parameters with which to connect to the remote host.
*
Expand Down
14 changes: 14 additions & 0 deletions sdk/nodejs/remote/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export class Command extends pulumi.CustomResource {
return obj['__pulumiType'] === Command.__pulumiType;
}

/**
* If the previous command's stdout and stderr (as generated by the prior create/update) is
* injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
* Defaults to true.
*/
public readonly addPreviousOutputInEnv!: pulumi.Output<boolean | undefined>;
/**
* The parameters with which to connect to the remote host.
*/
Expand Down Expand Up @@ -103,6 +109,7 @@ export class Command extends pulumi.CustomResource {
if ((!args || args.connection === undefined) && !opts.urn) {
throw new Error("Missing required property 'connection'");
}
resourceInputs["addPreviousOutputInEnv"] = args ? args.addPreviousOutputInEnv : undefined;
resourceInputs["connection"] = args?.connection ? pulumi.secret((args.connection ? pulumi.output(args.connection).apply(inputs.remote.connectionArgsProvideDefaults) : undefined)) : undefined;
resourceInputs["create"] = args ? args.create : undefined;
resourceInputs["delete"] = args ? args.delete : undefined;
Expand All @@ -114,6 +121,7 @@ export class Command extends pulumi.CustomResource {
resourceInputs["stderr"] = undefined /*out*/;
resourceInputs["stdout"] = undefined /*out*/;
} else {
resourceInputs["addPreviousOutputInEnv"] = undefined /*out*/;
resourceInputs["connection"] = undefined /*out*/;
resourceInputs["create"] = undefined /*out*/;
resourceInputs["delete"] = undefined /*out*/;
Expand All @@ -138,6 +146,12 @@ export class Command extends pulumi.CustomResource {
* The set of arguments for constructing a Command resource.
*/
export interface CommandArgs {
/**
* If the previous command's stdout and stderr (as generated by the prior create/update) is
* injected into the environment of the next run as PULUMI_COMMAND_STDOUT and PULUMI_COMMAND_STDERR.
* Defaults to true.
*/
addPreviousOutputInEnv?: pulumi.Input<boolean>;
/**
* The parameters with which to connect to the remote host.
*/
Expand Down
Loading