Commit 84189f7a authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/*: properly save interpolation context

parent d6004564
......@@ -35,7 +35,7 @@ type Config struct {
MountPath string `mapstructure:"mount_path"`
SourceAmi string `mapstructure:"source_ami"`
ctx *interpolate.Context
ctx interpolate.Context
}
type wrappedCommandTemplate struct {
......@@ -48,10 +48,10 @@ type Builder struct {
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.ctx = &interpolate.Context{Funcs: awscommon.TemplateFuncs}
b.config.ctx.Funcs = awscommon.TemplateFuncs
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: b.config.ctx,
InterpolateContext: &b.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"command_wrapper",
......@@ -96,8 +96,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Accumulate any errors
var errs *packer.MultiError
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(&b.config.ctx)...)
for _, mounts := range b.config.ChrootMounts {
if len(mounts) != 3 {
......@@ -132,7 +132,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ec2conn := ec2.New(config)
wrappedCommand := func(command string) (string, error) {
ctx := *b.config.ctx
ctx := b.config.ctx
ctx.Data = &wrappedCommandTemplate{Command: command}
return interpolate.Render(b.config.CommandWrapper, &ctx)
}
......
......@@ -33,7 +33,7 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction {
device := state.Get("device").(string)
wrappedCommand := state.Get("wrappedCommand").(CommandWrapper)
ctx := *config.ctx
ctx := config.ctx
ctx.Data = &mountPathData{Device: filepath.Base(device)}
mountPath, err := interpolate.Render(config.MountPath, &ctx)
......
......@@ -29,7 +29,7 @@ type Config struct {
awscommon.BlockDevices `mapstructure:",squash"`
awscommon.RunConfig `mapstructure:",squash"`
ctx *interpolate.Context
ctx interpolate.Context
}
type Builder struct {
......@@ -38,10 +38,10 @@ type Builder struct {
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.ctx = &interpolate.Context{Funcs: awscommon.TemplateFuncs}
b.config.ctx.Funcs = awscommon.TemplateFuncs
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: b.config.ctx,
InterpolateContext: &b.config.ctx,
}, raws...)
if err != nil {
return nil, err
......@@ -49,10 +49,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Accumulate any errors
var errs *packer.MultiError
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.BlockDevices.Prepare(b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.BlockDevices.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
......
......@@ -41,7 +41,7 @@ type Config struct {
X509KeyPath string `mapstructure:"x509_key_path"`
X509UploadPath string `mapstructure:"x509_upload_path"`
ctx *interpolate.Context
ctx interpolate.Context
}
type Builder struct {
......@@ -50,10 +50,10 @@ type Builder struct {
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.ctx = &interpolate.Context{Funcs: awscommon.TemplateFuncs}
b.config.ctx.Funcs = awscommon.TemplateFuncs
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: b.config.ctx,
InterpolateContext: &b.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"bundle_upload_command",
......@@ -114,10 +114,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Accumulate any errors
var errs *packer.MultiError
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.BlockDevices.Prepare(b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.BlockDevices.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
if b.config.AccountId == "" {
errs = packer.MultiErrorAppend(errs, errors.New("account_id is required"))
......
......@@ -42,7 +42,7 @@ func (s *StepBundleVolume) Run(state multistep.StateBag) multistep.StepAction {
Prefix: config.BundlePrefix,
PrivatePath: config.X509UploadPath,
}
config.BundleVolCommand, err = interpolate.Render(config.BundleVolCommand, config.ctx)
config.BundleVolCommand, err = interpolate.Render(config.BundleVolCommand, &config.ctx)
if err != nil {
err := fmt.Errorf("Error processing bundle volume command: %s", err)
state.Put("error", err)
......
......@@ -44,7 +44,7 @@ func (s *StepUploadBundle) Run(state multistep.StateBag) multistep.StepAction {
Region: region,
SecretKey: config.SecretKey,
}
config.BundleUploadCommand, err = interpolate.Render(config.BundleUploadCommand, config.ctx)
config.BundleUploadCommand, err = interpolate.Render(config.BundleUploadCommand, &config.ctx)
if err != nil {
err := fmt.Errorf("Error processing bundle upload command: %s", err)
state.Put("error", err)
......
......@@ -31,7 +31,7 @@ type Config struct {
DropletName string `mapstructure:"droplet_name"`
UserData string `mapstructure:"user_data"`
ctx *interpolate.Context
ctx interpolate.Context
}
func NewConfig(raws ...interface{}) (*Config, []string, error) {
......@@ -39,8 +39,9 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
var md mapstructure.Metadata
err := config.Decode(c, &config.DecodeOpts{
Metadata: &md,
Interpolate: true,
Metadata: &md,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"run_command",
......@@ -85,7 +86,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
}
var errs *packer.MultiError
if es := c.Comm.Prepare(c.ctx); len(es) > 0 {
if es := c.Comm.Prepare(&c.ctx); len(es) > 0 {
errs = packer.MultiErrorAppend(errs, es...)
}
if c.APIToken == "" {
......
......@@ -37,8 +37,9 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
var md mapstructure.Metadata
err := config.Decode(c, &config.DecodeOpts{
Metadata: &md,
Interpolate: true,
Metadata: &md,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"run_command",
......
......@@ -41,13 +41,14 @@ type Config struct {
account accountFile
privateKeyBytes []byte
stateTimeout time.Duration
ctx *interpolate.Context
ctx interpolate.Context
}
func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config)
err := config.Decode(c, &config.DecodeOpts{
Interpolate: true,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"run_command",
......
......@@ -35,7 +35,8 @@ type Builder struct {
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
Interpolate: true,
InterpolateContext: &b.config.ctx,
}, raws...)
if err != nil {
return nil, err
......
......@@ -57,7 +57,8 @@ type Config struct {
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
Interpolate: true,
InterpolateContext: &b.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"boot_command",
......
......@@ -34,7 +34,8 @@ type Config struct {
func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config)
err := config.Decode(c, &config.DecodeOpts{
Interpolate: true,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"boot_command",
......
......@@ -127,7 +127,8 @@ type Config struct {
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
Interpolate: true,
InterpolateContext: &b.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"boot_command",
......
......@@ -42,7 +42,8 @@ type Config struct {
func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config)
err := config.Decode(c, &config.DecodeOpts{
Interpolate: true,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"boot_command",
......
......@@ -68,7 +68,8 @@ type Config struct {
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
Interpolate: true,
InterpolateContext: &b.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"boot_command",
......
......@@ -35,7 +35,8 @@ type Config struct {
func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config)
err := config.Decode(c, &config.DecodeOpts{
Interpolate: true,
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"boot_command",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment