diff --git a/builder/profitbricks/step_create_server.go b/builder/profitbricks/step_create_server.go index 89b0ad7f0..102149a05 100644 --- a/builder/profitbricks/step_create_server.go +++ b/builder/profitbricks/step_create_server.go @@ -1,6 +1,7 @@ package profitbricks import ( + "encoding/json" "errors" "fmt" "github.com/mitchellh/multistep" @@ -62,7 +63,7 @@ func (s *stepCreateServer) Run(state multistep.StateBag) multistep.StepAction { datacenter = profitbricks.CompositeCreateDatacenter(datacenter) if datacenter.StatusCode > 299 { - ui.Error(datacenter.Response) + ui.Error(parseErrorMessage(datacenter.Response)) return multistep.ActionHalt } s.waitTillProvisioned(datacenter.Headers.Get("Location"), *c) @@ -77,7 +78,7 @@ func (s *stepCreateServer) Run(state multistep.StateBag) multistep.StepAction { }) if lan.StatusCode > 299 { - ui.Error(fmt.Sprintf("Error occured %s", lan.Response)) + ui.Error(fmt.Sprintf("Error occured %s", parseErrorMessage(lan.Response))) return multistep.ActionHalt } @@ -93,7 +94,7 @@ func (s *stepCreateServer) Run(state multistep.StateBag) multistep.StepAction { }) if lan.StatusCode > 299 { - ui.Error(fmt.Sprintf("Error occured %s", nic.Response)) + ui.Error(fmt.Sprintf("Error occured %s", parseErrorMessage(nic.Response))) return multistep.ActionHalt } @@ -180,3 +181,17 @@ func (d *stepCreateServer) getImageId(imageName string, c *Config) string { } return "" } + +func parseErrorMessage(raw string) (toreturn string) { + var tmp map[string]interface{} + json.Unmarshal([]byte(raw), &tmp) + + for _, v := range tmp["messages"].([]interface{}) { + for index, i := range v.(map[string]interface{}) { + if index == "message" { + toreturn = toreturn + i.(string) + "\n" + } + } + } + return toreturn +} diff --git a/website/source/docs/builders/profitbricks.html.md b/website/source/docs/builders/profitbricks.html.md index da3182ed7..0b59bcf60 100644 --- a/website/source/docs/builders/profitbricks.html.md +++ b/website/source/docs/builders/profitbricks.html.md @@ -25,7 +25,7 @@ builder. ### Required -- `image` (string) - ProfitBricks volume image +- `image` (string) - ProfitBricks volume image. Only Linux public images are supported. Defaults to "Ubuntu-16.04". To obtain full list of available images you can use [ProfitBricks CLI](https://github.com/profitbricks/profitbricks-cli#image). - `password` (string) - ProfitBrucks password. This can be specified via environment variable `PROFITBRICKS_PASSWORD', if provided. The value definded in the config has precedence over environemnt variable.