2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
|
|
|
|
2016-04-14 20:29:27 -04:00
|
|
|
package triton
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-03-13 13:04:48 -04:00
|
|
|
"github.com/hashicorp/packer/hcl2template"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2016-04-14 20:29:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// TargetImageConfig represents the configuration for the image to be created
|
|
|
|
// from the source machine.
|
|
|
|
type TargetImageConfig struct {
|
2019-05-28 11:50:58 -04:00
|
|
|
// The name the finished image in Triton will be
|
2019-06-06 10:29:25 -04:00
|
|
|
// assigned. Maximum 512 characters but should in practice be much shorter
|
|
|
|
// (think between 5 and 20 characters). For example postgresql-95-server for
|
|
|
|
// an image used as a PostgreSQL 9.5 server.
|
|
|
|
ImageName string `mapstructure:"image_name" required:"true"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The version string for this image. Maximum 128
|
2019-06-06 10:29:25 -04:00
|
|
|
// characters. Any string will do but a format of Major.Minor.Patch is
|
|
|
|
// strongly advised by Joyent. See Semantic Versioning
|
|
|
|
// for more information on the Major.Minor.Patch versioning format.
|
|
|
|
ImageVersion string `mapstructure:"image_version" required:"true"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// Description of the image. Maximum 512
|
2019-06-06 10:29:25 -04:00
|
|
|
// characters.
|
|
|
|
ImageDescription string `mapstructure:"image_description" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// URL of the homepage where users can find
|
2019-06-06 10:29:25 -04:00
|
|
|
// information about the image. Maximum 128 characters.
|
|
|
|
ImageHomepage string `mapstructure:"image_homepage" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// URL of the End User License Agreement (EULA)
|
2019-06-06 10:29:25 -04:00
|
|
|
// for the image. Maximum 128 characters.
|
|
|
|
ImageEULA string `mapstructure:"image_eula_url" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The UUID's of the users which will have
|
2019-06-06 10:29:25 -04:00
|
|
|
// access to this image. When omitted only the owner (the Triton user whose
|
|
|
|
// credentials are used) will have access to the image.
|
|
|
|
ImageACL []string `mapstructure:"image_acls" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// Tag applied to the image.
|
2019-06-06 10:29:25 -04:00
|
|
|
ImageTags map[string]string `mapstructure:"image_tags" required:"false"`
|
2020-03-13 13:04:48 -04:00
|
|
|
// Same as [`image_tags`](#image_tags) but defined as a singular block
|
|
|
|
// containing a key and a value field. In HCL2 mode the
|
|
|
|
// [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks)
|
|
|
|
// will allow you to create those programatically.
|
|
|
|
ImageTag []hcl2template.KeyValues `mapstructure:"image_tag" required:"false"`
|
2016-04-14 20:29:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare performs basic validation on a TargetImageConfig struct.
|
|
|
|
func (c *TargetImageConfig) Prepare(ctx *interpolate.Context) []error {
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
if c.ImageName == "" {
|
|
|
|
errs = append(errs, fmt.Errorf("An image_name must be specified"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.ImageVersion == "" {
|
|
|
|
errs = append(errs, fmt.Errorf("An image_version must be specified"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(errs) > 0 {
|
|
|
|
return errs
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|