2018-01-12 17:12:15 -05:00
|
|
|
package classic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-01-12 18:44:40 -05:00
|
|
|
"net/url"
|
2018-01-12 17:12:15 -05:00
|
|
|
|
|
|
|
"github.com/hashicorp/packer/common"
|
|
|
|
"github.com/hashicorp/packer/helper/communicator"
|
|
|
|
"github.com/hashicorp/packer/helper/config"
|
2018-01-18 18:52:31 -05:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2018-01-12 17:12:15 -05:00
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
|
|
|
Comm communicator.Config `mapstructure:",squash"`
|
|
|
|
|
|
|
|
Access *AccessConfig
|
|
|
|
|
|
|
|
// Access config overrides
|
|
|
|
Username string `mapstructure:"username"`
|
|
|
|
Password string `mapstructure:"password"`
|
|
|
|
IdentityDomain string `mapstructure:"identity_domain"`
|
|
|
|
APIEndpoint string `mapstructure:"api_endpoint"`
|
2018-01-12 18:44:40 -05:00
|
|
|
apiEndpointURL *url.URL
|
2018-01-12 17:12:15 -05:00
|
|
|
|
|
|
|
// Image
|
2018-01-17 16:07:41 -05:00
|
|
|
ImageName string `mapstructure:"image_name"`
|
2018-01-12 17:12:15 -05:00
|
|
|
Shape string `mapstructure:"shape"`
|
2018-01-17 19:25:38 -05:00
|
|
|
ImageList string `mapstructure:"image_list"`
|
2018-01-23 14:07:04 -05:00
|
|
|
// Optional. Describes what computers are allowed to reach your instance
|
|
|
|
// via SSH. This whitelist must contain the computer you're running Packer
|
|
|
|
// from. It defaults to public-internet, meaning that you can SSH into your
|
|
|
|
// instance from anywhere as long as you have the right keys
|
|
|
|
SSHSourceList string `mapstructure:"ssh_source_list"`
|
2018-01-12 17:12:15 -05:00
|
|
|
|
|
|
|
ctx interpolate.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewConfig(raws ...interface{}) (*Config, error) {
|
|
|
|
c := &Config{}
|
|
|
|
|
|
|
|
// Decode from template
|
|
|
|
err := config.Decode(c, &config.DecodeOpts{
|
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &c.ctx,
|
|
|
|
}, raws...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Failed to mapstructure Config: %+v", err)
|
|
|
|
}
|
|
|
|
|
2018-01-12 18:44:40 -05:00
|
|
|
c.apiEndpointURL, err = url.Parse(c.APIEndpoint)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error parsing API Endpoint: %s", err)
|
|
|
|
}
|
2018-01-23 14:07:04 -05:00
|
|
|
// set default source list
|
|
|
|
if c.SSHSourceList == "" {
|
|
|
|
c.SSHSourceList = "seciplist:/oracle/public/public-internet"
|
|
|
|
}
|
2018-01-12 18:44:40 -05:00
|
|
|
|
2018-01-18 18:52:31 -05:00
|
|
|
var errs *packer.MultiError
|
|
|
|
if es := c.Comm.Prepare(&c.ctx); len(es) > 0 {
|
|
|
|
errs = packer.MultiErrorAppend(errs, es...)
|
|
|
|
}
|
|
|
|
|
2018-01-12 17:12:15 -05:00
|
|
|
return c, nil
|
|
|
|
}
|