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-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/template/config"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/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"`
|
2020-04-16 09:37:22 -04:00
|
|
|
// Name/Value tags applied to the image.
|
2019-06-06 10:29:25 -04:00
|
|
|
ImageTags map[string]string `mapstructure:"image_tags" required:"false"`
|
2020-03-16 09:55:03 -04:00
|
|
|
// Same as [`image_tags`](#image_tags) but defined as a singular repeatable
|
2020-03-17 06:14:32 -04:00
|
|
|
// block containing a `name` and a `value` field. In HCL2 mode the
|
2021-01-14 17:38:28 -05:00
|
|
|
// [`dynamic_block`](/docs/templates/hcl_templates/expressions#dynamic-blocks)
|
2020-03-13 13:04:48 -04:00
|
|
|
// will allow you to create those programatically.
|
2020-11-18 18:46:42 -05:00
|
|
|
ImageTag config.NameValues `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
|
|
|
|
|
2020-03-16 10:46:08 -04:00
|
|
|
errs = append(errs, c.ImageTag.CopyOn(&c.ImageTags)...)
|
2020-03-16 09:53:06 -04:00
|
|
|
|
2016-04-14 20:29:27 -04:00
|
|
|
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
|
|
|
|
}
|