diff --git a/.github/actions/build-and-persist-plugin-binary/action.yml b/.github/actions/build-and-persist-plugin-binary/action.yml
index a9e0b2874..3845b9f56 100644
--- a/.github/actions/build-and-persist-plugin-binary/action.yml
+++ b/.github/actions/build-and-persist-plugin-binary/action.yml
@@ -10,7 +10,7 @@ inputs:
runs:
using: composite
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- run: "GOOS=${{ inputs.GOOS }} GOARCH=${{ inputs.GOARCH }} go build -o ./pkg/packer_plugin_amazon_${{ inputs.GOOS }}_${{ inputs.GOARCH }} ."
shell: bash
- run: zip ./pkg/packer_plugin_amazon_${{ inputs.GOOS }}_${{ inputs.GOARCH }}.zip ./pkg/packer_plugin_amazon_${{ inputs.GOOS }}_${{ inputs.GOARCH }}
diff --git a/.github/release.yml b/.github/release.yml
index 7719b0431..47288604a 100644
--- a/.github/release.yml
+++ b/.github/release.yml
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
changelog:
exclude:
labels:
diff --git a/.github/workflows/build_plugin_binaries.yml b/.github/workflows/build_plugin_binaries.yml
index c74db9fc8..d97e70af7 100644
--- a/.github/workflows/build_plugin_binaries.yml
+++ b/.github/workflows/build_plugin_binaries.yml
@@ -17,7 +17,7 @@ jobs:
container:
image: docker.mirror.hashicorp.services/cimg/go:1.18
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: "./.github/actions/build-and-persist-plugin-binary"
with:
GOOS: darwin
@@ -34,7 +34,7 @@ jobs:
container:
image: docker.mirror.hashicorp.services/cimg/go:1.18
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: "./.github/actions/build-and-persist-plugin-binary"
with:
GOOS: freebsd
@@ -55,7 +55,7 @@ jobs:
container:
image: docker.mirror.hashicorp.services/cimg/go:1.18
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: "./.github/actions/build-and-persist-plugin-binary"
with:
GOOS: linux
@@ -80,7 +80,7 @@ jobs:
container:
image: docker.mirror.hashicorp.services/cimg/go:1.18
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: "./.github/actions/build-and-persist-plugin-binary"
with:
GOOS: netbsd
@@ -101,7 +101,7 @@ jobs:
container:
image: docker.mirror.hashicorp.services/cimg/go:1.18
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: "./.github/actions/build-and-persist-plugin-binary"
with:
GOOS: openbsd
@@ -122,7 +122,7 @@ jobs:
container:
image: docker.mirror.hashicorp.services/cimg/go:1.18
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: "./.github/actions/build-and-persist-plugin-binary"
with:
GOOS: solaris
@@ -135,7 +135,7 @@ jobs:
container:
image: docker.mirror.hashicorp.services/cimg/go:1.18
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: "./.github/actions/build-and-persist-plugin-binary"
with:
GOOS: windows
diff --git a/.github/workflows/go-test-darwin.yml b/.github/workflows/go-test-darwin.yml
index cd23a4c40..30bf6c409 100644
--- a/.github/workflows/go-test-darwin.yml
+++ b/.github/workflows/go-test-darwin.yml
@@ -23,7 +23,7 @@ jobs:
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: 'Determine Go version'
id: get-go-version
run: |
@@ -35,7 +35,7 @@ jobs:
runs-on: macos-latest
name: Darwin Go tests
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
diff --git a/.github/workflows/go-test-linux.yml b/.github/workflows/go-test-linux.yml
index b6c16a8c7..00fb01e0c 100644
--- a/.github/workflows/go-test-linux.yml
+++ b/.github/workflows/go-test-linux.yml
@@ -23,7 +23,7 @@ jobs:
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: 'Determine Go version'
id: get-go-version
run: |
@@ -35,7 +35,7 @@ jobs:
runs-on: ubuntu-latest
name: Linux Go tests
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
diff --git a/.github/workflows/go-test-windows.yml b/.github/workflows/go-test-windows.yml
index caca3eb2b..a0ed1f00b 100644
--- a/.github/workflows/go-test-windows.yml
+++ b/.github/workflows/go-test-windows.yml
@@ -23,7 +23,7 @@ jobs:
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: 'Determine Go version'
id: get-go-version
run: |
@@ -35,7 +35,7 @@ jobs:
runs-on: windows-latest
name: Windows Go tests
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
diff --git a/.github/workflows/go-validate.yml b/.github/workflows/go-validate.yml
index 3d632d589..c4bcce800 100644
--- a/.github/workflows/go-validate.yml
+++ b/.github/workflows/go-validate.yml
@@ -22,7 +22,7 @@ jobs:
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: 'Determine Go version'
id: get-go-version
run: |
@@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest
name: Go Mod Tidy
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
@@ -45,7 +45,7 @@ jobs:
runs-on: ubuntu-latest
name: Lint check
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
@@ -59,7 +59,7 @@ jobs:
runs-on: ubuntu-latest
name: Gofmt check
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
@@ -77,10 +77,13 @@ jobs:
runs-on: ubuntu-latest
name: Generate check
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- run: |
export PATH=$PATH:$(go env GOPATH)/bin
make generate
+ git diff --exit-code || ( echo "Found diffs in generated code" \
+ && echo "You can use the command: \`make generate\` to reformat code." \
+ && false )
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 19863ec69..7a63e3d99 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -26,7 +26,7 @@ jobs:
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: 'Determine Go version'
id: get-go-version
run: |
@@ -38,7 +38,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
+ uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
diff --git a/.gitignore b/.gitignore
index ac48f6438..71ab8a630 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ packer-plugin-amazon
.docs
.DS_Store
*.sw*
+crash.log
diff --git a/.golangci.yml b/.golangci.yml
index 014dd27b8..78b774dcb 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
diff --git a/.goreleaser.yml b/.goreleaser.yml
index b8428ed6c..1c48ac230 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
# This is an example goreleaser.yaml file with some defaults.
# Make sure to check the documentation at http://goreleaser.com
env:
diff --git a/README.md b/README.md
index 962ebdb8e..1fc40f4a8 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Then, run [`packer init`](https://www.packer.io/docs/commands/init).
packer {
required_plugins {
amazon = {
- version = ">= 1.2.4"
+ version = ">= 1.2.5"
source = "github.com/hashicorp/amazon"
}
}
diff --git a/builder/chroot/builder.go b/builder/chroot/builder.go
index d25c3a6c9..6cebf0cfb 100644
--- a/builder/chroot/builder.go
+++ b/builder/chroot/builder.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type Config,BlockDevices,BlockDevice
diff --git a/builder/chroot/builder_test.go b/builder/chroot/builder_test.go
index 1b3f3796b..901391d39 100644
--- a/builder/chroot/builder_test.go
+++ b/builder/chroot/builder_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/copy_files.go b/builder/chroot/copy_files.go
index f7358556a..c10fb8545 100644
--- a/builder/chroot/copy_files.go
+++ b/builder/chroot/copy_files.go
@@ -1 +1,4 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
diff --git a/builder/chroot/copy_files_test.go b/builder/chroot/copy_files_test.go
index 6b3a56eaa..4ff70603e 100644
--- a/builder/chroot/copy_files_test.go
+++ b/builder/chroot/copy_files_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/device.go b/builder/chroot/device.go
index a77f67fb0..e4409a30e 100644
--- a/builder/chroot/device.go
+++ b/builder/chroot/device.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/device_test.go b/builder/chroot/device_test.go
index a47fc7dff..ea5aefd4b 100644
--- a/builder/chroot/device_test.go
+++ b/builder/chroot/device_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import "testing"
diff --git a/builder/chroot/lockfile.go b/builder/chroot/lockfile.go
index b02d462f0..213d40bcd 100644
--- a/builder/chroot/lockfile.go
+++ b/builder/chroot/lockfile.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:build windows
// +build windows
diff --git a/builder/chroot/lockfile_unix.go b/builder/chroot/lockfile_unix.go
index 98a77524a..90c301028 100644
--- a/builder/chroot/lockfile_unix.go
+++ b/builder/chroot/lockfile_unix.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:build !windows
// +build !windows
diff --git a/builder/chroot/step_attach_volume.go b/builder/chroot/step_attach_volume.go
index cb0223efd..20c9587ef 100644
--- a/builder/chroot/step_attach_volume.go
+++ b/builder/chroot/step_attach_volume.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_attach_volume_test.go b/builder/chroot/step_attach_volume_test.go
index 72f8b24f0..f0311251a 100644
--- a/builder/chroot/step_attach_volume_test.go
+++ b/builder/chroot/step_attach_volume_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_check_root_device.go b/builder/chroot/step_check_root_device.go
index f5d83b7bd..e8af36dfe 100644
--- a/builder/chroot/step_check_root_device.go
+++ b/builder/chroot/step_check_root_device.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_create_volume.go b/builder/chroot/step_create_volume.go
index b99636c19..ba50e19af 100644
--- a/builder/chroot/step_create_volume.go
+++ b/builder/chroot/step_create_volume.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_create_volume_test.go b/builder/chroot/step_create_volume_test.go
index 22cb82a75..8e692823e 100644
--- a/builder/chroot/step_create_volume_test.go
+++ b/builder/chroot/step_create_volume_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_early_unflock.go b/builder/chroot/step_early_unflock.go
index d2fd76c6e..75dd21cd9 100644
--- a/builder/chroot/step_early_unflock.go
+++ b/builder/chroot/step_early_unflock.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_flock.go b/builder/chroot/step_flock.go
index ada3b53fd..67d337220 100644
--- a/builder/chroot/step_flock.go
+++ b/builder/chroot/step_flock.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_flock_test.go b/builder/chroot/step_flock_test.go
index ea113861f..f1b12fd09 100644
--- a/builder/chroot/step_flock_test.go
+++ b/builder/chroot/step_flock_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_instance_info.go b/builder/chroot/step_instance_info.go
index cab55c0e9..8059e6325 100644
--- a/builder/chroot/step_instance_info.go
+++ b/builder/chroot/step_instance_info.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_mount_device.go b/builder/chroot/step_mount_device.go
index 201dfd0c7..223269c9a 100644
--- a/builder/chroot/step_mount_device.go
+++ b/builder/chroot/step_mount_device.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_mount_device_test.go b/builder/chroot/step_mount_device_test.go
index 9c0433245..9e47a85a1 100644
--- a/builder/chroot/step_mount_device_test.go
+++ b/builder/chroot/step_mount_device_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_prepare_device.go b/builder/chroot/step_prepare_device.go
index 3eeaceff4..c2cc8724f 100644
--- a/builder/chroot/step_prepare_device.go
+++ b/builder/chroot/step_prepare_device.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_register_ami.go b/builder/chroot/step_register_ami.go
index c2c42c497..63e0a3fa7 100644
--- a/builder/chroot/step_register_ami.go
+++ b/builder/chroot/step_register_ami.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_register_ami_test.go b/builder/chroot/step_register_ami_test.go
index 8cc0baed9..903b30267 100644
--- a/builder/chroot/step_register_ami_test.go
+++ b/builder/chroot/step_register_ami_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/chroot/step_snapshot.go b/builder/chroot/step_snapshot.go
index 4f39f2ffd..038a04f0a 100644
--- a/builder/chroot/step_snapshot.go
+++ b/builder/chroot/step_snapshot.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package chroot
import (
diff --git a/builder/common/access_config.go b/builder/common/access_config.go
index a88f78de1..47f341955 100644
--- a/builder/common/access_config.go
+++ b/builder/common/access_config.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type VaultAWSEngineOptions,AssumeRoleConfig
diff --git a/builder/common/access_config_test.go b/builder/common/access_config_test.go
index 5a92ec93b..27140d3c5 100644
--- a/builder/common/access_config_test.go
+++ b/builder/common/access_config_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/ami_config.go b/builder/common/ami_config.go
index 639560473..0e9de9492 100644
--- a/builder/common/ami_config.go
+++ b/builder/common/ami_config.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
package common
diff --git a/builder/common/ami_config_test.go b/builder/common/ami_config_test.go
index 17933dfb4..6ea1adf99 100644
--- a/builder/common/ami_config_test.go
+++ b/builder/common/ami_config_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/ami_filter.go b/builder/common/ami_filter.go
index 019638004..3dd386b94 100644
--- a/builder/common/ami_filter.go
+++ b/builder/common/ami_filter.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
package common
diff --git a/builder/common/artifact.go b/builder/common/artifact.go
index c440315e6..c7b7e72d2 100644
--- a/builder/common/artifact.go
+++ b/builder/common/artifact.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/artifact_test.go b/builder/common/artifact_test.go
index 703de779f..69865e7d9 100644
--- a/builder/common/artifact_test.go
+++ b/builder/common/artifact_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/awserrors/utils.go b/builder/common/awserrors/utils.go
index 676ef9b4a..fad85d88e 100644
--- a/builder/common/awserrors/utils.go
+++ b/builder/common/awserrors/utils.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package awserrors
import (
diff --git a/builder/common/block_device.go b/builder/common/block_device.go
index dcb653173..c58ab43ef 100644
--- a/builder/common/block_device.go
+++ b/builder/common/block_device.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type BlockDevice
diff --git a/builder/common/block_device_test.go b/builder/common/block_device_test.go
index 8d33b918e..c6bdcd276 100644
--- a/builder/common/block_device_test.go
+++ b/builder/common/block_device_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/boot_mode_validation.go b/builder/common/boot_mode_validation.go
index 665c2bd0b..8f69a97f2 100644
--- a/builder/common/boot_mode_validation.go
+++ b/builder/common/boot_mode_validation.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import "fmt"
diff --git a/builder/common/boot_mode_validation_test.go b/builder/common/boot_mode_validation_test.go
index 3aaa7e0c4..44aa1313f 100644
--- a/builder/common/boot_mode_validation_test.go
+++ b/builder/common/boot_mode_validation_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import "testing"
diff --git a/builder/common/build_filter.go b/builder/common/build_filter.go
index f95bcb4ab..3ecc3a7bc 100644
--- a/builder/common/build_filter.go
+++ b/builder/common/build_filter.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/build_filter_test.go b/builder/common/build_filter_test.go
index 6dcd79f15..11c8a2fa2 100644
--- a/builder/common/build_filter_test.go
+++ b/builder/common/build_filter_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/checkip.go b/builder/common/checkip.go
index f3e94e58e..11dd5b988 100644
--- a/builder/common/checkip.go
+++ b/builder/common/checkip.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/errors.go b/builder/common/errors.go
index bca247bfa..02c4343bc 100644
--- a/builder/common/errors.go
+++ b/builder/common/errors.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/errors_test.go b/builder/common/errors_test.go
index b2c05390e..22f95af75 100644
--- a/builder/common/errors_test.go
+++ b/builder/common/errors_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/helper_funcs.go b/builder/common/helper_funcs.go
index b80d67c5a..1475a6d24 100644
--- a/builder/common/helper_funcs.go
+++ b/builder/common/helper_funcs.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/interpolate_build_info.go b/builder/common/interpolate_build_info.go
index 010e1b20f..1bf4e7c03 100644
--- a/builder/common/interpolate_build_info.go
+++ b/builder/common/interpolate_build_info.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/interpolate_build_info_test.go b/builder/common/interpolate_build_info_test.go
index f371d3ce7..80027eb84 100644
--- a/builder/common/interpolate_build_info_test.go
+++ b/builder/common/interpolate_build_info_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/regions.go b/builder/common/regions.go
index 24344c726..6d03c613a 100644
--- a/builder/common/regions.go
+++ b/builder/common/regions.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/run_config.go b/builder/common/run_config.go
index 87f24a9e1..77ffa67fe 100644
--- a/builder/common/run_config.go
+++ b/builder/common/run_config.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type AmiFilterOptions,SecurityGroupFilterOptions,SubnetFilterOptions,VpcFilterOptions,PolicyDocument,Statement,MetadataOptions,LicenseConfigurationRequest,LicenseSpecification,Placement
@@ -96,6 +99,21 @@ type RunConfig struct {
// If using a non-default VPC,
// public IP addresses are not provided by default. If this is true, your
// new instance will get a Public IP. default: unset
+ //
+ // Note: when specifying this attribute without a `subnet_[id|filter]` or
+ // `vpc_[id|filter]`, we will attempt to infer this information from the
+ // default VPC/Subnet.
+ // This operation may require some extra permissions to the IAM role that
+ // runs the build:
+ //
+ // * ec2:DescribeVpcs
+ // * ec2:DescribeSubnets
+ //
+ // Additionally, since we filter subnets/AZs by their capability to host
+ // an instance of the selected type, you may also want to define the
+ // `ec2:DescribeInstanceTypeOfferings` action to the role running the build.
+ // Otherwise, Packer will pick the most available subnet in the VPC selected,
+ // which may not be able to host the instance type you provided.
AssociatePublicIpAddress confighelper.Trilean `mapstructure:"associate_public_ip_address" required:"false"`
// Destination availability zone to launch
// instance in. Leave this empty to allow Amazon to auto-assign.
diff --git a/builder/common/run_config_test.go b/builder/common/run_config_test.go
index 7c2308a68..82fbc888b 100644
--- a/builder/common/run_config_test.go
+++ b/builder/common/run_config_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/snapshot_config.go b/builder/common/snapshot_config.go
index 542b893bb..5b61c8e9f 100644
--- a/builder/common/snapshot_config.go
+++ b/builder/common/snapshot_config.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
package common
diff --git a/builder/common/ssh.go b/builder/common/ssh.go
index 601956257..817dcd3ff 100644
--- a/builder/common/ssh.go
+++ b/builder/common/ssh.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/ssh_test.go b/builder/common/ssh_test.go
index 27bedca80..27171363f 100644
--- a/builder/common/ssh_test.go
+++ b/builder/common/ssh_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/ssm/session.go b/builder/common/ssm/session.go
index e91655145..3e33eb0f1 100644
--- a/builder/common/ssm/session.go
+++ b/builder/common/ssm/session.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ssm
import (
diff --git a/builder/common/state.go b/builder/common/state.go
index 0d81fb9be..c396b043f 100644
--- a/builder/common/state.go
+++ b/builder/common/state.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type AWSPollingConfig
package common
diff --git a/builder/common/step_ami_region_copy.go b/builder/common/step_ami_region_copy.go
index 8207f5133..d635955ed 100644
--- a/builder/common/step_ami_region_copy.go
+++ b/builder/common/step_ami_region_copy.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_ami_region_copy_test.go b/builder/common/step_ami_region_copy_test.go
index ba966ff24..c2601b09b 100644
--- a/builder/common/step_ami_region_copy_test.go
+++ b/builder/common/step_ami_region_copy_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_cleanup_volumes.go b/builder/common/step_cleanup_volumes.go
index 69613b84b..4738e73f2 100644
--- a/builder/common/step_cleanup_volumes.go
+++ b/builder/common/step_cleanup_volumes.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_create_ssm_tunnel.go b/builder/common/step_create_ssm_tunnel.go
index 15a86329f..b6083527a 100644
--- a/builder/common/step_create_ssm_tunnel.go
+++ b/builder/common/step_create_ssm_tunnel.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_create_tags.go b/builder/common/step_create_tags.go
index ccb3a9352..9c3f7cc84 100644
--- a/builder/common/step_create_tags.go
+++ b/builder/common/step_create_tags.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_deregister_ami.go b/builder/common/step_deregister_ami.go
index 135052229..cc42bca26 100644
--- a/builder/common/step_deregister_ami.go
+++ b/builder/common/step_deregister_ami.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_get_password.go b/builder/common/step_get_password.go
index dac97f92f..a6c14e64a 100644
--- a/builder/common/step_get_password.go
+++ b/builder/common/step_get_password.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_iam_instance_profile.go b/builder/common/step_iam_instance_profile.go
index 4bee1f872..851f918b5 100644
--- a/builder/common/step_iam_instance_profile.go
+++ b/builder/common/step_iam_instance_profile.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_key_pair.go b/builder/common/step_key_pair.go
index f7c74069e..a12246592 100644
--- a/builder/common/step_key_pair.go
+++ b/builder/common/step_key_pair.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_key_pair_test.go b/builder/common/step_key_pair_test.go
index 02351c31a..1680bc614 100644
--- a/builder/common/step_key_pair_test.go
+++ b/builder/common/step_key_pair_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_modify_ami_attributes.go b/builder/common/step_modify_ami_attributes.go
index 6e662cdce..3304d96ee 100644
--- a/builder/common/step_modify_ami_attributes.go
+++ b/builder/common/step_modify_ami_attributes.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_modify_ebs_instance.go b/builder/common/step_modify_ebs_instance.go
index d58196d9e..a8222d6ff 100644
--- a/builder/common/step_modify_ebs_instance.go
+++ b/builder/common/step_modify_ebs_instance.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_network_info.go b/builder/common/step_network_info.go
index f5b1d9a83..1c0b4649e 100644
--- a/builder/common/step_network_info.go
+++ b/builder/common/step_network_info.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
@@ -9,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
+ "github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
confighelper "github.com/hashicorp/packer-plugin-sdk/template/config"
@@ -31,6 +35,10 @@ type StepNetworkInfo struct {
AvailabilityZone string
SecurityGroupIds []string
SecurityGroupFilter SecurityGroupFilterOptions
+ // RequestedMachineType is the machine type of the instance we want to create.
+ // This is used for selecting a subnet/AZ which supports the type of instance
+ // selected, and not just the most available / random one.
+ RequestedMachineType string
}
type subnetsSort []*ec2.Subnet
@@ -49,7 +57,7 @@ func mostFreeSubnet(subnets []*ec2.Subnet) *ec2.Subnet {
}
func (s *StepNetworkInfo) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
- ec2conn := state.Get("ec2").(*ec2.EC2)
+ ec2conn := state.Get("ec2").(ec2iface.EC2API)
ui := state.Get("ui").(packersdk.Ui)
// Set VpcID if none was specified but filters are defined in the template.
@@ -145,64 +153,12 @@ func (s *StepNetworkInfo) Run(ctx context.Context, state multistep.StateBag) mul
// Set VPC/Subnet if we explicitely enable or disable public IP assignment to the instance
// and we did not set or get a subnet ID before
if s.AssociatePublicIpAddress != confighelper.TriUnset && s.SubnetId == "" {
- ui.Say(fmt.Sprintf("Setting public IP address to %t on instance without a subnet ID",
- *s.AssociatePublicIpAddress.ToBoolPointer()))
-
- if s.VpcId == "" {
- ui.Say("No VPC ID provided, Packer will use the default VPC")
- vpcs, err := ec2conn.DescribeVpcs(&ec2.DescribeVpcsInput{
- Filters: []*ec2.Filter{
- {
- Name: aws.String("is-default"),
- Values: []*string{aws.String("true")},
- },
- },
- })
- if err != nil {
- err := fmt.Errorf("Failed to describe VPCs: %s", err)
- state.Put("error", err)
- ui.Error(err.Error())
- return multistep.ActionHalt
- }
-
- if len(vpcs.Vpcs) != 1 {
- err := fmt.Errorf("No default VPC found")
- state.Put("error", err)
- ui.Error(err.Error())
- return multistep.ActionHalt
- }
- defaultVPC := vpcs.Vpcs[0]
-
- s.VpcId = *defaultVPC.VpcId
- }
-
- var err error
-
- ui.Say(fmt.Sprintf("Inferring subnet from the selected VPC %q", s.VpcId))
- params := &ec2.DescribeSubnetsInput{}
- filters := map[string]string{
- "vpc-id": s.VpcId,
- "state": "available",
- }
- params.Filters, err = buildEc2Filters(filters)
+ err := s.GetDefaultVPCAndSubnet(ui, ec2conn, state)
if err != nil {
- err := fmt.Errorf("Failed to prepare subnet filters: %s", err)
- state.Put("error", err)
- ui.Error(err.Error())
- return multistep.ActionHalt
+ ui.Say("associate_public_ip_address is set without a subnet_id.")
+ ui.Say(fmt.Sprintf("Packer attempted to infer a subnet from default VPC (if unspecified), but failed due to: %s", err))
+ ui.Say("The associate_public_ip_address will be ignored for the remainder of the build, and a public IP will only be associated if the VPC chosen enables it by default.")
}
- subnets, err := ec2conn.DescribeSubnets(params)
- if err != nil {
- err := fmt.Errorf("Failed to describe subnets: %s", err)
- state.Put("error", err)
- ui.Error(err.Error())
- return multistep.ActionHalt
- }
-
- subnet := mostFreeSubnet(subnets.Subnets)
- s.SubnetId = *subnet.SubnetId
-
- ui.Say(fmt.Sprintf("Set subnet as %q", s.SubnetId))
}
// Try to find AZ and VPC Id from Subnet if they are not yet found/given
@@ -231,4 +187,142 @@ func (s *StepNetworkInfo) Run(ctx context.Context, state multistep.StateBag) mul
return multistep.ActionContinue
}
+func (s *StepNetworkInfo) GetDefaultVPCAndSubnet(ui packersdk.Ui, ec2conn ec2iface.EC2API, state multistep.StateBag) error {
+ ui.Say(fmt.Sprintf("Setting public IP address to %t on instance without a subnet ID",
+ *s.AssociatePublicIpAddress.ToBoolPointer()))
+
+ var vpc = s.VpcId
+ if vpc == "" {
+ ui.Say("No VPC ID provided, Packer will use the default VPC")
+ vpcs, err := ec2conn.DescribeVpcs(&ec2.DescribeVpcsInput{
+ Filters: []*ec2.Filter{
+ {
+ Name: aws.String("is-default"),
+ Values: []*string{aws.String("true")},
+ },
+ },
+ })
+ if err != nil {
+ return fmt.Errorf("Failed to describe VPCs: %s", err)
+ }
+
+ if len(vpcs.Vpcs) != 1 {
+ return fmt.Errorf("No default VPC found")
+ }
+ vpc = *vpcs.Vpcs[0].VpcId
+ }
+
+ var err error
+
+ ui.Say(fmt.Sprintf("Inferring subnet from the selected VPC %q", vpc))
+ params := &ec2.DescribeSubnetsInput{}
+ filters := map[string]string{
+ "vpc-id": vpc,
+ "state": "available",
+ }
+ params.Filters, err = buildEc2Filters(filters)
+ if err != nil {
+ return fmt.Errorf("Failed to prepare subnet filters: %s", err)
+ }
+ subnetOut, err := ec2conn.DescribeSubnets(params)
+ if err != nil {
+ return fmt.Errorf("Failed to describe subnets: %s", err)
+ }
+
+ subnets := subnetOut.Subnets
+
+ // Filter by AZ with support for machine type
+ azs := getAZFromSubnets(subnets)
+ azs, err = filterAZByMachineType(azs, s.RequestedMachineType, ec2conn)
+ if err == nil {
+ subnets = filterSubnetsByAZ(subnets, azs)
+ if subnets == nil {
+ return fmt.Errorf("Failed to get subnets for the filtered AZs")
+ }
+ } else {
+ ui.Say(fmt.Sprintf(
+ "Failed to filter subnets/AZ for the requested machine type %q: %s",
+ s.RequestedMachineType, err))
+ ui.Say("This may result in Packer picking a subnet/AZ that can't host the requested machine type")
+ ui.Say("Please check that you have the permissions required to run DescribeInstanceTypeOfferings and try again.")
+ }
+
+ subnet := mostFreeSubnet(subnets)
+
+ s.SubnetId = *subnet.SubnetId
+ s.VpcId = vpc
+ s.AvailabilityZone = *subnet.AvailabilityZone
+
+ ui.Say(fmt.Sprintf("Set subnet as %q", s.SubnetId))
+
+ return nil
+}
+
+func getAZFromSubnets(subnets []*ec2.Subnet) []string {
+ azs := map[string]struct{}{}
+ for _, sub := range subnets {
+ azs[*sub.AvailabilityZone] = struct{}{}
+ }
+
+ retAZ := make([]string, 0, len(azs))
+ for az := range azs {
+ retAZ = append(retAZ, az)
+ }
+
+ return retAZ
+}
+
+func filterAZByMachineType(azs []string, machineType string, ec2conn ec2iface.EC2API) ([]string, error) {
+ var retAZ []string
+
+ for _, az := range azs {
+ resp, err := ec2conn.DescribeInstanceTypeOfferings(&ec2.DescribeInstanceTypeOfferingsInput{
+ LocationType: aws.String("availability-zone"),
+ Filters: []*ec2.Filter{
+ {
+ Name: aws.String("location"),
+ Values: []*string{&az},
+ },
+ {
+ Name: aws.String("instance-type"),
+ Values: []*string{&machineType},
+ },
+ },
+ })
+ if err != nil {
+ err = fmt.Errorf("failed to get offerings for AZ %q: %s", az, err)
+ return nil, err
+ }
+
+ for _, off := range resp.InstanceTypeOfferings {
+ if *off.InstanceType == machineType {
+ retAZ = append(retAZ, az)
+ break
+ }
+ }
+ }
+
+ if retAZ == nil {
+ return nil, fmt.Errorf("no AZ match the requested machine type %q", machineType)
+ }
+
+ return retAZ, nil
+}
+
+func filterSubnetsByAZ(subnets []*ec2.Subnet, azs []string) []*ec2.Subnet {
+ var retSubs []*ec2.Subnet
+
+outLoop:
+ for _, sub := range subnets {
+ for _, az := range azs {
+ if *sub.AvailabilityZone == az {
+ retSubs = append(retSubs, sub)
+ continue outLoop
+ }
+ }
+ }
+
+ return retSubs
+}
+
func (s *StepNetworkInfo) Cleanup(multistep.StateBag) {}
diff --git a/builder/common/step_network_info_test.go b/builder/common/step_network_info_test.go
new file mode 100644
index 000000000..5dcc17d16
--- /dev/null
+++ b/builder/common/step_network_info_test.go
@@ -0,0 +1,573 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
+package common
+
+import (
+ "context"
+ "fmt"
+ "strings"
+ "testing"
+
+ "github.com/aws/aws-sdk-go/aws"
+ "github.com/aws/aws-sdk-go/service/ec2"
+ "github.com/aws/aws-sdk-go/service/ec2/ec2iface"
+ "github.com/google/go-cmp/cmp"
+ "github.com/hashicorp/packer-plugin-sdk/multistep"
+ packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
+ confighelper "github.com/hashicorp/packer-plugin-sdk/template/config"
+)
+
+type mockEC2ClientStepNetworkTests struct {
+ ec2iface.EC2API
+
+ describeInstanceTypeOfferings func(in *ec2.DescribeInstanceTypeOfferingsInput) (*ec2.DescribeInstanceTypeOfferingsOutput, error)
+ describeVpcs func(*ec2.DescribeVpcsInput) (*ec2.DescribeVpcsOutput, error)
+ describeSubnets func(*ec2.DescribeSubnetsInput) (*ec2.DescribeSubnetsOutput, error)
+}
+
+func (m *mockEC2ClientStepNetworkTests) DescribeInstanceTypeOfferings(in *ec2.DescribeInstanceTypeOfferingsInput) (*ec2.DescribeInstanceTypeOfferingsOutput, error) {
+ if m.describeInstanceTypeOfferings != nil {
+ return m.describeInstanceTypeOfferings(in)
+ }
+
+ return nil, fmt.Errorf("unimplemented: describeInstanceTypeOfferings")
+}
+
+func (m *mockEC2ClientStepNetworkTests) DescribeVpcs(in *ec2.DescribeVpcsInput) (*ec2.DescribeVpcsOutput, error) {
+ if m.describeVpcs != nil {
+ return m.describeVpcs(in)
+ }
+
+ return nil, fmt.Errorf("unimplemented: describeVpcs")
+}
+
+func (m *mockEC2ClientStepNetworkTests) DescribeSubnets(in *ec2.DescribeSubnetsInput) (*ec2.DescribeSubnetsOutput, error) {
+ if m.describeSubnets != nil {
+ return m.describeSubnets(in)
+ }
+
+ return nil, fmt.Errorf("unimplemented: describeSubnets")
+}
+
+func TestStepNetwork_GetFilterAZByMachineType(t *testing.T) {
+ testcases := []struct {
+ name string
+ describeImpl func(in *ec2.DescribeInstanceTypeOfferingsInput) (*ec2.DescribeInstanceTypeOfferingsOutput, error)
+ machineType string
+ inputAZs []string
+ expectedAZs []string
+ expectError bool
+ }{
+ {
+ name: "Fail: describe returns an error",
+ describeImpl: func(in *ec2.DescribeInstanceTypeOfferingsInput) (*ec2.DescribeInstanceTypeOfferingsOutput, error) {
+ return nil, fmt.Errorf("STOP")
+ },
+ machineType: "t2.micro",
+ inputAZs: []string{"us-east-1a", "us-east-1b"},
+ expectedAZs: nil,
+ expectError: true,
+ },
+ {
+ name: "Fail, no AZ match machine type",
+ describeImpl: func(in *ec2.DescribeInstanceTypeOfferingsInput) (*ec2.DescribeInstanceTypeOfferingsOutput, error) {
+ return &ec2.DescribeInstanceTypeOfferingsOutput{
+ InstanceTypeOfferings: []*ec2.InstanceTypeOffering{
+ {
+ InstanceType: aws.String("t3.mini"),
+ },
+ {
+ InstanceType: aws.String("t2.mini"),
+ },
+ },
+ }, nil
+ },
+ machineType: "t2.micro",
+ inputAZs: []string{"us-east-1b", "us-east-1c"},
+ expectedAZs: nil,
+ expectError: true,
+ },
+ {
+ name: "OK, found at least one AZ matching machine type",
+ describeImpl: func(in *ec2.DescribeInstanceTypeOfferingsInput) (*ec2.DescribeInstanceTypeOfferingsOutput, error) {
+ return &ec2.DescribeInstanceTypeOfferingsOutput{
+ InstanceTypeOfferings: []*ec2.InstanceTypeOffering{
+ {
+ InstanceType: aws.String("t2.micro"),
+ },
+ },
+ }, nil
+ },
+ machineType: "t2.micro",
+ inputAZs: []string{"us-east-1a", "us-east-1b"},
+ expectedAZs: []string{"us-east-1a", "us-east-1b"},
+ expectError: false,
+ },
+ }
+
+ for _, tt := range testcases {
+ t.Run(tt.name, func(t *testing.T) {
+ conn := &mockEC2ClientStepNetworkTests{}
+ conn.describeInstanceTypeOfferings = tt.describeImpl
+
+ retAZ, err := filterAZByMachineType(tt.inputAZs, tt.machineType, conn)
+
+ diff := cmp.Diff(retAZ, tt.expectedAZs)
+ if diff != "" {
+ t.Errorf("AZ mismatch between computed and expected: %s", diff)
+ }
+
+ if (err != nil) != tt.expectError {
+ t.Errorf("Error mismatch, got %t, expected %t", err != nil, tt.expectError)
+ }
+
+ if err != nil {
+ t.Logf("Got an error: %s", err)
+ }
+ })
+ }
+}
+
+func TestStepNetwork_FilterSubnetsByAZ(t *testing.T) {
+ testcases := []struct {
+ name string
+ inSubnets []*ec2.Subnet
+ azs []string
+ outSubnets []*ec2.Subnet
+ }{
+ {
+ name: "No subnet matching",
+ inSubnets: []*ec2.Subnet{
+ {
+ AvailabilityZone: aws.String("us-east-1-c"),
+ },
+ },
+ azs: []string{"us-east-1a"},
+ outSubnets: nil,
+ },
+ {
+ name: "Found subnet matching",
+ inSubnets: []*ec2.Subnet{
+ {
+ SubnetId: aws.String("subnet1"),
+ AvailabilityZone: aws.String("us-east-1c"),
+ },
+ {
+ SubnetId: aws.String("subnet2"),
+ AvailabilityZone: aws.String("us-east-1b"),
+ },
+ },
+ azs: []string{"us-east-1c"},
+ outSubnets: []*ec2.Subnet{
+ {
+ SubnetId: aws.String("subnet1"),
+ AvailabilityZone: aws.String("us-east-1c"),
+ },
+ },
+ },
+ {
+ name: "Found multiple subnets matching",
+ inSubnets: []*ec2.Subnet{
+ {
+ SubnetId: aws.String("subnet1"),
+ AvailabilityZone: aws.String("us-east-1c"),
+ },
+ {
+ SubnetId: aws.String("subnet2"),
+ AvailabilityZone: aws.String("us-east-1c"),
+ },
+ },
+ azs: []string{"us-east-1c"},
+ outSubnets: []*ec2.Subnet{
+ {
+ SubnetId: aws.String("subnet1"),
+ AvailabilityZone: aws.String("us-east-1c"),
+ },
+ {
+ SubnetId: aws.String("subnet2"),
+ AvailabilityZone: aws.String("us-east-1c"),
+ },
+ },
+ },
+ }
+
+ for _, tt := range testcases {
+ t.Run(tt.name, func(t *testing.T) {
+ subnets := filterSubnetsByAZ(tt.inSubnets, tt.azs)
+ diff := cmp.Diff(subnets, tt.outSubnets)
+ if diff != "" {
+ t.Errorf("subnet mismatch between computed and expected: %s", diff)
+ }
+ })
+ }
+}
+
+func TestStepNetwork_WithPublicIPSetAndNoVPCOrSubnet(t *testing.T) {
+ mockConn := &mockEC2ClientStepNetworkTests{
+ describeVpcs: func(dvi *ec2.DescribeVpcsInput) (*ec2.DescribeVpcsOutput, error) {
+ ok := false
+ for _, filter := range dvi.Filters {
+ if *filter.Name == "is-default" {
+ ok = true
+ break
+ }
+ }
+
+ if !ok {
+ return nil, fmt.Errorf("expected to filter on default VPC = true, did not find that filter")
+ }
+
+ return &ec2.DescribeVpcsOutput{
+ Vpcs: []*ec2.Vpc{
+ {
+ VpcId: aws.String("default-vpc"),
+ },
+ },
+ }, nil
+ },
+ describeSubnets: func(dsi *ec2.DescribeSubnetsInput) (*ec2.DescribeSubnetsOutput, error) {
+ if dsi.SubnetIds != nil {
+ sub := dsi.SubnetIds[0]
+ if *sub != "subnet1" {
+ return nil, fmt.Errorf("expected selected subnet to be us-east-1a, but was %q", *sub)
+ }
+
+ return &ec2.DescribeSubnetsOutput{
+ Subnets: []*ec2.Subnet{
+ {
+ SubnetId: aws.String("subnet1"),
+ AvailabilityZone: aws.String("us-east-1a"),
+ VpcId: aws.String("default-vpc"),
+ },
+ },
+ }, nil
+ }
+
+ vpcFilterFound := false
+ for _, filter := range dsi.Filters {
+ if *filter.Name != "vpc-id" {
+ continue
+ }
+ filterVal := *filter.Values[0]
+ if filterVal != "default-vpc" {
+ return nil, fmt.Errorf("expected vpc-id filter to be %q, got %q", "default-vpc", filterVal)
+ }
+
+ vpcFilterFound = true
+ }
+
+ if !vpcFilterFound {
+ return nil, fmt.Errorf("expected to find vpc-id filter, but did not find it")
+ }
+
+ return &ec2.DescribeSubnetsOutput{
+ Subnets: []*ec2.Subnet{
+ {
+ AvailabilityZone: aws.String("us-east-1a"),
+ SubnetId: aws.String("subnet1"),
+ AvailableIpAddressCount: aws.Int64(256),
+ },
+ {
+ AvailabilityZone: aws.String("us-east-1b"),
+ SubnetId: aws.String("subnet2"),
+ AvailableIpAddressCount: aws.Int64(512),
+ },
+ },
+ }, nil
+ },
+ describeInstanceTypeOfferings: func(in *ec2.DescribeInstanceTypeOfferingsInput) (*ec2.DescribeInstanceTypeOfferingsOutput, error) {
+ if *in.LocationType != "availability-zone" {
+ return nil, fmt.Errorf("called DescribeInstanceTypeOfferings with LocationType = %q, expected availability_zone", *in.LocationType)
+ }
+
+ var machines []*ec2.InstanceTypeOffering
+
+ foundLocation := false
+ for _, filter := range in.Filters {
+ if *filter.Name != "location" {
+ continue
+ }
+ foundLocation = true
+
+ filterVal := *filter.Values[0]
+ switch filterVal {
+ case "us-east-1a":
+ machines = []*ec2.InstanceTypeOffering{
+ {
+ InstanceType: aws.String("t2.mini"),
+ },
+ {
+ InstanceType: aws.String("t3.large"),
+ },
+ }
+ case "us-east-1b":
+ machines = []*ec2.InstanceTypeOffering{
+ {
+ InstanceType: aws.String("t2.mini"),
+ },
+ {
+ InstanceType: aws.String("t2.micro"),
+ },
+ }
+ default:
+ return nil, fmt.Errorf("error: location %q not expected", filterVal)
+ }
+ }
+
+ if !foundLocation {
+ return nil, fmt.Errorf("couldn't find location in filters")
+ }
+
+ return &ec2.DescribeInstanceTypeOfferingsOutput{
+ InstanceTypeOfferings: machines,
+ }, nil
+ },
+ }
+
+ stepConfig := &StepNetworkInfo{
+ AssociatePublicIpAddress: confighelper.TriTrue,
+ RequestedMachineType: "t3.large",
+ }
+
+ state := &multistep.BasicStateBag{}
+ state.Put("ec2", mockConn)
+ state.Put("ui", &packersdk.MockUi{})
+
+ actRet := stepConfig.Run(context.Background(), state)
+ if actRet == multistep.ActionHalt {
+ t.Fatalf("running the step failed: %s", state.Get("error").(error))
+ }
+
+ vpcid, ok := state.GetOk("vpc_id")
+ if !ok || vpcid != "default-vpc" {
+ t.Errorf("error: vpc should be 'default-vpc', but is %q", vpcid)
+ }
+ t.Logf("set vpc is %q", vpcid)
+
+ subnetid, ok := state.GetOk("subnet_id")
+ if !ok || subnetid != "subnet1" {
+ t.Errorf("error: subnet should be 'subnet1', but is %q", subnetid)
+ }
+ t.Logf("set subnet is %q", subnetid)
+
+ az, ok := state.GetOk("availability_zone")
+ if !ok || az != "us-east-1a" {
+ t.Errorf("error: availability_zone should be 'us-east-1a', but is %q", az)
+ }
+ t.Logf("set AZ is %q", az)
+}
+
+func TestStepNetwork_GetDefaultVPCFailDueToPermissions(t *testing.T) {
+ mockConn := &mockEC2ClientStepNetworkTests{
+ describeVpcs: func(dvi *ec2.DescribeVpcsInput) (*ec2.DescribeVpcsOutput, error) {
+ return nil, fmt.Errorf("Insufficient permissions: missing ec2:DescribeVpcs")
+ },
+ }
+
+ stepConfig := &StepNetworkInfo{
+ AssociatePublicIpAddress: confighelper.TriTrue,
+ RequestedMachineType: "t3.large",
+ }
+
+ ui := &packersdk.MockUi{}
+
+ state := &multistep.BasicStateBag{}
+ state.Put("ec2", mockConn)
+ state.Put("ui", ui)
+
+ actRet := stepConfig.Run(context.Background(), state)
+ if actRet == multistep.ActionHalt {
+ t.Fatalf("running the step failed: %s", state.Get("error").(error))
+ }
+
+ vpcid, ok := state.GetOk("vpc_id")
+ if !ok || vpcid != "" {
+ t.Errorf("error: vpc should be empty, but is %q", vpcid)
+ }
+
+ subnetid, ok := state.GetOk("subnet_id")
+ if !ok || subnetid != "" {
+ t.Errorf("error: subnet should be empty, but is %q", subnetid)
+ }
+
+ az, ok := state.GetOk("availability_zone")
+ if !ok || az != "" {
+ t.Errorf("error: availability_zone should be empty, but is %q", az)
+ }
+
+ var foundMsg bool
+
+ for _, msg := range ui.SayMessages {
+ if msg.Message == "associate_public_ip_address is set without a subnet_id." {
+ t.Log("found warning on associate_public_ip_address")
+ foundMsg = true
+ }
+ }
+
+ if !foundMsg {
+ t.Errorf("failed to find a message that states that associate_public_ip_address will be ignored.")
+ }
+}
+
+func TestStepNetwork_SetVPCAndSubnetWithoutAssociatePublicIP(t *testing.T) {
+ mockConn := &mockEC2ClientStepNetworkTests{}
+
+ stepConfig := &StepNetworkInfo{
+ AssociatePublicIpAddress: confighelper.TriUnset,
+ RequestedMachineType: "t3.large",
+ VpcId: "default-vpc",
+ SubnetId: "subnet1",
+ AvailabilityZone: "us-east-1a",
+ }
+
+ ui := &packersdk.MockUi{}
+
+ state := &multistep.BasicStateBag{}
+ state.Put("ec2", mockConn)
+ state.Put("ui", ui)
+
+ actRet := stepConfig.Run(context.Background(), state)
+ if actRet == multistep.ActionHalt {
+ t.Fatalf("running the step failed: %s", state.Get("error").(error))
+ }
+
+ vpcid, ok := state.GetOk("vpc_id")
+ if !ok || vpcid != "default-vpc" {
+ t.Errorf("error: vpc should be 'default-vpc', but is %q", vpcid)
+ }
+
+ subnetid, ok := state.GetOk("subnet_id")
+ if !ok || subnetid != "subnet1" {
+ t.Errorf("error: subnet should be 'subnet_id', but is %q", subnetid)
+ }
+
+ az, ok := state.GetOk("availability_zone")
+ if !ok || az != "us-east-1a" {
+ t.Errorf("error: availability_zone should be 'us-east-1a', but is %q", az)
+ }
+
+ var foundDefaultVPCMsg bool
+ for _, msg := range ui.SayMessages {
+ if strings.Contains(msg.Message, "Setting public IP address to") {
+ foundDefaultVPCMsg = true
+ }
+ }
+
+ if foundDefaultVPCMsg {
+ t.Errorf("Should not have found a message that stated that we need to process public IP address setting")
+ }
+}
+
+func TestStepNetwork_SetPublicIPAddressWithoutSubnetAndMissingDescribeInstanceTypeOfferings(t *testing.T) {
+ mockConn := &mockEC2ClientStepNetworkTests{
+ describeVpcs: func(dvi *ec2.DescribeVpcsInput) (*ec2.DescribeVpcsOutput, error) {
+ ok := false
+ for _, filter := range dvi.Filters {
+ if *filter.Name == "is-default" {
+ ok = true
+ break
+ }
+ }
+
+ if !ok {
+ return nil, fmt.Errorf("expected to filter on default VPC = true, did not find that filter")
+ }
+
+ return &ec2.DescribeVpcsOutput{
+ Vpcs: []*ec2.Vpc{
+ {
+ VpcId: aws.String("default-vpc"),
+ },
+ },
+ }, nil
+ },
+ describeSubnets: func(dsi *ec2.DescribeSubnetsInput) (*ec2.DescribeSubnetsOutput, error) {
+ if dsi.SubnetIds != nil {
+ sub := dsi.SubnetIds[0]
+ if *sub != "subnet1" {
+ return nil, fmt.Errorf("expected selected subnet to be us-east-1a, but was %q", *sub)
+ }
+
+ return &ec2.DescribeSubnetsOutput{
+ Subnets: []*ec2.Subnet{
+ {
+ SubnetId: aws.String("subnet1"),
+ AvailabilityZone: aws.String("us-east-1a"),
+ VpcId: aws.String("default-vpc"),
+ },
+ },
+ }, nil
+ }
+
+ vpcFilterFound := false
+ for _, filter := range dsi.Filters {
+ if *filter.Name != "vpc-id" {
+ continue
+ }
+ filterVal := *filter.Values[0]
+ if filterVal != "default-vpc" {
+ return nil, fmt.Errorf("expected vpc-id filter to be %q, got %q", "default-vpc", filterVal)
+ }
+
+ vpcFilterFound = true
+ }
+
+ if !vpcFilterFound {
+ return nil, fmt.Errorf("expected to find vpc-id filter, but did not find it")
+ }
+
+ return &ec2.DescribeSubnetsOutput{
+ Subnets: []*ec2.Subnet{
+ {
+ AvailabilityZone: aws.String("us-east-1a"),
+ SubnetId: aws.String("subnet1"),
+ AvailableIpAddressCount: aws.Int64(256),
+ },
+ {
+ AvailabilityZone: aws.String("us-east-1b"),
+ SubnetId: aws.String("subnet2"),
+ AvailableIpAddressCount: aws.Int64(512),
+ },
+ },
+ }, nil
+ },
+ describeInstanceTypeOfferings: func(in *ec2.DescribeInstanceTypeOfferingsInput) (*ec2.DescribeInstanceTypeOfferingsOutput, error) {
+ return nil, fmt.Errorf("Missing permission: ec2:DescribeInstanceTypeOfferings")
+ },
+ }
+
+ stepConfig := &StepNetworkInfo{
+ AssociatePublicIpAddress: confighelper.TriTrue,
+ RequestedMachineType: "t3.large",
+ }
+
+ ui := &packersdk.MockUi{}
+
+ state := &multistep.BasicStateBag{}
+ state.Put("ec2", mockConn)
+ state.Put("ui", ui)
+
+ actRet := stepConfig.Run(context.Background(), state)
+ if actRet == multistep.ActionHalt {
+ t.Fatalf("running the step failed: %s", state.Get("error").(error))
+ }
+
+ vpcid, ok := state.GetOk("vpc_id")
+ if !ok || vpcid != "default-vpc" {
+ t.Errorf("error: vpc should be 'default-vpc', but is %q", vpcid)
+ }
+ t.Logf("set vpc is %q", vpcid)
+
+ subnetid, ok := state.GetOk("subnet_id")
+ if !ok || subnetid != "subnet2" {
+ t.Errorf("error: subnet should be 'subnet2', but is %q", subnetid)
+ }
+ t.Logf("set subnet is %q", subnetid)
+
+ az, ok := state.GetOk("availability_zone")
+ if !ok || az != "us-east-1b" {
+ t.Errorf("error: availability_zone should be 'us-east-1a', but is %q", az)
+ }
+ t.Logf("set AZ is %q", az)
+}
diff --git a/builder/common/step_pre_validate.go b/builder/common/step_pre_validate.go
index a8a18089c..ad96b07a5 100644
--- a/builder/common/step_pre_validate.go
+++ b/builder/common/step_pre_validate.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
@@ -17,7 +20,6 @@ import (
// StepPreValidate provides an opportunity to pre-validate any configuration for
// the build before actually doing any time consuming work
-//
type StepPreValidate struct {
DestAmiName string
ForceDeregister bool
@@ -99,6 +101,7 @@ func (s *StepPreValidate) Run(ctx context.Context, state multistep.StateBag) mul
ui.Say(fmt.Sprintf("Prevalidating AMI Name: %s", s.DestAmiName))
req, resp := ec2conn.DescribeImagesRequest(&ec2.DescribeImagesInput{
+ Owners: []*string{aws.String("self")},
Filters: []*ec2.Filter{{
Name: aws.String("name"),
Values: []*string{aws.String(s.DestAmiName)},
diff --git a/builder/common/step_pre_validate_test.go b/builder/common/step_pre_validate_test.go
index ffaf946f9..f6e9a9b4e 100644
--- a/builder/common/step_pre_validate_test.go
+++ b/builder/common/step_pre_validate_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_run_source_instance.go b/builder/common/step_run_source_instance.go
index d4f90070d..4ca24e42f 100644
--- a/builder/common/step_run_source_instance.go
+++ b/builder/common/step_run_source_instance.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_run_spot_instance.go b/builder/common/step_run_spot_instance.go
index 7e8352978..f76092ef9 100644
--- a/builder/common/step_run_spot_instance.go
+++ b/builder/common/step_run_spot_instance.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_run_spot_instance_test.go b/builder/common/step_run_spot_instance_test.go
index d40fbbc00..11f51e048 100644
--- a/builder/common/step_run_spot_instance_test.go
+++ b/builder/common/step_run_spot_instance_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_security_group.go b/builder/common/step_security_group.go
index 6fcb41a50..7bd28a79e 100644
--- a/builder/common/step_security_group.go
+++ b/builder/common/step_security_group.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_set_generated_data.go b/builder/common/step_set_generated_data.go
index 6a28c18a0..c879ca171 100644
--- a/builder/common/step_set_generated_data.go
+++ b/builder/common/step_set_generated_data.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_source_ami_info.go b/builder/common/step_source_ami_info.go
index 200460ca9..1a9870811 100644
--- a/builder/common/step_source_ami_info.go
+++ b/builder/common/step_source_ami_info.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_source_ami_info_test.go b/builder/common/step_source_ami_info_test.go
index 4941180cd..96259c75f 100644
--- a/builder/common/step_source_ami_info_test.go
+++ b/builder/common/step_source_ami_info_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/step_stop_ebs_instance.go b/builder/common/step_stop_ebs_instance.go
index 1283b4404..b42b1f30f 100644
--- a/builder/common/step_stop_ebs_instance.go
+++ b/builder/common/step_stop_ebs_instance.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/tags.go b/builder/common/tags.go
index 85bbda1be..1c7eaff2d 100644
--- a/builder/common/tags.go
+++ b/builder/common/tags.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/template_funcs.go b/builder/common/template_funcs.go
index 14dd65d83..fcbe00f6e 100644
--- a/builder/common/template_funcs.go
+++ b/builder/common/template_funcs.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/template_funcs_test.go b/builder/common/template_funcs_test.go
index 11ad70aac..414b8864d 100644
--- a/builder/common/template_funcs_test.go
+++ b/builder/common/template_funcs_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/common/test_helper_funcs.go b/builder/common/test_helper_funcs.go
index c951ba855..612f92470 100644
--- a/builder/common/test_helper_funcs.go
+++ b/builder/common/test_helper_funcs.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package common
import (
diff --git a/builder/ebs/acceptance/aws.go b/builder/ebs/acceptance/aws.go
index 022dccfe1..6fc4a1f05 100644
--- a/builder/ebs/acceptance/aws.go
+++ b/builder/ebs/acceptance/aws.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package amazon_acc
import (
diff --git a/builder/ebs/acceptance/utils.go b/builder/ebs/acceptance/utils.go
index 22de14784..9ca3eee48 100644
--- a/builder/ebs/acceptance/utils.go
+++ b/builder/ebs/acceptance/utils.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package amazon_acc
import (
diff --git a/builder/ebs/builder.go b/builder/ebs/builder.go
index 1c5bef3a2..16ffb059e 100644
--- a/builder/ebs/builder.go
+++ b/builder/ebs/builder.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type Config
@@ -83,6 +86,8 @@ type Config struct {
//
// Fast launch is only relevant for Windows AMIs, and should not be used
// for other OSes.
+ // See the [Fast Launch Configuration](#fast-launch-config) section for
+ // information on the attributes supported for this block.
FastLaunch FastLaunchConfig `mapstructure:"fast_launch" required:"false"`
ctx interpolate.Context
@@ -305,6 +310,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
SubnetFilter: b.config.SubnetFilter,
AvailabilityZone: b.config.AvailabilityZone,
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
+ RequestedMachineType: b.config.InstanceType,
},
&awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
diff --git a/builder/ebs/builder_acc_test.go b/builder/ebs/builder_acc_test.go
index a91447339..12cedef62 100644
--- a/builder/ebs/builder_acc_test.go
+++ b/builder/ebs/builder_acc_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
/*
deregister the test image with
aws ec2 deregister-image --image-id $(aws ec2 describe-images --output text --filters "Name=name,Values=packer-test-packer-test-dereg" --query 'Images[*].{ID:ImageId}')
@@ -1283,14 +1286,10 @@ func TestAccBuilder_AssociatePublicIPWithoutSubnet(t *testing.T) {
return fmt.Errorf("did not change the public IP setting for the instance")
}
- if !strings.Contains(string(logs), "No VPC ID provided, Packer will choose one from the provided or default VPC") {
+ if !strings.Contains(string(logs), "No VPC ID provided, Packer will use the default VPC") {
return fmt.Errorf("did not pick the default VPC when setting subnet")
}
- if !strings.Contains(string(logs), "AvailabilityZone found") {
- return fmt.Errorf("did not get AZ from subnet")
- }
-
return nil
},
}
diff --git a/builder/ebs/builder_test.go b/builder/ebs/builder_test.go
index aece800d0..4bf014b30 100644
--- a/builder/ebs/builder_test.go
+++ b/builder/ebs/builder_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebs
import (
diff --git a/builder/ebs/fast_launch_setup.go b/builder/ebs/fast_launch_setup.go
index b934e8adb..59ec56e8c 100644
--- a/builder/ebs/fast_launch_setup.go
+++ b/builder/ebs/fast_launch_setup.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type FastLaunchConfig
diff --git a/builder/ebs/fast_launch_setup_test.go b/builder/ebs/fast_launch_setup_test.go
index 84f86916e..1f2d7a439 100644
--- a/builder/ebs/fast_launch_setup_test.go
+++ b/builder/ebs/fast_launch_setup_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebs
import "testing"
diff --git a/builder/ebs/step_create_ami.go b/builder/ebs/step_create_ami.go
index 760165755..44a599712 100644
--- a/builder/ebs/step_create_ami.go
+++ b/builder/ebs/step_create_ami.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebs
import (
diff --git a/builder/ebs/step_enable_deprecation.go b/builder/ebs/step_enable_deprecation.go
index 6ae89e0de..9b923bba2 100644
--- a/builder/ebs/step_enable_deprecation.go
+++ b/builder/ebs/step_enable_deprecation.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebs
import (
diff --git a/builder/ebs/step_enable_fast_launch.go b/builder/ebs/step_enable_fast_launch.go
index f2c8c8957..d367412b1 100644
--- a/builder/ebs/step_enable_fast_launch.go
+++ b/builder/ebs/step_enable_fast_launch.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebs
import (
diff --git a/builder/ebs/step_prepare_fast_launch_template.go b/builder/ebs/step_prepare_fast_launch_template.go
index 8310429d6..b3d3c2bf5 100644
--- a/builder/ebs/step_prepare_fast_launch_template.go
+++ b/builder/ebs/step_prepare_fast_launch_template.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebs
import (
diff --git a/builder/ebs/tags_acc_test.go b/builder/ebs/tags_acc_test.go
index f023ab24a..c36cafb27 100644
--- a/builder/ebs/tags_acc_test.go
+++ b/builder/ebs/tags_acc_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebs
import (
diff --git a/builder/ebs/test-fixtures/interpolated_run_tags.pkr.hcl b/builder/ebs/test-fixtures/interpolated_run_tags.pkr.hcl
index 0263133c7..f326d76c7 100644
--- a/builder/ebs/test-fixtures/interpolated_run_tags.pkr.hcl
+++ b/builder/ebs/test-fixtures/interpolated_run_tags.pkr.hcl
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
data "amazon-ami" "test" {
filters = {
name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*"
diff --git a/builder/ebs/test-fixtures/ssh-keys/ed25519_ssh_keypair.pkr.hcl b/builder/ebs/test-fixtures/ssh-keys/ed25519_ssh_keypair.pkr.hcl
index 8faefd3ee..be398faf0 100644
--- a/builder/ebs/test-fixtures/ssh-keys/ed25519_ssh_keypair.pkr.hcl
+++ b/builder/ebs/test-fixtures/ssh-keys/ed25519_ssh_keypair.pkr.hcl
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
data "amazon-ami" "test" {
filters = {
name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*"
diff --git a/builder/ebs/test-fixtures/ssh-keys/rsa_sha2_only_server.pkr.hcl b/builder/ebs/test-fixtures/ssh-keys/rsa_sha2_only_server.pkr.hcl
index 58a2a715b..1803072ba 100644
--- a/builder/ebs/test-fixtures/ssh-keys/rsa_sha2_only_server.pkr.hcl
+++ b/builder/ebs/test-fixtures/ssh-keys/rsa_sha2_only_server.pkr.hcl
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
/*
OpenSSH migrated the ssh-rsa key type, which historically used the ssh-rsa
signature algorithm based on SHA-1, to the new rsa-sha2-256 and rsa-sha2-512 signature algorithms.
diff --git a/builder/ebs/test-fixtures/ssh-keys/rsa_ssh_keypair.pkr.hcl b/builder/ebs/test-fixtures/ssh-keys/rsa_ssh_keypair.pkr.hcl
index 3767fa544..14f1e4cd9 100644
--- a/builder/ebs/test-fixtures/ssh-keys/rsa_ssh_keypair.pkr.hcl
+++ b/builder/ebs/test-fixtures/ssh-keys/rsa_ssh_keypair.pkr.hcl
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
data "amazon-ami" "test" {
filters = {
name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*"
diff --git a/builder/ebs/test-fixtures/unlimited-credits/burstable_instances.pkr.hcl b/builder/ebs/test-fixtures/unlimited-credits/burstable_instances.pkr.hcl
index 18984b2bb..a638503bf 100644
--- a/builder/ebs/test-fixtures/unlimited-credits/burstable_instances.pkr.hcl
+++ b/builder/ebs/test-fixtures/unlimited-credits/burstable_instances.pkr.hcl
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
variables {
standardCPUCredit = "standard"
unlimitedCPUCredit = "unlimited"
diff --git a/builder/ebs/test-fixtures/unlimited-credits/burstable_spot_instances.pkr.hcl b/builder/ebs/test-fixtures/unlimited-credits/burstable_spot_instances.pkr.hcl
index f6b92bc4d..d6fb1f8e1 100644
--- a/builder/ebs/test-fixtures/unlimited-credits/burstable_spot_instances.pkr.hcl
+++ b/builder/ebs/test-fixtures/unlimited-credits/burstable_spot_instances.pkr.hcl
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
variables {
standardCPUCredit = "standard"
unlimitedCPUCredit = "unlimited"
diff --git a/builder/ebssurrogate/block_device.go b/builder/ebssurrogate/block_device.go
index 85f290456..bd5aee7d1 100644
--- a/builder/ebssurrogate/block_device.go
+++ b/builder/ebssurrogate/block_device.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
package ebssurrogate
diff --git a/builder/ebssurrogate/builder.go b/builder/ebssurrogate/builder.go
index b0d79353d..384f14c7c 100644
--- a/builder/ebssurrogate/builder.go
+++ b/builder/ebssurrogate/builder.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type Config,RootBlockDevice,BlockDevice
@@ -333,6 +336,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
SubnetFilter: b.config.SubnetFilter,
AvailabilityZone: b.config.AvailabilityZone,
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
+ RequestedMachineType: b.config.InstanceType,
},
&awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
diff --git a/builder/ebssurrogate/builder_acc_test.go b/builder/ebssurrogate/builder_acc_test.go
index 1ae5b18ec..fa547a15d 100644
--- a/builder/ebssurrogate/builder_acc_test.go
+++ b/builder/ebssurrogate/builder_acc_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebssurrogate
import (
diff --git a/builder/ebssurrogate/builder_test.go b/builder/ebssurrogate/builder_test.go
index f063a3163..c3971e65c 100644
--- a/builder/ebssurrogate/builder_test.go
+++ b/builder/ebssurrogate/builder_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebssurrogate
import (
diff --git a/builder/ebssurrogate/root_block_device.go b/builder/ebssurrogate/root_block_device.go
index 997539ccb..0373dfbf1 100644
--- a/builder/ebssurrogate/root_block_device.go
+++ b/builder/ebssurrogate/root_block_device.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
package ebssurrogate
diff --git a/builder/ebssurrogate/step_register_ami.go b/builder/ebssurrogate/step_register_ami.go
index 7f1986a3f..079e4ecc3 100644
--- a/builder/ebssurrogate/step_register_ami.go
+++ b/builder/ebssurrogate/step_register_ami.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebssurrogate
import (
diff --git a/builder/ebssurrogate/step_register_ami_test.go b/builder/ebssurrogate/step_register_ami_test.go
index 2973f3a9e..8de563709 100644
--- a/builder/ebssurrogate/step_register_ami_test.go
+++ b/builder/ebssurrogate/step_register_ami_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebssurrogate
import (
diff --git a/builder/ebssurrogate/step_snapshot_volumes.go b/builder/ebssurrogate/step_snapshot_volumes.go
index fba4ac444..1f907043e 100644
--- a/builder/ebssurrogate/step_snapshot_volumes.go
+++ b/builder/ebssurrogate/step_snapshot_volumes.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebssurrogate
import (
diff --git a/builder/ebsvolume/artifact.go b/builder/ebsvolume/artifact.go
index 3dd1999a3..679770949 100644
--- a/builder/ebsvolume/artifact.go
+++ b/builder/ebsvolume/artifact.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebsvolume
import (
diff --git a/builder/ebsvolume/artifact_test.go b/builder/ebsvolume/artifact_test.go
index fcaa98b3e..a12acf8fe 100644
--- a/builder/ebsvolume/artifact_test.go
+++ b/builder/ebsvolume/artifact_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebsvolume
import (
diff --git a/builder/ebsvolume/block_device.go b/builder/ebsvolume/block_device.go
index d46f40043..38936312f 100644
--- a/builder/ebsvolume/block_device.go
+++ b/builder/ebsvolume/block_device.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
package ebsvolume
diff --git a/builder/ebsvolume/builder.go b/builder/ebsvolume/builder.go
index 47c0a62f6..d583be51c 100644
--- a/builder/ebsvolume/builder.go
+++ b/builder/ebsvolume/builder.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type Config,BlockDevice
@@ -280,6 +283,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
SubnetFilter: b.config.SubnetFilter,
AvailabilityZone: b.config.AvailabilityZone,
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
+ RequestedMachineType: b.config.InstanceType,
},
&awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
diff --git a/builder/ebsvolume/builder_test.go b/builder/ebsvolume/builder_test.go
index 9db0a189b..7350bb9f9 100644
--- a/builder/ebsvolume/builder_test.go
+++ b/builder/ebsvolume/builder_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebsvolume
import (
diff --git a/builder/ebsvolume/step_snapshot_ebs_volumes.go b/builder/ebsvolume/step_snapshot_ebs_volumes.go
index 80810e573..e2a65bc1f 100644
--- a/builder/ebsvolume/step_snapshot_ebs_volumes.go
+++ b/builder/ebsvolume/step_snapshot_ebs_volumes.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebsvolume
import (
diff --git a/builder/ebsvolume/step_snapshot_ebs_volumes_test.go b/builder/ebsvolume/step_snapshot_ebs_volumes_test.go
index 48d414126..fadcb08a7 100644
--- a/builder/ebsvolume/step_snapshot_ebs_volumes_test.go
+++ b/builder/ebsvolume/step_snapshot_ebs_volumes_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebsvolume
import (
diff --git a/builder/ebsvolume/step_tag_ebs_volumes.go b/builder/ebsvolume/step_tag_ebs_volumes.go
index a73f89286..78be062b6 100644
--- a/builder/ebsvolume/step_tag_ebs_volumes.go
+++ b/builder/ebsvolume/step_tag_ebs_volumes.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ebsvolume
import (
diff --git a/builder/examples/apache_server/packages.sh b/builder/examples/apache_server/packages.sh
index 0a6af1d1c..f929c2a94 100644
--- a/builder/examples/apache_server/packages.sh
+++ b/builder/examples/apache_server/packages.sh
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
echo "installing apache "
sudo apt-get update
sudo apt-get install apache2 -y
diff --git a/builder/examples/nginx_server/packages.sh b/builder/examples/nginx_server/packages.sh
index 3f5973ef0..3ffa39676 100644
--- a/builder/examples/nginx_server/packages.sh
+++ b/builder/examples/nginx_server/packages.sh
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
echo "installing nginx "
sudo apt-get update
sudo apt-get install nginx -y
diff --git a/builder/instance/builder.go b/builder/instance/builder.go
index e917bb621..e4276608f 100644
--- a/builder/instance/builder.go
+++ b/builder/instance/builder.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type Config
@@ -350,6 +353,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
SubnetFilter: b.config.SubnetFilter,
AvailabilityZone: b.config.AvailabilityZone,
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
+ RequestedMachineType: b.config.InstanceType,
},
&awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
diff --git a/builder/instance/builder_test.go b/builder/instance/builder_test.go
index 2929f7aa1..705d644b5 100644
--- a/builder/instance/builder_test.go
+++ b/builder/instance/builder_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package instance
import (
diff --git a/builder/instance/step_bundle_volume.go b/builder/instance/step_bundle_volume.go
index efd663f48..a279bd9ba 100644
--- a/builder/instance/step_bundle_volume.go
+++ b/builder/instance/step_bundle_volume.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package instance
import (
diff --git a/builder/instance/step_register_ami.go b/builder/instance/step_register_ami.go
index dfce60607..a838332a1 100644
--- a/builder/instance/step_register_ami.go
+++ b/builder/instance/step_register_ami.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package instance
import (
diff --git a/builder/instance/step_upload_bundle.go b/builder/instance/step_upload_bundle.go
index 24412eb45..e7cec69ac 100644
--- a/builder/instance/step_upload_bundle.go
+++ b/builder/instance/step_upload_bundle.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package instance
import (
diff --git a/builder/instance/step_upload_x509_cert.go b/builder/instance/step_upload_x509_cert.go
index 7937023ce..ea70aa0ad 100644
--- a/builder/instance/step_upload_x509_cert.go
+++ b/builder/instance/step_upload_x509_cert.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package instance
import (
diff --git a/datasource/ami/data.go b/datasource/ami/data.go
index ac15a24cf..18df731f7 100644
--- a/datasource/ami/data.go
+++ b/datasource/ami/data.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type DatasourceOutput,Config
package ami
diff --git a/datasource/ami/data_acc_test.go b/datasource/ami/data_acc_test.go
index c93a588ad..34d15206a 100644
--- a/datasource/ami/data_acc_test.go
+++ b/datasource/ami/data_acc_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ami
import (
diff --git a/datasource/ami/data_test.go b/datasource/ami/data_test.go
index 2c8f47512..5e73ef31c 100644
--- a/datasource/ami/data_test.go
+++ b/datasource/ami/data_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package ami
import (
diff --git a/datasource/ami/test-fixtures/configure-source-ssh.ps1 b/datasource/ami/test-fixtures/configure-source-ssh.ps1
index 7c12dd742..51303ec3e 100644
--- a/datasource/ami/test-fixtures/configure-source-ssh.ps1
+++ b/datasource/ami/test-fixtures/configure-source-ssh.ps1
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
# Version and download URL
$openSSHVersion = "8.1.0.0p1-Beta"
diff --git a/datasource/ami/test-fixtures/template.pkr.hcl b/datasource/ami/test-fixtures/template.pkr.hcl
index 23369bc86..2b7b8e8d7 100644
--- a/datasource/ami/test-fixtures/template.pkr.hcl
+++ b/datasource/ami/test-fixtures/template.pkr.hcl
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
data "amazon-ami" "test" {
filters = {
name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*"
diff --git a/datasource/parameterstore/data.go b/datasource/parameterstore/data.go
index e219b8b81..07a012f80 100644
--- a/datasource/parameterstore/data.go
+++ b/datasource/parameterstore/data.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type DatasourceOutput,Config
diff --git a/datasource/parameterstore/data_acc_test.go b/datasource/parameterstore/data_acc_test.go
index bb08d3412..db9153e8d 100644
--- a/datasource/parameterstore/data_acc_test.go
+++ b/datasource/parameterstore/data_acc_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package parameterstore
import (
diff --git a/datasource/parameterstore/data_test.go b/datasource/parameterstore/data_test.go
index cc5fe1d57..40dcb6be6 100644
--- a/datasource/parameterstore/data_test.go
+++ b/datasource/parameterstore/data_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package parameterstore
import "testing"
diff --git a/datasource/parameterstore/test-fixtures/template.pkr.hcl b/datasource/parameterstore/test-fixtures/template.pkr.hcl
index 47169ce91..e52a7e51d 100644
--- a/datasource/parameterstore/test-fixtures/template.pkr.hcl
+++ b/datasource/parameterstore/test-fixtures/template.pkr.hcl
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
data "amazon-parameterstore" "test" {
name = "packer_datasource_parameterstore_test_parameter"
with_decryption = false
diff --git a/datasource/secretsmanager/data.go b/datasource/secretsmanager/data.go
index 1686b7001..7b499ef1e 100644
--- a/datasource/secretsmanager/data.go
+++ b/datasource/secretsmanager/data.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type DatasourceOutput,Config
package secretsmanager
diff --git a/datasource/secretsmanager/data_acc_test.go b/datasource/secretsmanager/data_acc_test.go
index 477ba119a..bef572e5e 100644
--- a/datasource/secretsmanager/data_acc_test.go
+++ b/datasource/secretsmanager/data_acc_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package secretsmanager
import (
diff --git a/datasource/secretsmanager/data_test.go b/datasource/secretsmanager/data_test.go
index 5802b3b29..7226ca8ce 100644
--- a/datasource/secretsmanager/data_test.go
+++ b/datasource/secretsmanager/data_test.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package secretsmanager
import (
diff --git a/datasource/secretsmanager/test-fixtures/template.pkr.hcl b/datasource/secretsmanager/test-fixtures/template.pkr.hcl
index a5c024ce7..a23ef487b 100644
--- a/datasource/secretsmanager/test-fixtures/template.pkr.hcl
+++ b/datasource/secretsmanager/test-fixtures/template.pkr.hcl
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
data "amazon-secretsmanager" "test" {
name = "packer_datasource_secretsmanager_test_secret"
key = "packer_test_key"
diff --git a/docs-partials/builder/common/RunConfig-not-required.mdx b/docs-partials/builder/common/RunConfig-not-required.mdx
index 0689ddadc..2bdcb42fa 100644
--- a/docs-partials/builder/common/RunConfig-not-required.mdx
+++ b/docs-partials/builder/common/RunConfig-not-required.mdx
@@ -3,6 +3,21 @@
- `associate_public_ip_address` (confighelper.Trilean) - If using a non-default VPC,
public IP addresses are not provided by default. If this is true, your
new instance will get a Public IP. default: unset
+
+ Note: when specifying this attribute without a `subnet_[id|filter]` or
+ `vpc_[id|filter]`, we will attempt to infer this information from the
+ default VPC/Subnet.
+ This operation may require some extra permissions to the IAM role that
+ runs the build:
+
+ * ec2:DescribeVpcs
+ * ec2:DescribeSubnets
+
+ Additionally, since we filter subnets/AZs by their capability to host
+ an instance of the selected type, you may also want to define the
+ `ec2:DescribeInstanceTypeOfferings` action to the role running the build.
+ Otherwise, Packer will pick the most available subnet in the VPC selected,
+ which may not be able to host the instance type you provided.
- `availability_zone` (string) - Destination availability zone to launch
instance in. Leave this empty to allow Amazon to auto-assign.
diff --git a/docs-partials/builder/ebs/Config-not-required.mdx b/docs-partials/builder/ebs/Config-not-required.mdx
index b6428a7c6..fc309d2f6 100644
--- a/docs-partials/builder/ebs/Config-not-required.mdx
+++ b/docs-partials/builder/ebs/Config-not-required.mdx
@@ -48,5 +48,7 @@
Fast launch is only relevant for Windows AMIs, and should not be used
for other OSes.
+ See the [Fast Launch Configuration](#fast-launch-config) section for
+ information on the attributes supported for this block.
diff --git a/docs-partials/builder/ebs/FastLaunchConfig-not-required.mdx b/docs-partials/builder/ebs/FastLaunchConfig-not-required.mdx
index d081a2e2d..4086e66e0 100644
--- a/docs-partials/builder/ebs/FastLaunchConfig-not-required.mdx
+++ b/docs-partials/builder/ebs/FastLaunchConfig-not-required.mdx
@@ -1,14 +1,20 @@
-- `enable_fast_launch` (bool) - Configure AMI with fast-launch on Windows AMIs
+- `enable_fast_launch` (bool) - Configure fast-launch for Windows AMIs
- `template_id` (string) - The ID of the launch template to use for the fast launch
This cannot be specified in conjunction with the template name.
+
+ If no template is specified, the default launch template will be used,
+ as specified in the AWS docs.
- `template_name` (string) - The name of the launch template to use for fast launch
This cannot be specified in conjunction with the template ID.
+
+ If no template is specified, the default launch template will be used,
+ as specified in the AWS docs.
- `template_version` (int) - The version of the launch template to use
diff --git a/docs/builders/ebs.mdx b/docs/builders/ebs.mdx
index 2289239eb..8282ac02e 100644
--- a/docs/builders/ebs.mdx
+++ b/docs/builders/ebs.mdx
@@ -265,6 +265,14 @@ Linux](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html)
or [for
Windows](http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/finding-an-ami.html).
+### Fast Launch Config
+
+@include 'builder/ebs/FastLaunchConfig.mdx'
+
+#### Optional
+
+@include 'builder/ebs/FastLaunchConfig-not-required.mdx'
+
## Accessing the Instance to Debug
If you need to access the instance to debug for some reason, run the builder
diff --git a/docs/builders/index.mdx b/docs/builders/index.mdx
index aa7a6f10c..d54d38fcb 100644
--- a/docs/builders/index.mdx
+++ b/docs/builders/index.mdx
@@ -47,7 +47,7 @@ Then, run [`packer init`](/packer/docs/commands/init).
packer {
required_plugins {
amazon = {
- version = ">= 1.2.4"
+ version = ">= 1.2.5"
source = "github.com/hashicorp/amazon"
}
}
@@ -295,6 +295,16 @@ If you are using the `vpc_filter` option, you must also add:
ec2:DescribeVpcs
+This permission may also be needed by the `associate_public_ip_address` option, if specified without a subnet.
+In this case the plugin will invoke `DescribeVpcs` to find information about the default VPC.
+
+When using `associate_public_ip_address` without a subnet, you will also benefit from having:
+
+ ec2:DescribeInstanceTypeOfferings
+
+This will ensure that the plugin will pick a subnet/AZ that can host the type of instance
+you're requesting in your template.
+
## Troubleshooting
### Attaching IAM Policies to Roles
diff --git a/docs/datasources/index.mdx b/docs/datasources/index.mdx
index e471b48a0..85651f1e9 100644
--- a/docs/datasources/index.mdx
+++ b/docs/datasources/index.mdx
@@ -27,7 +27,7 @@ Then, run [`packer init`](/packer/docs/commands/init).
packer {
required_plugins {
amazon = {
- version = ">= 1.2.4"
+ version = ">= 1.2.5"
source = "github.com/hashicorp/amazon"
}
}
diff --git a/docs/post-processors/import.mdx b/docs/post-processors/import.mdx
index 6766c800c..08bca8ecb 100644
--- a/docs/post-processors/import.mdx
+++ b/docs/post-processors/import.mdx
@@ -47,7 +47,7 @@ Then, run [`packer init`](/packer/docs/commands/init).
packer {
required_plugins {
amazon = {
- version = ">= 1.2.4"
+ version = ">= 1.2.5"
source = "github.com/hashicorp/amazon"
}
}
diff --git a/example/build.pkr.hcl b/example/build.pkr.hcl
index 9d71a194b..deb7612da 100644
--- a/example/build.pkr.hcl
+++ b/example/build.pkr.hcl
@@ -1,3 +1,6 @@
+# Copyright (c) HashiCorp, Inc.
+# SPDX-License-Identifier: MPL-2.0
+
packer {
required_plugins {
amazon = {
diff --git a/main.go b/main.go
index 21d6a04a8..9359e8f58 100644
--- a/main.go
+++ b/main.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package main
import (
diff --git a/post-processor/import/post-processor.go b/post-processor/import/post-processor.go
index 7ab25abcd..e8e3219f4 100644
--- a/post-processor/import/post-processor.go
+++ b/post-processor/import/post-processor.go
@@ -1,3 +1,6 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
//go:generate packer-sdc mapstructure-to-hcl2 -type Config
package amazonimport
diff --git a/version/version.go b/version/version.go
index 3e660cc70..f13efa9a4 100644
--- a/version/version.go
+++ b/version/version.go
@@ -1,10 +1,13 @@
+// Copyright (c) HashiCorp, Inc.
+// SPDX-License-Identifier: MPL-2.0
+
package version
import "github.com/hashicorp/packer-plugin-sdk/version"
var (
// Version is the main version number that is being run at the moment.
- Version = "1.2.4"
+ Version = "1.2.5"
// VersionPrerelease is A pre-release marker for the Version. If this is ""
// (empty string) then it means that it is a final release. Otherwise, this