unpack attributes in oracle-classic builder earlier so that we error fast if there's an issue
This commit is contained in:
parent
ff717c5784
commit
7f631fcb77
@ -1,7 +1,9 @@
|
||||
package classic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
@ -15,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"`
|
||||
@ -105,5 +108,30 @@ func NewConfig(raws ...interface{}) (*Config, error) {
|
||||
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
|
||||
}
|
||||
|
@ -2,9 +2,7 @@ package classic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/hashicorp/go-oracle-terraform/compute"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
@ -32,33 +30,6 @@ func (s *stepCreateInstance) Run(_ context.Context, state multistep.StateBag) mu
|
||||
// get instances client
|
||||
instanceClient := client.Instances()
|
||||
|
||||
var data map[string]interface{}
|
||||
|
||||
if config.Attributes != "" {
|
||||
err := json.Unmarshal([]byte(config.Attributes), &data)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Problem parsing json from attributes: %s", err)
|
||||
ui.Error(err.Error())
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
} else if config.AttributesFile != "" {
|
||||
fidata, err := ioutil.ReadFile(config.AttributesFile)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Problem reading attributes_file: %s", err)
|
||||
ui.Error(err.Error())
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
err = json.Unmarshal(fidata, &data)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Problem parsing json from attrinutes_file: %s", err)
|
||||
ui.Error(err.Error())
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
}
|
||||
|
||||
// Instances Input
|
||||
input := &compute.CreateInstanceInput{
|
||||
Name: config.ImageName,
|
||||
@ -66,7 +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: data,
|
||||
Attributes: config.attribs,
|
||||
}
|
||||
|
||||
instanceInfo, err := instanceClient.CreateInstance(input)
|
||||
|
Loading…
x
Reference in New Issue
Block a user