Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add platform flag for ec2 image import task #434

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .web-docs/components/post-processor/import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ Optional:
`legacy-bios` or `uefi`. If `architecture` is set to `arm64` then this value
must be set to `uefi`.

- `platform` (string) - The operating system of the virtual machine. One of:
`linux` or `windows`. If `boot_mode` is set to `uefi` then this value must be
set to either `windows` or `linux` depending on the operating system of the
virtual machine.

- `custom_endpoint_ec2` (string) - This option is useful if you use a cloud
provider whose API is compatible with aws EC2. Specify another endpoint
like this `https://ec2.custom.endpoint.com`.
Expand Down
5 changes: 5 additions & 0 deletions docs/post-processors/import.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ Optional:
`legacy-bios` or `uefi`. If `architecture` is set to `arm64` then this value
must be set to `uefi`.

- `platform` (string) - The operating system of the virtual machine. One of:
`linux` or `windows`. If `boot_mode` is set to `uefi` then this value must be
set to either `windows` or `linux` depending on the operating system of the
virtual machine.

- `custom_endpoint_ec2` (string) - This option is useful if you use a cloud
provider whose API is compatible with aws EC2. Specify another endpoint
like this `https://ec2.custom.endpoint.com`.
Expand Down
13 changes: 13 additions & 0 deletions post-processor/import/post-processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Config struct {
Format string `mapstructure:"format"`
Architecture string `mapstructure:"architecture"`
BootMode string `mapstructure:"boot_mode"`
Platform string `mapstructure:"platform"`

ctx interpolate.Context
}
Expand Down Expand Up @@ -136,6 +137,17 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
errs, fmt.Errorf("invalid format '%s'. Only 'ova', 'raw', 'vhd', 'vhdx', or 'vmdk' are allowed", p.config.Format))
}

switch p.config.Platform {
case "windows", "linux":
case "":
if p.config.BootMode == "uefi" {
errs = packersdk.MultiErrorAppend(
errs, fmt.Errorf("invalid platform '%s', 'platform' must be set for 'uefi' image imports", p.config.Platform))
}
default:
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf(
"invalid platform '%s'. Only 'linux' and 'windows' are allowed", p.config.Platform))
}
if p.config.S3Encryption != "" && p.config.S3Encryption != "AES256" && p.config.S3Encryption != "aws:kms" {
errs = packersdk.MultiErrorAppend(
errs, fmt.Errorf("invalid s3 encryption format '%s'. Only 'AES256' and 'aws:kms' are allowed", p.config.S3Encryption))
Expand Down Expand Up @@ -259,6 +271,7 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifa
},
Architecture: &p.config.Architecture,
BootMode: &p.config.BootMode,
Platform: &p.config.Platform,
}

if p.config.Encrypt && p.config.KMSKey != "" {
Expand Down
2 changes: 2 additions & 0 deletions post-processor/import/post-processor.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading