diff --git a/glide.lock b/glide.lock index b8e395a..f3873f3 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 3376e32cf5d5ceac32ebf18afeceff4ecf9a0f46049cc71655072e163c770aa9 -updated: 2018-01-13T20:38:40.8020517-06:00 +hash: f10eebcb5626b953fac7a6a6a1df87070d955b7c1c60a04ca9e0b95058132644 +updated: 2018-01-15T22:32:59.5281924-06:00 imports: - name: github.com/Azure/go-ntlmssp version: c92175d540060095c69ced311f76aea56c83ecdb @@ -96,7 +96,7 @@ imports: - name: github.com/pkg/sftp version: 72ec6e85598d2480c30f633c154b07b6c112eade - name: github.com/sandwichcloud/deli-cli - version: 0140b24c73e59e3151fbdc2fb33f203b906688ec + version: 851787e73850ccae3d209fcbf9d8bbc303516f36 subpackages: - api - api/client diff --git a/glide.yaml b/glide.yaml index a0a60f0..d43e60f 100644 --- a/glide.yaml +++ b/glide.yaml @@ -5,4 +5,4 @@ import: - package: github.com/mitchellh/multistep version: 391576a156a54cfbb4cf5d5eda40cf6ffa3e3a4d - package: github.com/sandwichcloud/deli-cli - version: 0.0.14 + version: 0.0.16 diff --git a/sandwich/image_config.go b/sandwich/image_config.go index e2601f5..0f80624 100644 --- a/sandwich/image_config.go +++ b/sandwich/image_config.go @@ -7,7 +7,9 @@ import ( ) type ImageConfig struct { - ImageName string `mapstructure:"image_name"` + ImageName string `mapstructure:"image_name"` + ImagePublic bool `mapstructure:"image_public"` + ImageMembers []string `mapstructure:"image_members"` } func (c *ImageConfig) Prepare(ctx *interpolate.Context) []error { diff --git a/sandwich/step_image_instance.go b/sandwich/step_image_instance.go index 0c67fca..4a4d6bb 100644 --- a/sandwich/step_image_instance.go +++ b/sandwich/step_image_instance.go @@ -21,7 +21,7 @@ func (s *StepImageInstance) Run(state multistep.StateBag) multistep.StepAction { instanceClient := config.sandwichClient.Instance() imageClient := config.sandwichClient.Image() - image, err := instanceClient.ActionImage(instance.ID.String(), config.ImageName, "PRIVATE") + image, err := instanceClient.ActionImage(instance.ID.String(), config.ImageName) if err != nil { err := fmt.Errorf("Error imaging instance: %s", err) state.Put("error", err) @@ -47,6 +47,26 @@ func (s *StepImageInstance) Run(state multistep.StateBag) multistep.StepAction { state.Put("imageID", image.ID.String()) + if config.ImagePublic { + err := imageClient.ActionSetVisibility(image.ID.String(), true) + if err != nil { + err := fmt.Errorf("Error making image public: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } else { + for _, memberID := range config.ImageMembers { + err := imageClient.MemberAdd(image.ID.String(), memberID) + if err != nil { + err := fmt.Errorf("Error adding image member: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } + } + ui.Say("Image has been created.") return multistep.ActionContinue