Pass cloud name in options bag instead of an explicit parameter

This commit is contained in:
Matt Ellis 2017-11-02 10:40:42 -07:00
parent ab7c4c121f
commit a27d2bde72
4 changed files with 10 additions and 6 deletions

View file

@ -15,10 +15,14 @@ type stackSummary struct {
ResourceCount string
}
type StackCreationOptions struct {
Cloud string
}
var errHasResources = errors.New("stack has existing resources and force was false")
type pulumiBackend interface {
CreateStack(stackName tokens.QName, cloud string) error
CreateStack(stackName tokens.QName, opts StackCreationOptions) error
GetStacks() ([]stackSummary, error)
RemoveStack(stackName tokens.QName, force bool) error

View file

@ -23,14 +23,14 @@ import (
type pulumiCloudPulumiBackend struct{}
func (b *pulumiCloudPulumiBackend) CreateStack(stackName tokens.QName, cloud string) error {
func (b *pulumiCloudPulumiBackend) CreateStack(stackName tokens.QName, opts StackCreationOptions) error {
projID, err := getCloudProjectIdentifier()
if err != nil {
return err
}
createStackReq := apitype.CreateStackRequest{
CloudName: cloud,
CloudName: opts.Cloud,
StackName: stackName.String(),
}

View file

@ -20,8 +20,8 @@ import (
type localPulumiBackend struct{}
func (b *localPulumiBackend) CreateStack(stackName tokens.QName, cloud string) error {
contract.Requiref(cloud == "", "cloud", "local backend does not support clouds, cloud must be empty")
func (b *localPulumiBackend) CreateStack(stackName tokens.QName, opts StackCreationOptions) error {
contract.Requiref(opts.Cloud == "", "cloud", "local backend does not support clouds, cloud must be empty")
if _, _, _, err := getStack(stackName); err == nil {
return errors.Errorf("stack '%v' already exists", stackName)

View file

@ -24,7 +24,7 @@ func newStackInitCmd() *cobra.Command {
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
stackName := tokens.QName(args[0])
if err := backend.CreateStack(stackName, cloud); err != nil {
if err := backend.CreateStack(stackName, StackCreationOptions{Cloud: cloud}); err != nil {
return err
}