From bd1a0d07fb6b4fdb1907b21cb81a8e7157108995 Mon Sep 17 00:00:00 2001 From: Nina Berg Date: Tue, 8 Jul 2014 13:15:17 -0400 Subject: [PATCH] Added some variables to amazon-ebs builder and chef-client provisioner --- builder/amazon/common/run_config.go | 49 ++++++++++++++------------ provisioner/chef-client/provisioner.go | 42 ++++++++++++---------- 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index c50c22f7e..d7dd6ec99 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -42,6 +42,32 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error { } } + templates := map[string]*string{ + "iam_instance_profile": &c.IamInstanceProfile, + "instance_type": &c.InstanceType, + "ssh_timeout": &c.RawSSHTimeout, + "ssh_username": &c.SSHUsername, + "ssh_private_key_file": &c.SSHPrivateKeyFile, + "source_ami": &c.SourceAmi, + "subnet_id": &c.SubnetId, + "temporary_key_pair_name": &c.TemporaryKeyPairName, + "vpc_id": &c.VpcId, + "availability_zone": &c.AvailabilityZone, + "user_data": &c.UserData, + "user_data_file": &c.UserDataFile, + "security_group_id": &c.SecurityGroupId, + } + + errs := make([]error, 0) + for n, ptr := range templates { + var err error + *ptr, err = t.Process(*ptr, nil) + if err != nil { + errs = append( + errs, fmt.Errorf("Error processing %s: %s", n, err)) + } + } + // Defaults if c.SSHPort == 0 { c.SSHPort = 22 @@ -57,7 +83,6 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error { // Validation var err error - errs := make([]error, 0) if c.SourceAmi == "" { errs = append(errs, errors.New("A source_ami must be specified")) } @@ -87,28 +112,6 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error { } } - templates := map[string]*string{ - "iam_instance_profile": &c.IamInstanceProfile, - "instance_type": &c.InstanceType, - "ssh_timeout": &c.RawSSHTimeout, - "ssh_username": &c.SSHUsername, - "ssh_private_key_file": &c.SSHPrivateKeyFile, - "source_ami": &c.SourceAmi, - "subnet_id": &c.SubnetId, - "temporary_key_pair_name": &c.TemporaryKeyPairName, - "vpc_id": &c.VpcId, - "availability_zone": &c.AvailabilityZone, - } - - for n, ptr := range templates { - var err error - *ptr, err = t.Process(*ptr, nil) - if err != nil { - errs = append( - errs, fmt.Errorf("Error processing %s: %s", n, err)) - } - } - sliceTemplates := map[string][]string{ "security_group_ids": c.SecurityGroupIds, } diff --git a/provisioner/chef-client/provisioner.go b/provisioner/chef-client/provisioner.go index 1e2847f54..83ea57efc 100644 --- a/provisioner/chef-client/provisioner.go +++ b/provisioner/chef-client/provisioner.go @@ -71,6 +71,29 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { } p.config.tpl.UserVars = p.config.PackerUserVars + // Accumulate any errors + errs := common.CheckUnusedConfig(md) + + templates := map[string]*string{ + "config_template": &p.config.ConfigTemplate, + "node_name": &p.config.NodeName, + "staging_dir": &p.config.StagingDir, + "chef_server_url": &p.config.ServerUrl, + "execute_command": &p.config.ExecuteCommand, + "install_command": &p.config.InstallCommand, + "validation_key_path": &p.config.ValidationKeyPath, + "validation_client_name": &p.config.ValidationClientName, + } + + for n, ptr := range templates { + var err error + *ptr, err = p.config.tpl.Process(*ptr, nil) + if err != nil { + errs = packer.MultiErrorAppend( + errs, fmt.Errorf("Error processing %s: %s", n, err)) + } + } + if p.config.ExecuteCommand == "" { p.config.ExecuteCommand = "{{if .Sudo}}sudo {{end}}chef-client " + "--no-color -c {{.ConfigPath}} -j {{.JsonPath}}" @@ -90,25 +113,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { p.config.StagingDir = "/tmp/packer-chef-client" } - // Accumulate any errors - errs := common.CheckUnusedConfig(md) - - templates := map[string]*string{ - "config_template": &p.config.ConfigTemplate, - "node_name": &p.config.NodeName, - "staging_dir": &p.config.StagingDir, - "chef_server_url": &p.config.ServerUrl, - } - - for n, ptr := range templates { - var err error - *ptr, err = p.config.tpl.Process(*ptr, nil) - if err != nil { - errs = packer.MultiErrorAppend( - errs, fmt.Errorf("Error processing %s: %s", n, err)) - } - } - sliceTemplates := map[string][]string{ "run_list": p.config.RunList, }