Rename config key name

This commit is contained in:
Gennady Lipenkov 2020-07-16 17:29:45 +03:00
parent 9c565a97c0
commit 03a0bf26f2
5 changed files with 15 additions and 15 deletions

View File

@ -64,7 +64,7 @@ type Config struct {
ImageLabels map[string]string `mapstructure:"image_labels" required:"false"` ImageLabels map[string]string `mapstructure:"image_labels" required:"false"`
// Minimum size of the disk that will be created from built image, specified in gigabytes. // Minimum size of the disk that will be created from built image, specified in gigabytes.
// Should be more or equal to `disk_size_gb`. // Should be more or equal to `disk_size_gb`.
ImageMinDiskSize int `mapstructure:"image_min_disk_size" required:"false"` ImageMinDiskSizeGb int `mapstructure:"image_min_disk_size_gb" required:"false"`
// The unique name of the resulting image. Defaults to // The unique name of the resulting image. Defaults to
// `packer-{{timestamp}}`. // `packer-{{timestamp}}`.
ImageName string `mapstructure:"image_name" required:"false"` ImageName string `mapstructure:"image_name" required:"false"`
@ -167,14 +167,14 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
c.DiskType = "network-hdd" c.DiskType = "network-hdd"
} }
if c.ImageMinDiskSize == 0 { if c.ImageMinDiskSizeGb == 0 {
c.ImageMinDiskSize = c.DiskSizeGb c.ImageMinDiskSizeGb = c.DiskSizeGb
} }
if c.ImageMinDiskSize <= c.DiskSizeGb { if c.ImageMinDiskSizeGb < c.DiskSizeGb {
errs = packer.MultiErrorAppend(errs, errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Invalid image_min_disk_size value (%d): Must be equal or greate than disk_size_gb (%d)", fmt.Errorf("Invalid image_min_disk_size value (%d): Must be equal or greate than disk_size_gb (%d)",
c.ImageMinDiskSize, c.DiskSizeGb)) c.ImageMinDiskSizeGb, c.DiskSizeGb))
} }
if c.ImageDescription == "" { if c.ImageDescription == "" {

View File

@ -73,7 +73,7 @@ type FlatConfig struct {
ImageDescription *string `mapstructure:"image_description" required:"false" cty:"image_description" hcl:"image_description"` 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"` 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"` ImageLabels map[string]string `mapstructure:"image_labels" required:"false" cty:"image_labels" hcl:"image_labels"`
ImageMinDiskSize *int `mapstructure:"image_min_disk_size" required:"false" cty:"image_min_disk_size" hcl:"image_min_disk_size"` 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"` 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"` 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"` InstanceCores *int `mapstructure:"instance_cores" required:"false" cty:"instance_cores" hcl:"instance_cores"`
@ -176,7 +176,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"image_description": &hcldec.AttrSpec{Name: "image_description", Type: cty.String, Required: false}, "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_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_labels": &hcldec.AttrSpec{Name: "image_labels", Type: cty.Map(cty.String), Required: false},
"image_min_disk_size": &hcldec.AttrSpec{Name: "image_min_disk_size", Type: cty.Number, 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_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}, "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}, "instance_cores": &hcldec.AttrSpec{Name: "instance_cores", Type: cty.Number, Required: false},

View File

@ -175,30 +175,30 @@ func TestConfigImageMinDiskSize(t *testing.T) {
{ {
Name: "image_min_disk_size lower than disk_size (default value)", Name: "image_min_disk_size lower than disk_size (default value)",
Config: map[string]interface{}{ Config: map[string]interface{}{
"image_min_disk_size": 2, "image_min_disk_size_gb": 2,
}, },
Err: true, Err: true,
}, },
{ {
Name: "image_min_disk_size greater than disk_size (default value)", Name: "image_min_disk_size greater than disk_size (default value)",
Config: map[string]interface{}{ Config: map[string]interface{}{
"image_min_disk_size": 20, "image_min_disk_size_gb": 20,
}, },
Err: false, Err: false,
}, },
{ {
Name: "image_min_disk_size lower than disk_size (custom value)", Name: "image_min_disk_size lower than disk_size (custom value)",
Config: map[string]interface{}{ Config: map[string]interface{}{
"disk_size_gb": 50, "disk_size_gb": 50,
"image_min_disk_size": 20, "image_min_disk_size_gb": 20,
}, },
Err: true, Err: true,
}, },
{ {
Name: "image_min_disk_size greate than disk_size (custom value)", Name: "image_min_disk_size greate than disk_size (custom value)",
Config: map[string]interface{}{ Config: map[string]interface{}{
"disk_size_gb": 50, "disk_size_gb": 50,
"image_min_disk_size": 55, "image_min_disk_size_gb": 55,
}, },
Err: false, Err: false,
}, },

View File

@ -34,7 +34,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
Family: c.ImageFamily, Family: c.ImageFamily,
Description: c.ImageDescription, Description: c.ImageDescription,
Labels: c.ImageLabels, Labels: c.ImageLabels,
MinDiskSize: toBytes(c.ImageMinDiskSize), MinDiskSize: toBytes(c.ImageMinDiskSizeGb),
ProductIds: c.ImageProductIDs, ProductIds: c.ImageProductIDs,
Source: &compute.CreateImageRequest_DiskId{ Source: &compute.CreateImageRequest_DiskId{
DiskId: diskID, DiskId: diskID,

View File

@ -22,7 +22,7 @@
- `image_labels` (map[string]string) - Key/value pair labels to - `image_labels` (map[string]string) - Key/value pair labels to
apply to the created image. apply to the created image.
- `image_min_disk_size` (int) - Minimum size of the disk that will be created from built image, specified in gigabytes. - `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`. Should be more or equal to `disk_size_gb`.
- `image_name` (string) - The unique name of the resulting image. Defaults to - `image_name` (string) - The unique name of the resulting image. Defaults to