2017-10-16 21:04:35 +02:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-10-27 07:14:56 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/apitype"
|
2017-10-16 21:04:35 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newStackInitCmd() *cobra.Command {
|
2017-10-27 07:14:56 +02:00
|
|
|
if usePulumiCloudCommands() {
|
|
|
|
return newCloudStackInitCmd()
|
|
|
|
}
|
|
|
|
return newFAFStackInitCmd()
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFAFStackInitCmd() *cobra.Command {
|
2017-10-16 21:04:35 +02:00
|
|
|
return &cobra.Command{
|
|
|
|
Use: "init <stack>",
|
2017-10-27 07:14:56 +02:00
|
|
|
Args: cobra.ExactArgs(1),
|
2017-10-16 21:04:35 +02:00
|
|
|
Short: "Create an empty stack with the given name, ready for updates",
|
|
|
|
Long: "Create an empty stack with the given name, ready for updates\n" +
|
|
|
|
"\n" +
|
|
|
|
"This command creates an empty stack with the given name. It has no resources,\n" +
|
|
|
|
"but afterwards it can become the target of a deployment using the `update` command.",
|
|
|
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
2017-11-01 21:34:19 +01:00
|
|
|
var backend pulumiBackend = &localPulumiBackend{}
|
2017-10-16 21:04:35 +02:00
|
|
|
|
2017-11-01 21:34:19 +01:00
|
|
|
stackName := tokens.QName(args[0])
|
2017-10-16 21:04:35 +02:00
|
|
|
|
2017-11-01 21:34:19 +01:00
|
|
|
if err := backend.CreateStack(stackName); err != nil {
|
2017-10-16 21:04:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-10-31 01:47:12 +01:00
|
|
|
return setCurrentStack(stackName)
|
2017-10-16 21:04:35 +02:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
2017-10-27 07:14:56 +02:00
|
|
|
|
|
|
|
func newCloudStackInitCmd() *cobra.Command {
|
|
|
|
var cloud string
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "init <stack>",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Short: "Create an empty stack with the given name, ready for updates",
|
|
|
|
Long: "Create an empty stack with the given name, ready for updates\n" +
|
|
|
|
"\n" +
|
|
|
|
"This command creates an empty stack with the given name. It has no resources,\n" +
|
|
|
|
"but afterwards it can become the target of a deployment using the `update` command.",
|
|
|
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
2017-10-31 01:47:12 +01:00
|
|
|
// Look up the owner, repository, and project from the workspace and nearest package.
|
|
|
|
w, err := newWorkspace()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
projID, err := getCloudProjectIdentifier(w)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-10-27 07:14:56 +02:00
|
|
|
stackName := args[0]
|
|
|
|
createStackReq := apitype.CreateStackRequest{
|
|
|
|
CloudName: cloud,
|
|
|
|
StackName: stackName,
|
|
|
|
}
|
|
|
|
|
|
|
|
var createStackResp apitype.CreateStackResponse
|
2017-10-31 01:47:12 +01:00
|
|
|
path := fmt.Sprintf("/orgs/%s/programs/%s/%s/stacks", projID.Owner, projID.Repository, projID.Project)
|
2017-10-27 07:14:56 +02:00
|
|
|
if err := pulumiRESTCall("POST", path, &createStackReq, &createStackResp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Printf("Created Stack '%s' hosted in Cloud '%s'\n", stackName, createStackResp.CloudName)
|
|
|
|
|
|
|
|
stackQName := tokens.QName(stackName)
|
2017-10-31 01:47:12 +01:00
|
|
|
return setCurrentStack(stackQName)
|
2017-10-27 07:14:56 +02:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
2017-10-31 01:47:12 +01:00
|
|
|
// If not set will use the "default" cloud for the organization.
|
2017-10-27 07:14:56 +02:00
|
|
|
cmd.PersistentFlags().StringVarP(
|
|
|
|
&cloud, "cloud", "c", "",
|
|
|
|
"Target cloud")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|