From 73b7499811cb0e910114737c6f73f865d736b9d8 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Mon, 23 Nov 2020 16:27:26 +0100 Subject: [PATCH 01/10] HCL2: version block: test validation & document version/availability (#10298) * HCL2: Test that the packer block passes in packer validate * HCL2: Test invalid packer blocks are invalid * docs: state from which version the packer block is available --- command/test-fixtures/validate/build.pkr.hcl | 4 ++++ command/test-fixtures/validate/invalid_packer_block.pkr.hcl | 3 +++ command/validate_test.go | 3 +++ website/pages/docs/from-1.5/blocks/packer.mdx | 2 ++ 4 files changed, 12 insertions(+) create mode 100644 command/test-fixtures/validate/invalid_packer_block.pkr.hcl diff --git a/command/test-fixtures/validate/build.pkr.hcl b/command/test-fixtures/validate/build.pkr.hcl index 416189e5a..b70cd535f 100644 --- a/command/test-fixtures/validate/build.pkr.hcl +++ b/command/test-fixtures/validate/build.pkr.hcl @@ -1,3 +1,7 @@ +packer { + required_version = ">= v1.0.0" +} + source "file" "chocolate" { target = "chocolate.txt" content = "chocolate" diff --git a/command/test-fixtures/validate/invalid_packer_block.pkr.hcl b/command/test-fixtures/validate/invalid_packer_block.pkr.hcl new file mode 100644 index 000000000..6388be9fd --- /dev/null +++ b/command/test-fixtures/validate/invalid_packer_block.pkr.hcl @@ -0,0 +1,3 @@ +packer { + version = ">= v1.0.0" +} diff --git a/command/validate_test.go b/command/validate_test.go index f8884cd18..ede32c1a3 100644 --- a/command/validate_test.go +++ b/command/validate_test.go @@ -26,6 +26,9 @@ func TestValidateCommand(t *testing.T) { // wrong version field {path: filepath.Join(testFixture("version_req", "wrong_field_name")), exitCode: 1}, + + // wrong packer block + {path: filepath.Join(testFixture("validate", "invalid_packer_block.pkr.hcl")), exitCode: 1}, } for _, tc := range tt { diff --git a/website/pages/docs/from-1.5/blocks/packer.mdx b/website/pages/docs/from-1.5/blocks/packer.mdx index 4b0e5b5c4..85d1cc114 100644 --- a/website/pages/docs/from-1.5/blocks/packer.mdx +++ b/website/pages/docs/from-1.5/blocks/packer.mdx @@ -11,6 +11,8 @@ description: |- `@include 'from-1.5/beta-hcl2-note.mdx'` +-> **Note:** The Packer block is only available in Packer v1.6.5 and later. + The `packer` configuration block type is used to configure some behaviors of Packer itself, such as the minimum required Packer version needed to apply your configuration. From 138e3a081ba51fdf8c4468e371919c8e459132ee Mon Sep 17 00:00:00 2001 From: Gennady Lipenkov Date: Tue, 24 Nov 2020 19:15:46 +0300 Subject: [PATCH 02/10] Add retries and wait after disk attach operation --- post-processor/yandex-export/script.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/post-processor/yandex-export/script.go b/post-processor/yandex-export/script.go index d12883e08..2a2cbfd43 100644 --- a/post-processor/yandex-export/script.go +++ b/post-processor/yandex-export/script.go @@ -110,8 +110,22 @@ if ! yc compute instance attach-disk ${INSTANCE_ID} --disk-name ${DISKNAME} --de Exit 1 fi +DISK_LINK="/dev/disk/by-id/virtio-doexport" +echo "Waiting for disk..." +for attempt in 1 2 3; do + if [ -L "${DISK_LINK}" ]; then + break + fi + echo "Attempt ${attempt}" + if [ ${attempt} -eq 3 ]; then + echo "Symlink ${DISK_LINK} not found" + Exit 1 + fi + sleep 3 +done + echo "Dumping disk..." -if ! qemu-img convert -O qcow2 -o cluster_size=2M /dev/disk/by-id/virtio-doexport disk.qcow2 ; then +if ! qemu-img convert -O qcow2 -o cluster_size=2M "${DISK_LINK}" disk.qcow2 ; then echo "Failed to dump disk to qcow2 image." Exit 1 fi From a509781a03f5fad6890a28641a55d949da55fb98 Mon Sep 17 00:00:00 2001 From: Roman Mingazeev Date: Tue, 24 Nov 2020 20:04:37 +0300 Subject: [PATCH 03/10] added check of service account id in export --- post-processor/yandex-export/post-processor.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/post-processor/yandex-export/post-processor.go b/post-processor/yandex-export/post-processor.go index 8c48da450..e10deed7c 100644 --- a/post-processor/yandex-export/post-processor.go +++ b/post-processor/yandex-export/post-processor.go @@ -21,6 +21,8 @@ import ( "github.com/hashicorp/packer/packer-plugin-sdk/template/config" "github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate" "github.com/hashicorp/packer/post-processor/artifice" + "github.com/yandex-cloud/go-genproto/yandex/cloud/iam/v1" + ycsdk "github.com/yandex-cloud/go-sdk" ) const defaultStorageEndpoint = "storage.yandexcloud.net" @@ -196,6 +198,11 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact return nil, false, false, err } + ui.Say(fmt.Sprintf("Validating service_account_id: '%s'...", yandexConfig.ServiceAccountID)) + if err := validateServiceAccount(ctx, driver.SDK(), yandexConfig.ServiceAccountID); err != nil { + return nil, false, false, err + } + // Set up the state. state := new(multistep.BasicStateBag) state.Put("config", &yandexConfig) @@ -259,3 +266,10 @@ func formUrls(paths []string) []string { } return result } + +func validateServiceAccount(ctx context.Context, ycsdk *ycsdk.SDK, serviceAccountID string) error { + _, err := ycsdk.IAM().ServiceAccount().Get(ctx, &iam.GetServiceAccountRequest{ + ServiceAccountId: serviceAccountID, + }) + return err +} From 677c48d294c5ab5684d53a5f138efe389f745529 Mon Sep 17 00:00:00 2001 From: Roman Mingazeev Date: Tue, 24 Nov 2020 20:07:52 +0300 Subject: [PATCH 04/10] add record to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f320c681c..60d1cd44b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ ### BUG FIXES * builder/amazon: Fix single `tag` interpolation to allow for templating engine usage. [GH-10224] +* post-processort/yandex-export: added check of service account id ## 1.6.5 (October 30, 2020) From fdb36e329d1f684d8966c7f11e034a35c694471a Mon Sep 17 00:00:00 2001 From: Corey Hickey Date: Tue, 24 Nov 2020 15:39:43 -0800 Subject: [PATCH 05/10] allow attaching guest additions without a communicator This avoids the error: * guest_additions_mode has to be 'disable' when communicator = 'none'. ...when the following are set: "communicator": "none", "guest_additions_mode": "attach", This particular combination of parameters is valid; for example, in my case, a kickstart post-install script mounts the CD image from /dev/sr1 and runs the installer, without needing any intervention from packer itself. From my reading of the documentation, it appears that the "upload" mode would indeed require a communicator, so I change the logic to check for that specifically. --- builder/virtualbox/common/guest_additions_config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builder/virtualbox/common/guest_additions_config.go b/builder/virtualbox/common/guest_additions_config.go index 673f4a3d1..5e8d430ba 100644 --- a/builder/virtualbox/common/guest_additions_config.go +++ b/builder/virtualbox/common/guest_additions_config.go @@ -83,9 +83,9 @@ func (c *GuestAdditionsConfig) Prepare(communicatorType string) []error { fmt.Errorf("guest_additions_mode is invalid. Must be one of: %v", validModes)) } - if communicatorType == "none" && c.GuestAdditionsMode != "disable" { - errs = append(errs, fmt.Errorf("guest_additions_mode has to be "+ - "'disable' when communicator = 'none'.")) + if communicatorType == "none" && c.GuestAdditionsMode == "upload" { + errs = append(errs, fmt.Errorf("communicator must not be 'none' "+ + "when guest_additions_mode = 'upload'.")) } return errs From 6c410e4d13861dd84135689b81fb8831aedd70e0 Mon Sep 17 00:00:00 2001 From: sylviamoss Date: Wed, 25 Nov 2020 10:48:10 +0100 Subject: [PATCH 06/10] improve customization example --- website/pages/docs/builders/vmware/vsphere-clone.mdx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/website/pages/docs/builders/vmware/vsphere-clone.mdx b/website/pages/docs/builders/vmware/vsphere-clone.mdx index a9b68e4be..c12f999cf 100644 --- a/website/pages/docs/builders/vmware/vsphere-clone.mdx +++ b/website/pages/docs/builders/vmware/vsphere-clone.mdx @@ -141,7 +141,9 @@ can be done via environment variable: "network_interface": { "ipv4_address": "10.0.0.10", "ipv4_netmask": "24" - } + }, + "ipv4_gateway": "10.0.0.1", + "dns_server_list": ["10.0.0.18"] } ``` @@ -159,6 +161,9 @@ can be done via environment variable: ipv4_address = "10.0.0.10" ipv4_netmask = "24" } + + ipv4_gateway = 10.0.0.1 + dns_server_list = ["10.0.0.18"] } ``` From ef67fb1cc87359d3025c9394d5528f62c11bf976 Mon Sep 17 00:00:00 2001 From: Gennady Lipenkov Date: Wed, 25 Nov 2020 15:45:49 +0300 Subject: [PATCH 07/10] Some wait before check --- post-processor/yandex-export/script.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post-processor/yandex-export/script.go b/post-processor/yandex-export/script.go index 2a2cbfd43..150324b42 100644 --- a/post-processor/yandex-export/script.go +++ b/post-processor/yandex-export/script.go @@ -113,6 +113,7 @@ fi DISK_LINK="/dev/disk/by-id/virtio-doexport" echo "Waiting for disk..." for attempt in 1 2 3; do + sleep 3 if [ -L "${DISK_LINK}" ]; then break fi @@ -121,7 +122,6 @@ for attempt in 1 2 3; do echo "Symlink ${DISK_LINK} not found" Exit 1 fi - sleep 3 done echo "Dumping disk..." From 4c3e310f57816d3db973cff83a96730d6831596b Mon Sep 17 00:00:00 2001 From: Gennady Lipenkov Date: Thu, 26 Nov 2020 17:29:33 +0300 Subject: [PATCH 08/10] manually trigger udev --- post-processor/yandex-export/script.go | 1 + 1 file changed, 1 insertion(+) diff --git a/post-processor/yandex-export/script.go b/post-processor/yandex-export/script.go index 150324b42..b3d6b010a 100644 --- a/post-processor/yandex-export/script.go +++ b/post-processor/yandex-export/script.go @@ -114,6 +114,7 @@ DISK_LINK="/dev/disk/by-id/virtio-doexport" echo "Waiting for disk..." for attempt in 1 2 3; do sleep 3 + /sbin/udevadm trigger if [ -L "${DISK_LINK}" ]; then break fi From d82b9d2072947f9a6f5035badc934f961dbb6617 Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Mon, 30 Nov 2020 10:40:03 -0500 Subject: [PATCH 09/10] builder/qemu: Add ok check for state values (#10249) This changes fixes two crashes in `step_run` that expects certain information to be in state from prior steps. This change requires testing to ensure the bugs have been fixed. I believe there may be more state values that need to be checked as they may not be put into state if a build configuration has attributes that would skip or otherwise not put data into the statebag. --- builder/qemu/step_create_disk.go | 7 +++---- builder/qemu/step_run.go | 10 +++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/builder/qemu/step_create_disk.go b/builder/qemu/step_create_disk.go index 03de4fe7e..8a0c8eb51 100644 --- a/builder/qemu/step_create_disk.go +++ b/builder/qemu/step_create_disk.go @@ -32,12 +32,11 @@ func (s *stepCreateDisk) Run(ctx context.Context, state multistep.StateBag) mult return multistep.ActionContinue } - var diskFullPaths, diskSizes []string - ui.Say("Creating required virtual machine disks") // The 'main' or 'default' disk - diskFullPaths = append(diskFullPaths, filepath.Join(s.OutputDir, name)) - diskSizes = append(diskSizes, s.DiskSize) + diskFullPaths := []string{filepath.Join(s.OutputDir, name)} + diskSizes := []string{s.DiskSize} + // Additional disks if len(s.AdditionalDiskSize) > 0 { for i, diskSize := range s.AdditionalDiskSize { diff --git a/builder/qemu/step_run.go b/builder/qemu/step_run.go index ab2b36886..873b79256 100644 --- a/builder/qemu/step_run.go +++ b/builder/qemu/step_run.go @@ -216,8 +216,10 @@ func (s *stepRun) getDeviceAndDriveArgs(config *Config, state multistep.StateBag drivesToAttach = append(drivesToAttach, imgPath) } - diskFullPaths := state.Get("qemu_disk_paths").([]string) - drivesToAttach = append(drivesToAttach, diskFullPaths...) + if v, ok := state.GetOk("qemu_disk_paths"); ok { + diskFullPaths := v.([]string) + drivesToAttach = append(drivesToAttach, diskFullPaths...) + } for i, drivePath := range drivesToAttach { driveArgumentString := fmt.Sprintf("file=%s,if=%s,cache=%s,discard=%s,format=%s", drivePath, config.DiskInterface, config.DiskCache, config.DiskDiscard, config.Format) @@ -284,7 +286,9 @@ func (s *stepRun) applyUserOverrides(defaultArgs map[string]interface{}, config commHostPort := 0 if config.CommConfig.Comm.Type != "none" { - commHostPort = state.Get("commHostPort").(int) + if v, ok := state.GetOk("commHostPort"); ok { + commHostPort = v.(int) + } } httpIp := state.Get("http_ip").(string) httpPort := state.Get("http_port").(int) From 5ff59be2426170556f13cec82925eb8a2c8d2cdf Mon Sep 17 00:00:00 2001 From: adeniyistephen1 Date: Sat, 21 Nov 2020 13:09:31 +0100 Subject: [PATCH 10/10] Fix SSH-Private-Key-File to the vsphere-iso mdx file --- website/pages/docs/builders/vmware/vsphere-iso.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/pages/docs/builders/vmware/vsphere-iso.mdx b/website/pages/docs/builders/vmware/vsphere-iso.mdx index a6b06b6ec..f27bee15e 100644 --- a/website/pages/docs/builders/vmware/vsphere-iso.mdx +++ b/website/pages/docs/builders/vmware/vsphere-iso.mdx @@ -288,6 +288,8 @@ Minimal example of usage to import a OVF template: @include 'helper/communicator/SSH-not-required.mdx' +@include 'helper/communicator/SSH-Private-Key-File-not-required.mdx' + #### Optional WinRM fields: @include 'helper/communicator/WinRM-not-required.mdx'