Merge pull request #5874 from hashicorp/do_5866

fail in oracle classic builder if user tries winrm since it doesn't w…
This commit is contained in:
Matthew Hooker 2018-02-08 14:57:35 -08:00 committed by GitHub
commit 125a9133d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 1 deletions

View File

@ -1,8 +1,11 @@
package classic
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"os"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/communicator"
@ -14,6 +17,7 @@ import (
type Config struct {
common.PackerConfig `mapstructure:",squash"`
Comm communicator.Config `mapstructure:",squash"`
attribs map[string]interface{}
// Access config overrides
Username string `mapstructure:"username"`
@ -27,6 +31,9 @@ type Config struct {
Shape string `mapstructure:"shape"`
SourceImageList string `mapstructure:"source_image_list"`
DestImageList string `mapstructure:"dest_image_list"`
// Attributes and Atributes file are both optional and mutually exclusive.
Attributes string `mapstructure:"attributes"`
AttributesFile string `mapstructure:"attributes_file"`
// Optional; if you don't enter anything, the image list description
// will read "Packer-built image list"
DestImageListDescription string `mapstructure:"image_description"`
@ -81,13 +88,50 @@ func NewConfig(raws ...interface{}) (*Config, error) {
}
}
if c.Attributes != "" && c.AttributesFile != "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Only one of user_data or user_data_file can be specified."))
} else if c.AttributesFile != "" {
if _, err := os.Stat(c.AttributesFile); err != nil {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("attributes_file not found: %s", c.AttributesFile))
}
}
if es := c.Comm.Prepare(&c.ctx); len(es) > 0 {
errs = packer.MultiErrorAppend(errs, es...)
}
if c.Comm.Type == "winrm" {
err = fmt.Errorf("winRM is not supported with the oracle-classic builder yet.")
errs = packer.MultiErrorAppend(errs, err)
}
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
}
// unpack attributes from json into config
var data map[string]interface{}
if c.Attributes != "" {
err := json.Unmarshal([]byte(c.Attributes), &data)
if err != nil {
err = fmt.Errorf("Problem parsing json from attributes: %s", err)
packer.MultiErrorAppend(errs, err)
}
c.attribs = data
} else if c.AttributesFile != "" {
fidata, err := ioutil.ReadFile(c.AttributesFile)
if err != nil {
err = fmt.Errorf("Problem reading attributes_file: %s", err)
packer.MultiErrorAppend(errs, err)
}
err = json.Unmarshal(fidata, &data)
c.attribs = data
if err != nil {
err = fmt.Errorf("Problem parsing json from attrinutes_file: %s", err)
packer.MultiErrorAppend(errs, err)
}
c.attribs = data
}
return c, nil
}

View File

@ -37,6 +37,7 @@ func (s *stepCreateInstance) Run(_ context.Context, state multistep.StateBag) mu
ImageList: config.SourceImageList,
SSHKeys: []string{keyName},
Networking: map[string]compute.NetworkingInfo{"eth0": netInfo},
Attributes: config.attribs,
}
instanceInfo, err := instanceClient.CreateInstance(input)

View File

@ -63,6 +63,16 @@ This builder currently only works with the SSH communicator.
### Optional
- `attributes` (string) - (string) - Attributes to apply when launching the
instance. Note that you need to be careful about escaping characters due to
the templates being JSON. It is often more convenient to use
`attributes_file`, instead. You may only define either `attributes` or
`attributes_file`, not both.
- `attributes_file` (string) - Path to a json file that will be used for the
attributes when launching the instance. You may only define either
`attributes` or `attributes_file`, not both.
- `image_description` (string) - a description for your destination
image list. If you don't provide one, Packer will provide a generic description.
@ -91,7 +101,8 @@ obfuscated; you will need to add a working `username`, `password`,
"api_endpoint": "https://api-###.compute.###.oraclecloud.com/",
"source_image_list": "/oracle/public/OL_7.2_UEKR4_x86_64",
"shape": "oc3",
"image_name": "Packer_Builder_Test_{{timestamp}}"
"image_name": "Packer_Builder_Test_{{timestamp}}",
"attributes": "{\"userdata\": {\"pre-bootstrap\": {\"script\": [\"...\"]}}}",
"dest_image_list": "Packer_Builder_Test_List"
}
],