amazon-import post-processor: support license_type

Implements a new config option for the amazon-import post-processor
allowing users to specify a LicenseType during the import process.

Closes: #4631
This commit is contained in:
Brian Warsing 2017-03-07 06:42:51 -08:00
parent ce40c3d708
commit c5dfe3d503
1 changed files with 8 additions and 2 deletions

View File

@ -34,6 +34,7 @@ type Config struct {
Description string `mapstructure:"ami_description"`
Users []string `mapstructure:"ami_users"`
Groups []string `mapstructure:"ami_groups"`
LicenseType string `mapstructure:"license_type"`
ctx interpolate.Context
}
@ -63,6 +64,10 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
p.config.S3Key = "packer-import-{{timestamp}}.ova"
}
if p.config.LicenseType == "" {
p.config.LicenseType = "BYOL"
}
errs := new(packer.MultiError)
// Check and render s3_key_name
@ -158,7 +163,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
ui.Message(fmt.Sprintf("Completed upload of %s to s3://%s/%s", source, p.config.S3Bucket, p.config.S3Key))
// Call EC2 image import process
log.Printf("Calling EC2 to import from s3://%s/%s", p.config.S3Bucket, p.config.S3Key)
log.Printf("Calling EC2 to import from s3://%s/%s with license type '%s'", p.config.S3Bucket, p.config.S3Key, p.config.LicenseType)
ec2conn := ec2.New(session)
import_start, err := ec2conn.ImportImage(&ec2.ImportImageInput{
@ -170,13 +175,14 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
},
},
},
LicenseType: &p.config.LicenseType,
})
if err != nil {
return nil, false, fmt.Errorf("Failed to start import from s3://%s/%s: %s", p.config.S3Bucket, p.config.S3Key, err)
}
ui.Message(fmt.Sprintf("Started import of s3://%s/%s, task id %s", p.config.S3Bucket, p.config.S3Key, *import_start.ImportTaskId))
ui.Message(fmt.Sprintf("Started import of s3://%s/%s with license type %s, task id %s", p.config.S3Bucket, p.config.S3Key, p.config.LicenseType, *import_start.ImportTaskId))
// Wait for import process to complete, this takes a while
ui.Message(fmt.Sprintf("Waiting for task %s to complete (may take a while)", *import_start.ImportTaskId))