diff --git a/CHANGELOG.md b/CHANGELOG.md index 5161f2f41..fd44c4bea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ * builder/amazon: Fix single `tag` interpolation to allow for templating engine usage. [GH-10224] * builder/yandex: Fixed using cloud config when using IPv6 [GH-10297] +* post-processort/yandex-export: added check of service account id ## 1.6.5 (October 30, 2020) 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) 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 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/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 +} diff --git a/post-processor/yandex-export/script.go b/post-processor/yandex-export/script.go index d12883e08..b3d6b010a 100644 --- a/post-processor/yandex-export/script.go +++ b/post-processor/yandex-export/script.go @@ -110,8 +110,23 @@ 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 + sleep 3 + /sbin/udevadm trigger + if [ -L "${DISK_LINK}" ]; then + break + fi + echo "Attempt ${attempt}" + if [ ${attempt} -eq 3 ]; then + echo "Symlink ${DISK_LINK} not found" + Exit 1 + fi +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 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"] } ``` 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' 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.