func (p *PostProcessor) Configure(raws ...interface{}) error { err := config.Decode(&p.config, &config.DecodeOpts{ Interpolate: true, InterpolateContext: &p.config.ctx, InterpolateFilter: &interpolate.RenderFilter{ Exclude: []string{"output"}, }, }, raws...) if err != nil { return err } errs := new(packer.MultiError) // required configuration templates := map[string]*string{ "region": &p.config.Region, "bucket": &p.config.Bucket, "manifest": &p.config.ManifestPath, "box_name": &p.config.BoxName, "box_dir": &p.config.BoxDir, "version": &p.config.Version, } for key, ptr := range templates { if *ptr == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("vagrant-s3 %s must be set", key)) } } // Template process for key, ptr := range templates { if err = interpolate.Validate(*ptr, &p.config.ctx); err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error parsing %s template: %s", key, err)) } } auth, err := aws.GetAuth(p.config.AccessKey, p.config.SecretKey) if err != nil { errs = packer.MultiErrorAppend(errs, fmt.Errorf("Unable to create Aws Authentication. Try providing keys 'access_key_id' and 'secret_key'")) } // determine region region, valid := aws.Regions[p.config.Region] if valid { p.s3 = s3.New(auth, region).Bucket(p.config.Bucket) } else { errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid region specified: %s", p.config.Region)) } if p.config.ACL == "" { p.config.ACL = "public-read" } if len(errs.Errors) > 0 { return errs } return nil }
func (p *PostProcessor) Configure(raws ...interface{}) error { err := config.Decode(&p.config, &config.DecodeOpts{ Interpolate: true, InterpolateContext: &p.config.ctx, InterpolateFilter: &interpolate.RenderFilter{ Exclude: []string{}, }, }, raws...) errs := new(packer.MultiError) // If there is no explicit number of Go threads to use, then set it if os.Getenv("GOMAXPROCS") == "" { runtime.GOMAXPROCS(runtime.NumCPU()) } if p.config.OutputPath == "" { p.config.OutputPath = "packer_{{.BuildName}}_{{.Provider}}" } if err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error parsing target template: %s", err)) } templates := map[string]*string{ "output": &p.config.OutputPath, } if p.config.CompressionLevel > pgzip.BestCompression { p.config.CompressionLevel = pgzip.BestCompression } // Technically 0 means "don't compress" but I don't know how to // differentiate between "user entered zero" and "user entered nothing". // Also, why bother creating a compressed file with zero compression? if p.config.CompressionLevel == -1 || p.config.CompressionLevel == 0 { p.config.CompressionLevel = pgzip.DefaultCompression } for key, ptr := range templates { if *ptr == "" { errs = packer.MultiErrorAppend( errs, fmt.Errorf("%s must be set", key)) } *ptr, err = interpolate.Render(p.config.OutputPath, &p.config.ctx) if err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error processing %s: %s", key, err)) } } p.config.detectFromFilename() if len(errs.Errors) > 0 { return errs } return nil }
func (p *PostProcessor) Configure(raws ...interface{}) error { err := config.Decode(&p.config, &config.DecodeOpts{ Interpolate: true, InterpolateFilter: &interpolate.RenderFilter{ Exclude: []string{}, }, }, raws...) if err != nil { return err } if p.config.ChecksumTypes == nil { p.config.ChecksumTypes = []string{"md5"} } if p.config.OutputPath == "" { p.config.OutputPath = "packer_{{.BuildName}}_{{.BuilderType}}" + ".checksum" } errs := new(packer.MultiError) if err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error parsing target template: %s", err)) } if len(errs.Errors) > 0 { return errs } return nil }
func (p *OVFPostProcessor) Configure(raws ...interface{}) error { err := config.Decode(&p.cfg, &config.DecodeOpts{ Interpolate: true, InterpolateContext: &p.cfg.ctx, InterpolateFilter: &interpolate.RenderFilter{ Exclude: []string{}, }, }, raws...) if err != nil { return err } if p.cfg.TargetType == "" { p.cfg.TargetType = "ovf" } if p.cfg.TargetPath == "" { p.cfg.TargetPath = "packer_{{ .BuildName }}_{{.Provider}}" if p.cfg.TargetType == "ova" { p.cfg.TargetPath += ".ova" } } errs := new(packer.MultiError) _, err = exec.LookPath(executable) if err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error: Could not find ovftool executable: %s", err)) } if err = interpolate.Validate(p.cfg.TargetPath, &p.cfg.ctx); err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error parsing target template: %s", err)) } if !(p.cfg.TargetType == "ovf" || p.cfg.TargetType == "ova") { errs = packer.MultiErrorAppend( errs, errors.New("Invalid target type. Only 'ovf' or 'ova' are allowed.")) } if !(p.cfg.Compression >= 0 && p.cfg.Compression <= 9) { errs = packer.MultiErrorAppend( errs, errors.New("Invalid compression level. Must be between 1 and 9, or 0 for no compression.")) } if len(errs.Errors) > 0 { return errs } return nil }
// Entry point for configuration parisng when we've defined func (p *PostProcessor) Configure(raws ...interface{}) error { p.config.ctx.Funcs = awscommon.TemplateFuncs err := config.Decode(&p.config, &config.DecodeOpts{ Interpolate: true, InterpolateContext: &p.config.ctx, InterpolateFilter: &interpolate.RenderFilter{ Exclude: []string{ "s3_key_name", }, }, }, raws...) if err != nil { return err } // Set defaults if p.config.S3Key == "" { p.config.S3Key = "packer-import-{{timestamp}}.ova" } errs := new(packer.MultiError) // Check and render s3_key_name if err = interpolate.Validate(p.config.S3Key, &p.config.ctx); err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error parsing s3_key_name template: %s", err)) } // Check we have AWS access variables defined somewhere errs = packer.MultiErrorAppend(errs, p.config.AccessConfig.Prepare(&p.config.ctx)...) // define all our required paramaters templates := map[string]*string{ "s3_bucket_name": &p.config.S3Bucket, } // Check out required params are defined for key, ptr := range templates { if *ptr == "" { errs = packer.MultiErrorAppend( errs, fmt.Errorf("%s must be set", key)) } } // Anything which flagged return back up the stack if len(errs.Errors) > 0 { return errs } log.Println(common.ScrubConfig(p.config, p.config.AccessKey, p.config.SecretKey)) return nil }
func (b *Builder) validateVMXTemplatePath() error { f, err := os.Open(b.config.VMXTemplatePath) if err != nil { return err } defer f.Close() data, err := ioutil.ReadAll(f) if err != nil { return err } return interpolate.Validate(string(data), &b.config.ctx) }
func (p *PostProcessor) Configure(raws ...interface{}) error { err := config.Decode(&p.config, &config.DecodeOpts{ Interpolate: true, InterpolateContext: &p.config.ctx, InterpolateFilter: &interpolate.RenderFilter{ Exclude: []string{}, }, }, raws...) if err != nil { return err } errs := new(packer.MultiError) // required configuration templates := map[string]*string{ "name": &p.config.Name, "output": &p.config.MetadataPath, "url_prefix": &p.config.UrlPrefix, "box_dir": &p.config.BoxDir, "version": &p.config.Version, } for key, ptr := range templates { if *ptr == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("%s must be set", key)) } } for key, ptr := range templates { if err = interpolate.Validate(*ptr, &p.config.ctx); err != nil { errs = packer.MultiErrorAppend(errs, fmt.Errorf("Error parsing %s template: %s", key, err)) } } if len(errs.Errors) > 0 { return errs } return nil }
func (p *PostProcessor) Configure(raws ...interface{}) error { err := config.Decode(&p.config, &config.DecodeOpts{ Interpolate: true, InterpolateContext: &p.config.ctx, InterpolateFilter: &interpolate.RenderFilter{ Exclude: []string{}, }, }, raws...) if err != nil { return err } if p.config.OutputPath == "" { p.config.OutputPath = "packer-manifest.json" } if err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil { return fmt.Errorf("Error parsing target template: %s", err) } return nil }
func (p *PostProcessor) Configure(raws ...interface{}) error { err := config.Decode(&p.config, &config.DecodeOpts{ Interpolate: true, InterpolateContext: &p.config.ctx, InterpolateFilter: &interpolate.RenderFilter{ Exclude: []string{"output"}, }, }, raws...) if err != nil { return err } errs := new(packer.MultiError) if p.config.GuestfishBinary == "" { p.config.GuestfishBinary = "guestfish" } if p.config.OutputPath == "" { p.config.OutputPath = "packer_{{.BuildName}}_tarball" } if _, err := exec.LookPath(p.config.GuestfishBinary); err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error finding executable %s: %s", p.config.GuestfishBinary, err)) } if err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error parsing target template: %s", err)) } if len(errs.Errors) > 0 { return errs } return nil }
func (p *PostProcessor) Configure(raws ...interface{}) error { err := config.Decode(&p.config, &config.DecodeOpts{ Interpolate: true, InterpolateContext: &p.config.ctx, InterpolateFilter: &interpolate.RenderFilter{ Exclude: []string{}, }, }, raws...) errs := new(packer.MultiError) if err != nil { return err } //p.config.tpl.UserVars = p.config.ctx.UserVariables if err = interpolate.Validate(p.config.TargetPath, &p.config.ctx); err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error parsing target template: %s", err)) } if p.config.OVFtoolPath == "" { p.config.OVFtoolPath = "ovftool" } if p.config.TargetType == "" { p.config.TargetType = "ova" } if p.config.TargetPath == "" { p.config.TargetPath = "packer_build_provider" if p.config.TargetType == "ova" { p.config.TargetPath += ".ova" } } if p.config.ViPort == 0 { p.config.ViPort = 443 } if p.config.SshPort == 0 { p.config.SshPort = 22 } if p.config.Username == "" { p.config.Username = "******" } if !(p.config.TargetType == "ovf" || p.config.TargetType == "ova") { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Invalid target type. Only 'ovf' or 'ova' are allowed.")) } if !(p.config.CompressionLevel >= 0 && p.config.CompressionLevel <= 9) { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Invalid compression level. Must be between 1 and 9, or 0 for no compression.")) } if len(errs.Errors) > 0 { return errs } if p.config.Host == "" { return fmt.Errorf("ovftool post processor: host parameter is required") } if p.config.Password == "" { return fmt.Errorf("ovftool post processor: password parameter is required") } if p.config.VMName == "" { return fmt.Errorf("ovftool post processor: vm_name parameter is required") } return nil }
func (p *PostProcessor) Configure(raws ...interface{}) error { err := config.Decode(&p.config, &config.DecodeOpts{ Interpolate: true, InterpolateContext: &p.config.ctx, InterpolateFilter: &interpolate.RenderFilter{ Exclude: []string{"output"}, }, }, raws...) if err != nil { return err } errs := new(packer.MultiError) // required configuration templates := map[string]*string{ "region": &p.config.Region, "bucket": &p.config.Bucket, "manifest": &p.config.ManifestPath, "box_name": &p.config.BoxName, "box_dir": &p.config.BoxDir, } for key, ptr := range templates { if *ptr == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("vagrant-s3 %s must be set", key)) } } // Template process for key, ptr := range templates { if err = interpolate.Validate(*ptr, &p.config.ctx); err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("Error parsing %s template: %s", key, err)) } } // create a session and an S3 service accessKey := p.config.AccessKey secretKey := p.config.SecretKey p.session = session.New(&aws.Config{ Region: aws.String(p.config.Region), Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""), }) p.s3 = s3.New(p.session) // check that we have permission to access the bucket _, err = p.s3.HeadBucket(&s3.HeadBucketInput{ Bucket: aws.String(p.config.Bucket), }) if err != nil { errs = packer.MultiErrorAppend(errs, fmt.Errorf("Unable to access the bucket %s, make sure your credentials are valid and have sufficient permissions", p.config.Bucket)) } if p.config.ACL == "" { p.config.ACL = "public-read" } if len(errs.Errors) > 0 { return errs } return nil }