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

builder/*: properly save interpolation context

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