generated from pulumi/pulumi-provider-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a freeform command resource * Typo * Implement a command component * Regen SDKs
- Loading branch information
1 parent
9acb8f2
commit a7835aa
Showing
23 changed files
with
1,392 additions
and
244 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/pulumi/pulumi-go-provider/infer" | ||
pb "github.com/unmango/pulumi-baremetal/gen/go/unmango/baremetal/v1alpha1" | ||
"github.com/unmango/pulumi-baremetal/provider/pkg/provider/internal/logger" | ||
"github.com/unmango/pulumi-baremetal/provider/pkg/provider/internal/provisioner" | ||
) | ||
|
||
type CommandArgs struct { | ||
Args []string `pulumi:"args"` | ||
Triggers []any `pulumi:"triggers,optional"` | ||
} | ||
|
||
type Command struct{} | ||
|
||
type CommandState struct { | ||
CommandArgs | ||
|
||
ExitCode int `pulumi:"exitCode"` | ||
Stdout string `pulumi:"stdout"` | ||
Stderr string `pulumi:"stderr"` | ||
} | ||
|
||
// Create implements infer.CustomCreate. | ||
func (Command) Create(ctx context.Context, name string, inputs CommandArgs, preview bool) (string, CommandState, error) { | ||
log := logger.FromContext(ctx) | ||
state := CommandState{} | ||
|
||
p, err := provisioner.FromContext(ctx) | ||
if err != nil { | ||
log.Error("Failed creating provisioner") | ||
return name, state, fmt.Errorf("creating provisioner: %w", err) | ||
} | ||
|
||
if preview { | ||
if _, err = p.Ping(ctx, &pb.PingRequest{}); err != nil { | ||
log.WarningStatusf("Failed pinging provisioner: %s", err) | ||
} | ||
|
||
return name, state, nil | ||
} | ||
|
||
display := display(inputs.Args) | ||
log.DebugStatus("Sending exec request to provisioner") | ||
res, err := p.Exec(ctx, &pb.ExecRequest{ | ||
Args: inputs.Args, | ||
}) | ||
if err != nil { | ||
log.Errorf("command:%s %s", display, err) | ||
return name, state, fmt.Errorf("sending exec request: %w", err) | ||
} | ||
|
||
if res.Result.ExitCode > 0 { | ||
log.Error(display) | ||
return name, state, fmt.Errorf("exec failed: %s", res.Result) | ||
} | ||
|
||
state.CommandArgs = inputs | ||
state.ExitCode = int(res.Result.ExitCode) | ||
state.Stdout = res.Result.Stdout | ||
state.Stderr = res.Result.Stderr | ||
|
||
log.InfoStatus(display) | ||
return name, state, nil | ||
} | ||
|
||
var _ = (infer.CustomCreate[CommandArgs, CommandState])((*Command)(nil)) | ||
|
||
func display(args []string) string { | ||
return strings.Join(args, " ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// *** WARNING: this file was generated by pulumi. *** | ||
// *** Do not edit by hand unless you're certain you know what you are doing! *** | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Threading.Tasks; | ||
using Pulumi.Serialization; | ||
using Pulumi; | ||
|
||
namespace UnMango.Baremetal.Command | ||
{ | ||
[BaremetalResourceType("baremetal:command:Command")] | ||
public partial class Command : global::Pulumi.CustomResource | ||
{ | ||
[Output("args")] | ||
public Output<ImmutableArray<string>> Args { get; private set; } = null!; | ||
|
||
[Output("exitCode")] | ||
public Output<int> ExitCode { get; private set; } = null!; | ||
|
||
[Output("stderr")] | ||
public Output<string> Stderr { get; private set; } = null!; | ||
|
||
[Output("stdout")] | ||
public Output<string> Stdout { get; private set; } = null!; | ||
|
||
[Output("triggers")] | ||
public Output<ImmutableArray<object>> Triggers { get; private set; } = null!; | ||
|
||
|
||
/// <summary> | ||
/// Create a Command resource with the given unique name, arguments, and options. | ||
/// </summary> | ||
/// | ||
/// <param name="name">The unique name of the resource</param> | ||
/// <param name="args">The arguments used to populate this resource's properties</param> | ||
/// <param name="options">A bag of options that control this resource's behavior</param> | ||
public Command(string name, CommandArgs args, CustomResourceOptions? options = null) | ||
: base("baremetal:command:Command", name, args ?? new CommandArgs(), MakeResourceOptions(options, "")) | ||
{ | ||
} | ||
|
||
private Command(string name, Input<string> id, CustomResourceOptions? options = null) | ||
: base("baremetal:command:Command", name, null, MakeResourceOptions(options, id)) | ||
{ | ||
} | ||
|
||
private static CustomResourceOptions MakeResourceOptions(CustomResourceOptions? options, Input<string>? id) | ||
{ | ||
var defaultOptions = new CustomResourceOptions | ||
{ | ||
Version = Utilities.Version, | ||
PluginDownloadURL = "github://api.github.com/unmango", | ||
}; | ||
var merged = CustomResourceOptions.Merge(defaultOptions, options); | ||
// Override the ID if one was specified for consistency with other language SDKs. | ||
merged.Id = id ?? merged.Id; | ||
return merged; | ||
} | ||
/// <summary> | ||
/// Get an existing Command resource's state with the given name, ID, and optional extra | ||
/// properties used to qualify the lookup. | ||
/// </summary> | ||
/// | ||
/// <param name="name">The unique name of the resulting resource.</param> | ||
/// <param name="id">The unique provider ID of the resource to lookup.</param> | ||
/// <param name="options">A bag of options that control this resource's behavior</param> | ||
public static Command Get(string name, Input<string> id, CustomResourceOptions? options = null) | ||
{ | ||
return new Command(name, id, options); | ||
} | ||
} | ||
|
||
public sealed class CommandArgs : global::Pulumi.ResourceArgs | ||
{ | ||
[Input("args", required: true)] | ||
private InputList<string>? _args; | ||
public InputList<string> Args | ||
{ | ||
get => _args ?? (_args = new InputList<string>()); | ||
set => _args = value; | ||
} | ||
|
||
[Input("triggers")] | ||
private InputList<object>? _triggers; | ||
public InputList<object> Triggers | ||
{ | ||
get => _triggers ?? (_triggers = new InputList<object>()); | ||
set => _triggers = value; | ||
} | ||
|
||
public CommandArgs() | ||
{ | ||
} | ||
public static new CommandArgs Empty => new CommandArgs(); | ||
} | ||
} |
Empty file.
Oops, something went wrong.