From 464514383ab89babfeed5e719a63f3bec972220c Mon Sep 17 00:00:00 2001 From: Christophe Jauffret Date: Fri, 17 Mar 2023 19:00:13 +0100 Subject: [PATCH] support multiple categories --- builder/nutanix/config.go | 71 ++++++++++++------------ builder/nutanix/config.hcl2spec.go | 87 ++++++++++++++++++------------ builder/nutanix/driver.go | 16 +++--- builder/nutanix/step_copy_image.go | 2 +- docs/builders/nutanix.mdx | 26 +++++++-- example/source.nutanix.pkr.hcl | 11 ++++ test/e2e/centos-img/source.pkr.hcl | 14 +++-- test/e2e/centos-iso/source.pkr.hcl | 18 ++++--- 8 files changed, 156 insertions(+), 89 deletions(-) diff --git a/builder/nutanix/config.go b/builder/nutanix/config.go index 8fd7548..e08c070 100644 --- a/builder/nutanix/config.go +++ b/builder/nutanix/config.go @@ -1,4 +1,4 @@ -//go:generate packer-sdc mapstructure-to-hcl2 -type Config,ClusterConfig,VmConfig,VmDisk,VmNIC +//go:generate packer-sdc mapstructure-to-hcl2 -type Config,Category,ClusterConfig,VmConfig,VmDisk,VmNIC package nutanix @@ -36,14 +36,18 @@ type Config struct { VmConfig `mapstructure:",squash"` ForceDeregister bool `mapstructure:"force_deregister" json:"force_deregister" required:"false"` ImageDescription string `mapstructure:"image_description" json:"image_description" required:"false"` - ImageCategoryKey string `mapstructure:"image_category_key" json:"image_category_key" required:"false"` - ImageCategoryValue string `mapstructure:"image_category_value" json:"image_category_value" required:"false"` + ImageCategories []Category `mapstructure:"image_categories" required:"false"` ImageDelete bool `mapstructure:"image_delete" json:"image_delete" required:"false"` WaitTimeout time.Duration `mapstructure:"ip_wait_timeout" json:"ip_wait_timeout" required:"false"` ctx interpolate.Context } +type Category struct { + Key string `mapstructure:"key" json:"key" required:"false"` + Value string `mapstructure:"value" json:"value" required:"false"` +} + type ClusterConfig struct { Username string `mapstructure:"nutanix_username" required:"false"` Password string `mapstructure:"nutanix_password" required:"false"` @@ -65,19 +69,18 @@ type VmNIC struct { SubnetUUID string `mapstructure:"subnet_uuid" json:"subnet_uuid" required:"false"` } type VmConfig struct { - VMName string `mapstructure:"vm_name" json:"vm_name" required:"false"` - OSType string `mapstructure:"os_type" json:"os_type" required:"true"` - BootType string `mapstructure:"boot_type" json:"boot_type" required:"false"` - VmDisks []VmDisk `mapstructure:"vm_disks"` - VmNICs []VmNIC `mapstructure:"vm_nics"` - ImageName string `mapstructure:"image_name" json:"image_name" required:"false"` - ClusterUUID string `mapstructure:"cluster_uuid" json:"cluster_uuid" required:"false"` - ClusterName string `mapstructure:"cluster_name" json:"cluster_name" required:"false"` - CPU int64 `mapstructure:"cpu" json:"cpu" required:"false"` - MemoryMB int64 `mapstructure:"memory_mb" json:"memory_mb" required:"false"` - UserData string `mapstructure:"user_data" json:"user_data" required:"false"` - VmCategoryKey string `mapstructure:"vm_category_key" json:"vm_category_key" required:"false"` - VmCategoryValue string `mapstructure:"vm_category_value" json:"vm_category_value" required:"false"` + VMName string `mapstructure:"vm_name" json:"vm_name" required:"false"` + OSType string `mapstructure:"os_type" json:"os_type" required:"true"` + BootType string `mapstructure:"boot_type" json:"boot_type" required:"false"` + VmDisks []VmDisk `mapstructure:"vm_disks"` + VmNICs []VmNIC `mapstructure:"vm_nics"` + ImageName string `mapstructure:"image_name" json:"image_name" required:"false"` + ClusterUUID string `mapstructure:"cluster_uuid" json:"cluster_uuid" required:"false"` + ClusterName string `mapstructure:"cluster_name" json:"cluster_name" required:"false"` + CPU int64 `mapstructure:"cpu" json:"cpu" required:"false"` + MemoryMB int64 `mapstructure:"memory_mb" json:"memory_mb" required:"false"` + UserData string `mapstructure:"user_data" json:"user_data" required:"false"` + VMCategories []Category `mapstructure:"vm_categories" required:"false"` } func (c *Config) Prepare(raws ...interface{}) ([]string, error) { @@ -138,10 +141,6 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) { errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("missing nutanix_username")) } - // if c.VmConfig.SourceImageName == "" { - // errs = packersdk.MultiErrorAppend(errs, errors.New("Missing source_image_name")) - // } - if c.VmConfig.VMName == "" { p := fmt.Sprintf("Packer-%s", random.String(random.PossibleAlphaNumUpper, 8)) log.Println("No vmname assigned, setting to " + p) @@ -156,25 +155,29 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) { } // Validate if both Image Category key and value are given in same time - if c.ImageCategoryKey != "" && c.ImageCategoryValue == "" { - log.Println("Nutanix Image Category value missing from configuration") - errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("missing image_category_value")) - } + for _, imageCategory := range c.ImageCategories { + if imageCategory.Key != "" && imageCategory.Value == "" { + log.Println("Nutanix Image Category value missing from configuration") + errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("missing value for image category %s", imageCategory.Key)) + } - if c.ImageCategoryKey == "" && c.ImageCategoryValue != "" { - log.Println("Nutanix Image Category key missing from configuration") - errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("missing image_category_key")) + if imageCategory.Key == "" && imageCategory.Value != "" { + log.Println("Nutanix Image Category name missing from configuration") + errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("missing name for an image categories with value %s", imageCategory.Value)) + } } // Validate if both VM Category key and value are given in same time - if c.VmCategoryKey != "" && c.VmCategoryValue == "" { - log.Println("Nutanix VM Category value missing from configuration") - errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("missing vm_category_value")) - } + for _, vmCategory := range c.VMCategories { + if vmCategory.Key != "" && vmCategory.Value == "" { + log.Println("Nutanix VM Category value missing from configuration") + errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("missing value for vm category %s", vmCategory.Key)) + } - if c.VmCategoryKey == "" && c.VmCategoryValue != "" { - log.Println("Nutanix VM Category key missing from configuration") - errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("missing vm_category_key")) + if vmCategory.Key == "" && vmCategory.Value != "" { + log.Println("Nutanix VM Category name missing from configuration") + errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("missing name for a vm categories with value %s", vmCategory.Value)) + } } if c.CommConfig.SSHPort == 0 { diff --git a/builder/nutanix/config.hcl2spec.go b/builder/nutanix/config.hcl2spec.go index 34b7639..bfd5b9d 100644 --- a/builder/nutanix/config.hcl2spec.go +++ b/builder/nutanix/config.hcl2spec.go @@ -7,6 +7,31 @@ import ( "github.com/zclconf/go-cty/cty" ) +// FlatCategory is an auto-generated flat version of Category. +// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. +type FlatCategory struct { + Key *string `mapstructure:"key" json:"key" required:"false" cty:"key" hcl:"key"` + Value *string `mapstructure:"value" json:"value" required:"false" cty:"value" hcl:"value"` +} + +// FlatMapstructure returns a new FlatCategory. +// FlatCategory is an auto-generated flat version of Category. +// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up. +func (*Category) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } { + return new(FlatCategory) +} + +// HCL2Spec returns the hcl spec of a Category. +// This spec is used by HCL to read the fields of Category. +// The decoded values from this spec will then be applied to a FlatCategory. +func (*FlatCategory) HCL2Spec() map[string]hcldec.Spec { + s := map[string]hcldec.Spec{ + "key": &hcldec.AttrSpec{Name: "key", Type: cty.String, Required: false}, + "value": &hcldec.AttrSpec{Name: "value", Type: cty.String, Required: false}, + } + return s +} + // FlatClusterConfig is an auto-generated flat version of ClusterConfig. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatClusterConfig struct { @@ -119,12 +144,10 @@ type FlatConfig struct { CPU *int64 `mapstructure:"cpu" json:"cpu" required:"false" cty:"cpu" hcl:"cpu"` MemoryMB *int64 `mapstructure:"memory_mb" json:"memory_mb" required:"false" cty:"memory_mb" hcl:"memory_mb"` UserData *string `mapstructure:"user_data" json:"user_data" required:"false" cty:"user_data" hcl:"user_data"` - VmCategoryKey *string `mapstructure:"vm_category_key" json:"vm_category_key" required:"false" cty:"vm_category_key" hcl:"vm_category_key"` - VmCategoryValue *string `mapstructure:"vm_category_value" json:"vm_category_value" required:"false" cty:"vm_category_value" hcl:"vm_category_value"` + VMCategories []FlatCategory `mapstructure:"vm_categories" required:"false" cty:"vm_categories" hcl:"vm_categories"` ForceDeregister *bool `mapstructure:"force_deregister" json:"force_deregister" required:"false" cty:"force_deregister" hcl:"force_deregister"` ImageDescription *string `mapstructure:"image_description" json:"image_description" required:"false" cty:"image_description" hcl:"image_description"` - ImageCategoryKey *string `mapstructure:"image_category_key" json:"image_category_key" required:"false" cty:"image_category_key" hcl:"image_category_key"` - ImageCategoryValue *string `mapstructure:"image_category_value" json:"image_category_value" required:"false" cty:"image_category_value" hcl:"image_category_value"` + ImageCategories []FlatCategory `mapstructure:"image_categories" required:"false" cty:"image_categories" hcl:"image_categories"` ImageDelete *bool `mapstructure:"image_delete" json:"image_delete" required:"false" cty:"image_delete" hcl:"image_delete"` WaitTimeout *string `mapstructure:"ip_wait_timeout" json:"ip_wait_timeout" required:"false" cty:"ip_wait_timeout" hcl:"ip_wait_timeout"` } @@ -219,12 +242,10 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "cpu": &hcldec.AttrSpec{Name: "cpu", Type: cty.Number, Required: false}, "memory_mb": &hcldec.AttrSpec{Name: "memory_mb", Type: cty.Number, Required: false}, "user_data": &hcldec.AttrSpec{Name: "user_data", Type: cty.String, Required: false}, - "vm_category_key": &hcldec.AttrSpec{Name: "vm_category_key", Type: cty.String, Required: false}, - "vm_category_value": &hcldec.AttrSpec{Name: "vm_category_value", Type: cty.String, Required: false}, + "vm_categories": &hcldec.BlockListSpec{TypeName: "vm_categories", Nested: hcldec.ObjectSpec((*FlatCategory)(nil).HCL2Spec())}, "force_deregister": &hcldec.AttrSpec{Name: "force_deregister", Type: cty.Bool, Required: false}, "image_description": &hcldec.AttrSpec{Name: "image_description", Type: cty.String, Required: false}, - "image_category_key": &hcldec.AttrSpec{Name: "image_category_key", Type: cty.String, Required: false}, - "image_category_value": &hcldec.AttrSpec{Name: "image_category_value", Type: cty.String, Required: false}, + "image_categories": &hcldec.BlockListSpec{TypeName: "image_categories", Nested: hcldec.ObjectSpec((*FlatCategory)(nil).HCL2Spec())}, "image_delete": &hcldec.AttrSpec{Name: "image_delete", Type: cty.Bool, Required: false}, "ip_wait_timeout": &hcldec.AttrSpec{Name: "ip_wait_timeout", Type: cty.String, Required: false}, } @@ -234,19 +255,18 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { // FlatVmConfig is an auto-generated flat version of VmConfig. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatVmConfig struct { - VMName *string `mapstructure:"vm_name" json:"vm_name" required:"false" cty:"vm_name" hcl:"vm_name"` - OSType *string `mapstructure:"os_type" json:"os_type" required:"true" cty:"os_type" hcl:"os_type"` - BootType *string `mapstructure:"boot_type" json:"boot_type" required:"false" cty:"boot_type" hcl:"boot_type"` - VmDisks []FlatVmDisk `mapstructure:"vm_disks" cty:"vm_disks" hcl:"vm_disks"` - VmNICs []FlatVmNIC `mapstructure:"vm_nics" cty:"vm_nics" hcl:"vm_nics"` - ImageName *string `mapstructure:"image_name" json:"image_name" required:"false" cty:"image_name" hcl:"image_name"` - ClusterUUID *string `mapstructure:"cluster_uuid" json:"cluster_uuid" required:"false" cty:"cluster_uuid" hcl:"cluster_uuid"` - ClusterName *string `mapstructure:"cluster_name" json:"cluster_name" required:"false" cty:"cluster_name" hcl:"cluster_name"` - CPU *int64 `mapstructure:"cpu" json:"cpu" required:"false" cty:"cpu" hcl:"cpu"` - MemoryMB *int64 `mapstructure:"memory_mb" json:"memory_mb" required:"false" cty:"memory_mb" hcl:"memory_mb"` - UserData *string `mapstructure:"user_data" json:"user_data" required:"false" cty:"user_data" hcl:"user_data"` - VmCategoryKey *string `mapstructure:"vm_category_key" json:"vm_category_key" required:"false" cty:"vm_category_key" hcl:"vm_category_key"` - VmCategoryValue *string `mapstructure:"vm_category_value" json:"vm_category_value" required:"false" cty:"vm_category_value" hcl:"vm_category_value"` + VMName *string `mapstructure:"vm_name" json:"vm_name" required:"false" cty:"vm_name" hcl:"vm_name"` + OSType *string `mapstructure:"os_type" json:"os_type" required:"true" cty:"os_type" hcl:"os_type"` + BootType *string `mapstructure:"boot_type" json:"boot_type" required:"false" cty:"boot_type" hcl:"boot_type"` + VmDisks []FlatVmDisk `mapstructure:"vm_disks" cty:"vm_disks" hcl:"vm_disks"` + VmNICs []FlatVmNIC `mapstructure:"vm_nics" cty:"vm_nics" hcl:"vm_nics"` + ImageName *string `mapstructure:"image_name" json:"image_name" required:"false" cty:"image_name" hcl:"image_name"` + ClusterUUID *string `mapstructure:"cluster_uuid" json:"cluster_uuid" required:"false" cty:"cluster_uuid" hcl:"cluster_uuid"` + ClusterName *string `mapstructure:"cluster_name" json:"cluster_name" required:"false" cty:"cluster_name" hcl:"cluster_name"` + CPU *int64 `mapstructure:"cpu" json:"cpu" required:"false" cty:"cpu" hcl:"cpu"` + MemoryMB *int64 `mapstructure:"memory_mb" json:"memory_mb" required:"false" cty:"memory_mb" hcl:"memory_mb"` + UserData *string `mapstructure:"user_data" json:"user_data" required:"false" cty:"user_data" hcl:"user_data"` + VMCategories []FlatCategory `mapstructure:"vm_categories" required:"false" cty:"vm_categories" hcl:"vm_categories"` } // FlatMapstructure returns a new FlatVmConfig. @@ -261,19 +281,18 @@ func (*VmConfig) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec // The decoded values from this spec will then be applied to a FlatVmConfig. func (*FlatVmConfig) HCL2Spec() map[string]hcldec.Spec { s := map[string]hcldec.Spec{ - "vm_name": &hcldec.AttrSpec{Name: "vm_name", Type: cty.String, Required: false}, - "os_type": &hcldec.AttrSpec{Name: "os_type", Type: cty.String, Required: false}, - "boot_type": &hcldec.AttrSpec{Name: "boot_type", Type: cty.String, Required: false}, - "vm_disks": &hcldec.BlockListSpec{TypeName: "vm_disks", Nested: hcldec.ObjectSpec((*FlatVmDisk)(nil).HCL2Spec())}, - "vm_nics": &hcldec.BlockListSpec{TypeName: "vm_nics", Nested: hcldec.ObjectSpec((*FlatVmNIC)(nil).HCL2Spec())}, - "image_name": &hcldec.AttrSpec{Name: "image_name", Type: cty.String, Required: false}, - "cluster_uuid": &hcldec.AttrSpec{Name: "cluster_uuid", Type: cty.String, Required: false}, - "cluster_name": &hcldec.AttrSpec{Name: "cluster_name", Type: cty.String, Required: false}, - "cpu": &hcldec.AttrSpec{Name: "cpu", Type: cty.Number, Required: false}, - "memory_mb": &hcldec.AttrSpec{Name: "memory_mb", Type: cty.Number, Required: false}, - "user_data": &hcldec.AttrSpec{Name: "user_data", Type: cty.String, Required: false}, - "vm_category_key": &hcldec.AttrSpec{Name: "vm_category_key", Type: cty.String, Required: false}, - "vm_category_value": &hcldec.AttrSpec{Name: "vm_category_value", Type: cty.String, Required: false}, + "vm_name": &hcldec.AttrSpec{Name: "vm_name", Type: cty.String, Required: false}, + "os_type": &hcldec.AttrSpec{Name: "os_type", Type: cty.String, Required: false}, + "boot_type": &hcldec.AttrSpec{Name: "boot_type", Type: cty.String, Required: false}, + "vm_disks": &hcldec.BlockListSpec{TypeName: "vm_disks", Nested: hcldec.ObjectSpec((*FlatVmDisk)(nil).HCL2Spec())}, + "vm_nics": &hcldec.BlockListSpec{TypeName: "vm_nics", Nested: hcldec.ObjectSpec((*FlatVmNIC)(nil).HCL2Spec())}, + "image_name": &hcldec.AttrSpec{Name: "image_name", Type: cty.String, Required: false}, + "cluster_uuid": &hcldec.AttrSpec{Name: "cluster_uuid", Type: cty.String, Required: false}, + "cluster_name": &hcldec.AttrSpec{Name: "cluster_name", Type: cty.String, Required: false}, + "cpu": &hcldec.AttrSpec{Name: "cpu", Type: cty.Number, Required: false}, + "memory_mb": &hcldec.AttrSpec{Name: "memory_mb", Type: cty.Number, Required: false}, + "user_data": &hcldec.AttrSpec{Name: "user_data", Type: cty.String, Required: false}, + "vm_categories": &hcldec.BlockListSpec{TypeName: "vm_categories", Nested: hcldec.ObjectSpec((*FlatCategory)(nil).HCL2Spec())}, } return s } diff --git a/builder/nutanix/driver.go b/builder/nutanix/driver.go index 624716e..e8cd9ff 100644 --- a/builder/nutanix/driver.go +++ b/builder/nutanix/driver.go @@ -31,7 +31,7 @@ type Driver interface { UploadImage(string, string, string, VmConfig) (*nutanixImage, error) DeleteImage(string) error GetImage(string) (*nutanixImage, error) - SaveVMDisk(string, string, string) (*nutanixImage, error) + SaveVMDisk(string, []Category) (*nutanixImage, error) WaitForShutdown(string, <-chan struct{}) bool } @@ -426,9 +426,11 @@ func (d *NutanixDriver) CreateRequest(vm VmConfig) (*v3.VMIntentInput, error) { } } - if vm.VmCategoryKey != "" && vm.VmCategoryValue != "" { + if len(vm.VMCategories) != 0 { c := make(map[string]string) - c[vm.VmCategoryKey] = vm.VmCategoryValue + for _, category := range vm.VMCategories { + c[category.Key] = category.Value + } req.Metadata.Categories = c } @@ -732,7 +734,7 @@ func (d *NutanixDriver) PowerOff(vmUUID string) error { log.Printf("PowerOff task: %s", taskUUID) return nil } -func (d *NutanixDriver) SaveVMDisk(diskUUID string, imageCategoryKey string, imageCategoryValue string) (*nutanixImage, error) { +func (d *NutanixDriver) SaveVMDisk(diskUUID string, imageCategories []Category) (*nutanixImage, error) { configCreds := client.Credentials{ URL: fmt.Sprintf("%s:%d", d.ClusterConfig.Endpoint, d.ClusterConfig.Port), @@ -795,9 +797,11 @@ func (d *NutanixDriver) SaveVMDisk(diskUUID string, imageCategoryKey string, ima }, } - if imageCategoryKey != "" && imageCategoryValue != "" { + if len(imageCategories) != 0 { c := make(map[string]string) - c[imageCategoryKey] = imageCategoryValue + for _, category := range imageCategories { + c[category.Key] = category.Value + } req.Metadata.Categories = c } diff --git a/builder/nutanix/step_copy_image.go b/builder/nutanix/step_copy_image.go index c19d8ce..1e5dfd8 100644 --- a/builder/nutanix/step_copy_image.go +++ b/builder/nutanix/step_copy_image.go @@ -40,7 +40,7 @@ func (s *stepCopyImage) Run(ctx context.Context, state multistep.StateBag) multi return multistep.ActionHalt } - imageResponse, err := d.SaveVMDisk(diskToCopy, s.Config.ImageCategoryKey, s.Config.ImageCategoryValue) + imageResponse, err := d.SaveVMDisk(diskToCopy, s.Config.ImageCategories) if err != nil { ui.Error("Image creation failed: " + err.Error()) state.Put("error", err) diff --git a/docs/builders/nutanix.mdx b/docs/builders/nutanix.mdx index d43c95d..5efce3c 100644 --- a/docs/builders/nutanix.mdx +++ b/docs/builders/nutanix.mdx @@ -31,6 +31,7 @@ These parameters allow to define information about platform and temporary VM use - `cd_label` (string) - Label of this CD Drive. - `boot_type` (string) - Type of boot used on the temporary VM ("legacy" or "UEFI"). - `ip_wait_timeout` (duration string | ex: "0h42m0s") - Amount of time to wait for VM's IP, similar to 'ssh_timeout'. Defaults to 15m (15 minutes). See the Golang [ParseDuration](https://golang.org/pkg/time/#ParseDuration) documentation for full details. + - `vm_categories` ([]Category) - Assign Categories to the vm. ## Output configuration @@ -39,15 +40,12 @@ These parameters allow to configure everything around image creation, from the t ### All OS - `image_name` (string) - Name of the output image. - `image_description` (string) - Description for output image. -- `image_category_key` (string) - Name of the category to assign to the image. -- `image_category_value` (string) - Value of the category to assign to the image. +- `image_categories` ([]Category) - Assign Categories to the image. - `force_deregister` (bool) - Allow output image override if already exists. - `image_delete` (bool) - Delete image once build process is completed. - `shutdown_command` (string) - Command line to shutdown your temporary VM. - `shutdown_timeout` (string) - Timeout for VM shutdown (format : 2m). - `communicator` (string) - Protocol used for Packer connection (ex "winrm" or "ssh"). Default is : "ssh". -- `vm_category_key` (string) - Name of the category to assign to the vm. -- `vm_category_value` (string) - Value of the category to assign to the vm. ### Dedicated to Linux - `user_data` (string) - cloud-init content base64 coded. @@ -127,5 +125,25 @@ Sample } ``` +## Categories Configuration + +Use `image_categories{}` and `vm_categories{}` to assign category to your image or vm. If you want to assign multiple categories , use the entry multiple times. + +In this section, you have to define category you will to assign with the following parameters: + +- `key` (string) - Name of the category to assign. +- `value` (string) - Value of the category to assign. + +Sample +```hcl + image_categories { + key = "OSType" + value = "ubuntu-22.04" + } +``` + +Note: Categories must already be present in Prism Central. + ## Samples + You can find samples [here](https://github.com/nutanix-cloud-native/packer-plugin-nutanix/tree/main/example) for these instructions usage. \ No newline at end of file diff --git a/example/source.nutanix.pkr.hcl b/example/source.nutanix.pkr.hcl index 0633945..58ddb81 100644 --- a/example/source.nutanix.pkr.hcl +++ b/example/source.nutanix.pkr.hcl @@ -17,6 +17,17 @@ source "nutanix" "centos" { subnet_name = var.nutanix_subnet } + + image_categories { + key = "TemplateType" + value = "Vm" + } + + vm_categories { + key = "Environment" + value = "Dev" + } + image_name = "centos-packer-image" force_deregister = true user_data = "I2Nsb3VkLWNvbmZpZwp1c2VyczoKICAtIG5hbWU6IGNlbnRvcwogICAgc3VkbzogWydBTEw9KEFMTCkgTk9QQVNTV0Q6QUxMJ10KY2hwYXNzd2Q6CiAgbGlzdDogfAogICAgY2VudG9zOnBhY2tlcgogIGV4cGlyZTogRmFsc2UKc3NoX3B3YXV0aDogVHJ1ZQ==" diff --git a/test/e2e/centos-img/source.pkr.hcl b/test/e2e/centos-img/source.pkr.hcl index d4b20e4..14b8a3e 100644 --- a/test/e2e/centos-img/source.pkr.hcl +++ b/test/e2e/centos-img/source.pkr.hcl @@ -17,14 +17,20 @@ source "nutanix" "centos" { subnet_name = var.nutanix_subnet } + image_categories { + key = "TemplateType" + value = "Vm" + } + + vm_categories { + key = "Environment" + value = "Testing" + } + vm_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}" - vm_category_key = "Environment" - vm_category_value = "Testing" image_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}" image_delete = true - image_category_key = "Environment" - image_category_value = "Testing" force_deregister = true user_data = "I2Nsb3VkLWNvbmZpZwp1c2VyczoKICAtIG5hbWU6IGNlbnRvcwogICAgc3VkbzogWydBTEw9KEFMTCkgTk9QQVNTV0Q6QUxMJ10KY2hwYXNzd2Q6CiAgbGlzdDogfAogICAgY2VudG9zOnBhY2tlcgogIGV4cGlyZTogRmFsc2UKc3NoX3B3YXV0aDogVHJ1ZQ==" diff --git a/test/e2e/centos-iso/source.pkr.hcl b/test/e2e/centos-iso/source.pkr.hcl index 2df5b9e..f4df7bc 100644 --- a/test/e2e/centos-iso/source.pkr.hcl +++ b/test/e2e/centos-iso/source.pkr.hcl @@ -20,18 +20,24 @@ source "nutanix" "centos" { vm_nics { subnet_name = var.nutanix_subnet } - + + image_categories { + key = "TemplateType" + value = "Vm" + } + + vm_categories { + key = "Environment" + value = "Testing" + } + cd_files = ["scripts/ks.cfg"] cd_label = "OEMDRV" vm_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}" - vm_category_key = "Environment" - vm_category_value = "Testing" - image_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}" image_delete = true - image_category_key = "Environment" - image_category_value = "Testing" + force_deregister = true