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

[auto/nodejs] Support for remote operations #11170

Merged
merged 1 commit into from Oct 28, 2022
Merged

[auto/nodejs] Support for remote operations #11170

merged 1 commit into from Oct 28, 2022

Conversation

justinvp
Copy link
Member

@justinvp justinvp commented Oct 27, 2022

This change adds preview support for remote operations in Node.js's Automation API.

Here's an example of using it:

import * as process from "process";
import { RemoteWorkspace, fullyQualifiedStackName } from "@pulumi/pulumi/automation";

const args = process.argv.slice(2);
const destroy = args.length > 0 && args[0] === "destroy";

const org = "justinvp";
const projectName = "aws-ts-s3-folder";
const stackName = fullyQualifiedStackName(org, projectName, "devnode");

(async function() {
    const stack = await RemoteWorkspace.createOrSelectStack({
        stackName,
        url: "https://github.com/pulumi/examples.git",
        branch: "refs/heads/master",
        projectPath: projectName,
    }, {
        envVars: {
            AWS_REGION:            "us-west-2",
            AWS_ACCESS_KEY_ID:     process.env.AWS_ACCESS_KEY_ID ?? "",
            AWS_SECRET_ACCESS_KEY: { secret: process.env.AWS_SECRET_ACCESS_KEY ?? "" },
            AWS_SESSION_TOKEN:     { secret: process.env.AWS_SESSION_TOKEN ?? "" },
        },
    });

    if (destroy) {
        await stack.destroy({ onOutput: out => process.stdout.write(out) });
        console.log("Stack successfully destroyed");
        process.exit(0);
    }

    const upRes = await stack.up({ onOutput: out => process.stdout.write(out) });
    console.log("Update succeeded!");
    console.log(`url: ${upRes.outputs.websiteUrl.value}`);
})();

I will add sanity tests subsequently.

@justinvp justinvp requested a review from a team October 27, 2022 19:12
@pulumi-bot
Copy link
Contributor

pulumi-bot commented Oct 27, 2022

Changelog

[uncommitted] (2022-10-28)

Features

  • [auto/nodejs] Support for remote operations
    #11170

@justinvp
Copy link
Member Author

bors merge

bors bot added a commit that referenced this pull request Oct 28, 2022
11168: [auto/go] Support for remote operations r=justinvp a=justinvp

This change adds preview support for remote operations in Go's Automation API.

Here's an example of using it:

```go
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/pulumi/pulumi/sdk/v3/go/auto"
	"github.com/pulumi/pulumi/sdk/v3/go/auto/optremotedestroy"
	"github.com/pulumi/pulumi/sdk/v3/go/auto/optremoteup"
)

func main() {
	// to destroy our program, we can run `go run main.go destroy`
	var preview, destroy, refresh bool
	argsWithoutProg := os.Args[1:]
	destroy := len(argsWithoutProg) > 0 && argsWithoutProg[0] == "destroy"
	ctx := context.Background()

	org := "justinvp"
	projectName := "aws-ts-s3-folder"
	stackName := auto.FullyQualifiedStackName(org, projectName, "devgo")

	repo := auto.GitRepo{
		URL:         "https://github.com/pulumi/examples.git",
		Branch:      "refs/heads/master",
		ProjectPath: projectName,
	}

	env := map[string]auto.EnvVarValue{
		"AWS_REGION":            {Value: "us-west-2"},
		"AWS_ACCESS_KEY_ID":     {Value: os.Getenv("AWS_ACCESS_KEY_ID")},
		"AWS_SECRET_ACCESS_KEY": {Value: os.Getenv("AWS_SECRET_ACCESS_KEY"), Secret: true},
		"AWS_SESSION_TOKEN":     {Value: os.Getenv("AWS_SESSION_TOKEN"), Secret: true},
	}

	s, err := auto.UpsertRemoteStackGitSource(ctx, stackName, repo, auto.RemoteEnvVars(env))
	if err != nil {
		fmt.Printf("Failed to create or select stack: %v\n", err)
		os.Exit(1)
	}

	if destroy {
		stdoutStreamer := optremotedestroy.ProgressStreams(os.Stdout)
		_, err := s.Destroy(ctx, stdoutStreamer)
		if err != nil {
			fmt.Printf("Failed to destroy stack: %v", err)
		}
		fmt.Println("Stack successfully destroyed")
		os.Exit(0)
	}


	stdoutStreamer := optremoteup.ProgressStreams(os.Stdout)
	res, err := s.Up(ctx, stdoutStreamer)
	if err != nil {
		fmt.Printf("Failed to update stack: %v\n\n", err)
		os.Exit(1)
	}

	fmt.Println("Update succeeded!")

	url, ok := res.Outputs["websiteUrl"].Value.(string)
	if !ok {
		fmt.Println("Failed to unmarshall output URL")
		os.Exit(1)
	}
	fmt.Printf("URL: %s\n", url)
}
```

I will add sanity tests subsequently.

11170: [auto/nodejs] Support for remote operations r=justinvp a=justinvp

This change adds preview support for remote operations in Node.js's Automation API.

Here's an example of using it:

```ts
import * as process from "process";
import { RemoteWorkspace, fullyQualifiedStackName } from "`@pulumi/pulumi/automation";`

const args = process.argv.slice(2);
const destroy = args.length > 0 && args[0] === "destroy";

const org = "justinvp";
const projectName = "aws-ts-s3-folder";
const stackName = fullyQualifiedStackName(org, projectName, "devnode");

(async function() {
    const stack = await RemoteWorkspace.createOrSelectStack({
        stackName,
        url: "https://github.com/pulumi/examples.git",
        branch: "refs/heads/master",
        projectPath: projectName,
    }, {
        envVars: {
            AWS_REGION:            "us-west-2",
            AWS_ACCESS_KEY_ID:     process.env.AWS_ACCESS_KEY_ID ?? "",
            AWS_SECRET_ACCESS_KEY: { secret: process.env.AWS_SECRET_ACCESS_KEY ?? "" },
            AWS_SESSION_TOKEN:     { secret: process.env.AWS_SESSION_TOKEN ?? "" },
        },
    });

    if (destroy) {
        await stack.destroy({ onOutput: out => process.stdout.write(out) });
        console.log("Stack successfully destroyed");
        process.exit(0);
    }

    const upRes = await stack.up({ onOutput: out => process.stdout.write(out) });
    console.log("Update succeeded!");
    console.log(`url: ${upRes.outputs.websiteUrl.value}`);
})();
```

I will add sanity tests subsequently.

Co-authored-by: Justin Van Patten <jvp@justinvp.com>
@bors
Copy link
Contributor

bors bot commented Oct 28, 2022

This PR was included in a batch that was canceled, it will be automatically retried

@bors
Copy link
Contributor

bors bot commented Oct 28, 2022

Canceled.

@justinvp
Copy link
Member Author

bors merge

@bors
Copy link
Contributor

bors bot commented Oct 28, 2022

Build succeeded:

@bors bors bot merged commit bbde400 into master Oct 28, 2022
@pulumi-bot pulumi-bot deleted the justin/remote_node branch October 28, 2022 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants