@ -17,6 +17,7 @@ import (
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
"github.com/mitchellh/mapstructure"
compute "google.golang.org/api/compute/v1"
)
@ -76,6 +77,8 @@ type Config struct {
EnableIntegrityMonitoring bool ` mapstructure:"enable_integrity_monitoring" required:"false" `
// Whether to use an IAP proxy.
IAPConfig ` mapstructure:",squash" `
// Create the image. Useful for setting to `false` during a build test stage. Defaults to `true`.
CreateImage bool ` mapstructure:"create_image" required:"false" `
// The unique name of the resulting image. Defaults to
// `packer-{{timestamp}}`.
ImageName string ` mapstructure:"image_name" required:"false" `
@ -288,7 +291,9 @@ type Config struct {
func ( c * Config ) Prepare ( raws ... interface { } ) ( [ ] string , error ) {
c . ctx . Funcs = TemplateFuncs
var md mapstructure . Metadata
err := config . Decode ( c , & config . DecodeOpts {
Metadata : & md ,
Interpolate : true ,
InterpolateContext : & c . ctx ,
InterpolateFilter : & interpolate . RenderFilter {
@ -329,6 +334,18 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
}
}
hasCreateImage := false
for _ , k := range md . Keys {
if k == "create_image" {
hasCreateImage = true
break
}
}
if ! hasCreateImage {
c . CreateImage = true
}
if c . ImageDescription == "" {
c . ImageDescription = "Created by Packer"
}