pulumi/cmd/stack_export.go
Luke Hoban 5ede33e03d
Run tests against managed stacks backend instead of FnF (#1092)
Tests now target managed stacks instead of local stacks.

The existing logged in user and target backend API are used unless PULUMI_ACCES_TOKEN is defined, in which case tests are run under that access token and against the PULUMI_API backend.

For developer machines, we will now need to be logged in to Pulumi to run tests, and whichever default API backend is logged in (the one listed as current in ~/.pulumi/credentials.json) will be used. If you need to override these, provide PULUMI_ACCESS_TOKEN and possibly PULUMI_API.

For Travis, we currently target the staging service using the Pulumi Bot user.

We have decided to run tests in the pulumi organization. This can be overridden for local testing (or in Travis in the future) by defining PULUMI_API_OWNER_ORGANIZATION and using an access token with access to that organization.

Part of pulumi/home#195.
2018-04-02 21:34:54 -07:00

61 lines
1.5 KiB
Go

// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
package cmd
import (
"encoding/json"
"os"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/pulumi/pulumi/pkg/util/cmdutil"
)
func newStackExportCmd() *cobra.Command {
var file string
cmd := &cobra.Command{
Use: "export",
Args: cmdutil.MaximumNArgs(0),
Short: "Export a stack's deployment to standard out",
Long: "Export a stack's deployment to standard out.\n" +
"\n" +
"The deployment can then be hand-edited and used to update the stack via\n" +
"`pulumi stack import`. This process may be used to correct inconsistencies\n" +
"in a stack's state due to failed deployments, manual changes to cloud\n" +
"resources, etc.",
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
// Fetch the current stack and export its deployment
s, err := requireCurrentStack(false)
if err != nil {
return err
}
deployment, err := s.ExportDeployment()
if err != nil {
return err
}
// Read from stdin or a specified file.
writer := os.Stdout
if file != "" {
writer, err = os.Create(file)
if err != nil {
return errors.Wrap(err, "could not open file")
}
}
// Write the deployment.
enc := json.NewEncoder(writer)
enc.SetIndent("", " ")
if err = enc.Encode(deployment); err != nil {
return errors.Wrap(err, "could not export deployment")
}
return nil
}),
}
cmd.PersistentFlags().StringVarP(
&file, "file", "", "", "A filename to write stack output to")
return cmd
}