Merge pull request #9594 from GennadySpb/yndx-image-min-disk-size
yandex: Add new property 'min_disk_size' of built image
This commit is contained in:
commit
0883e185a2
|
@ -47,6 +47,7 @@
|
|||
default for the http server IP [GH-9441]
|
||||
* builder/yandex: Support authentication by Service Account on instance
|
||||
[GH-9383]
|
||||
* builder/yandex: Allow set `min_disk_size` for an image.
|
||||
* communicator/ssh: Add support for OpenSSH certificate signing [GH-9521]
|
||||
* communicator/ssh: Allow users to provide a list of ciphers that they want
|
||||
Packer to support. [GH-9453]
|
||||
|
|
|
@ -62,6 +62,9 @@ type Config struct {
|
|||
// Key/value pair labels to
|
||||
// apply to the created image.
|
||||
ImageLabels map[string]string `mapstructure:"image_labels" required:"false"`
|
||||
// Minimum size of the disk that will be created from built image, specified in gigabytes.
|
||||
// Should be more or equal to `disk_size_gb`.
|
||||
ImageMinDiskSizeGb int `mapstructure:"image_min_disk_size_gb" required:"false"`
|
||||
// The unique name of the resulting image. Defaults to
|
||||
// `packer-{{timestamp}}`.
|
||||
ImageName string `mapstructure:"image_name" required:"false"`
|
||||
|
@ -164,6 +167,16 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
|||
c.DiskType = "network-hdd"
|
||||
}
|
||||
|
||||
if c.ImageMinDiskSizeGb == 0 {
|
||||
c.ImageMinDiskSizeGb = c.DiskSizeGb
|
||||
}
|
||||
|
||||
if c.ImageMinDiskSizeGb < c.DiskSizeGb {
|
||||
errs = packer.MultiErrorAppend(errs,
|
||||
fmt.Errorf("Invalid image_min_disk_size value (%d): Must be equal or greate than disk_size_gb (%d)",
|
||||
c.ImageMinDiskSizeGb, c.DiskSizeGb))
|
||||
}
|
||||
|
||||
if c.ImageDescription == "" {
|
||||
c.ImageDescription = "Created by Packer"
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ type FlatConfig struct {
|
|||
ImageDescription *string `mapstructure:"image_description" required:"false" cty:"image_description" hcl:"image_description"`
|
||||
ImageFamily *string `mapstructure:"image_family" required:"false" cty:"image_family" hcl:"image_family"`
|
||||
ImageLabels map[string]string `mapstructure:"image_labels" required:"false" cty:"image_labels" hcl:"image_labels"`
|
||||
ImageMinDiskSizeGb *int `mapstructure:"image_min_disk_size_gb" required:"false" cty:"image_min_disk_size_gb" hcl:"image_min_disk_size_gb"`
|
||||
ImageName *string `mapstructure:"image_name" required:"false" cty:"image_name" hcl:"image_name"`
|
||||
ImageProductIDs []string `mapstructure:"image_product_ids" required:"false" cty:"image_product_ids" hcl:"image_product_ids"`
|
||||
InstanceCores *int `mapstructure:"instance_cores" required:"false" cty:"instance_cores" hcl:"instance_cores"`
|
||||
|
@ -175,6 +176,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"image_description": &hcldec.AttrSpec{Name: "image_description", Type: cty.String, Required: false},
|
||||
"image_family": &hcldec.AttrSpec{Name: "image_family", Type: cty.String, Required: false},
|
||||
"image_labels": &hcldec.AttrSpec{Name: "image_labels", Type: cty.Map(cty.String), Required: false},
|
||||
"image_min_disk_size_gb": &hcldec.AttrSpec{Name: "image_min_disk_size_gb", Type: cty.Number, Required: false},
|
||||
"image_name": &hcldec.AttrSpec{Name: "image_name", Type: cty.String, Required: false},
|
||||
"image_product_ids": &hcldec.AttrSpec{Name: "image_product_ids", Type: cty.List(cty.String), Required: false},
|
||||
"instance_cores": &hcldec.AttrSpec{Name: "instance_cores", Type: cty.Number, Required: false},
|
||||
|
|
|
@ -166,6 +166,62 @@ func TestConfigPrepareStartupScriptFile(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestConfigImageMinDiskSize(t *testing.T) {
|
||||
cases := []struct {
|
||||
Name string
|
||||
Config map[string]interface{}
|
||||
Err bool
|
||||
}{
|
||||
{
|
||||
Name: "image_min_disk_size lower than disk_size (default value)",
|
||||
Config: map[string]interface{}{
|
||||
"image_min_disk_size_gb": 2,
|
||||
},
|
||||
Err: true,
|
||||
},
|
||||
{
|
||||
Name: "image_min_disk_size greater than disk_size (default value)",
|
||||
Config: map[string]interface{}{
|
||||
"image_min_disk_size_gb": 20,
|
||||
},
|
||||
Err: false,
|
||||
},
|
||||
{
|
||||
Name: "image_min_disk_size lower than disk_size (custom value)",
|
||||
Config: map[string]interface{}{
|
||||
"disk_size_gb": 50,
|
||||
"image_min_disk_size_gb": 20,
|
||||
},
|
||||
Err: true,
|
||||
},
|
||||
{
|
||||
Name: "image_min_disk_size greate than disk_size (custom value)",
|
||||
Config: map[string]interface{}{
|
||||
"disk_size_gb": 50,
|
||||
"image_min_disk_size_gb": 55,
|
||||
},
|
||||
Err: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
raw := testConfig(t)
|
||||
|
||||
for k, v := range tc.Config {
|
||||
raw[k] = v
|
||||
}
|
||||
|
||||
var c Config
|
||||
warns, errs := c.Prepare(raw)
|
||||
|
||||
if tc.Err {
|
||||
testConfigErr(t, warns, errs, tc.Name)
|
||||
} else {
|
||||
testConfigOk(t, warns, errs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigDefaults(t *testing.T) {
|
||||
cases := []struct {
|
||||
Read func(c *Config) interface{}
|
||||
|
|
|
@ -34,6 +34,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
|
|||
Family: c.ImageFamily,
|
||||
Description: c.ImageDescription,
|
||||
Labels: c.ImageLabels,
|
||||
MinDiskSize: toBytes(c.ImageMinDiskSizeGb),
|
||||
ProductIds: c.ImageProductIDs,
|
||||
Source: &compute.CreateImageRequest_DiskId{
|
||||
DiskId: diskID,
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
- `image_labels` (map[string]string) - Key/value pair labels to
|
||||
apply to the created image.
|
||||
|
||||
- `image_min_disk_size_gb` (int) - Minimum size of the disk that will be created from built image, specified in gigabytes.
|
||||
Should be more or equal to `disk_size_gb`.
|
||||
|
||||
- `image_name` (string) - The unique name of the resulting image. Defaults to
|
||||
`packer-{{timestamp}}`.
|
||||
|
||||
|
|
Loading…
Reference in New Issue