feat: add capacity_reservation_market_type configuration option#645
feat: add capacity_reservation_market_type configuration option#645harrison-ahearn wants to merge 1 commit into
Conversation
Add support for specifying market type when using EC2 capacity reservations. This enables users to leverage interruptible capacity reservations and capacity blocks by setting the capacity_reservation_market_type field. Changes include: - Add CapacityReservationMarketType field to RunConfig - Add validation for market type values (interruptible-capacity-reservation, capacity-block) - Update StepRunSourceInstance to apply market type to instance launch options - Update all builder types (ebs, ebssurrogate, ebsvolume, instance) to pass through the new field - Regenerate HCL2 spec files for all builders - Update documentation with new configuration option Co-Authored-By: Claude <noreply@anthropic.com>
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Have you signed the CLA already but the status is still pending? Recheck it. |
There was a problem hiding this comment.
Pull request overview
Adds a new capacity_reservation_market_type option to all AWS Packer builders so that users can target interruptible capacity reservations and capacity blocks when launching the source instance. The field is added to RunConfig, validated in Prepare, plumbed through each builder's StepRunSourceInstance, and surfaced via the regenerated HCL2 spec files and docs partials.
Changes:
- New
CapacityReservationMarketTypefield + validation in bothcommon/run_config.goandbuilder/common/run_config.go. StepRunSourceInstance(in both common packages) now setsInstanceMarketOptionswhen the market type is configured, with a defensive nil‑check onCapacityReservationSpecification.- All four builders (ebs, ebssurrogate, ebsvolume, instance) pass the new field through; HCL2 spec files and the two RunConfig docs partials are regenerated.
Reviewed changes
Copilot reviewed 10 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| common/run_config.go | Adds field and validation (valid values + requires id/ARN). |
| common/step_run_source_instance.go | Plumbs market type into InstanceMarketOptions (SDK v2). |
| builder/common/run_config.go | Mirror of root validation for the legacy package. |
| builder/common/step_run_source_instance.go | Mirror of step changes (SDK v1). |
| builder/ebs/builder.go, builder/ebssurrogate/builder.go, builder/ebsvolume/builder.go, builder/instance/builder.go | Wire new config into StepRunSourceInstance. |
| builder/{ebs,ebssurrogate,ebsvolume,instance}/builder.hcl2spec.go | Regenerated HCL2 specs. |
| docs-partials/common/RunConfig-not-required.mdx, docs-partials/builder/common/RunConfig-not-required.mdx | Documents the new option. |
Files not reviewed (4)
- builder/ebs/builder.hcl2spec.go: Language not supported
- builder/ebssurrogate/builder.hcl2spec.go: Language not supported
- builder/ebsvolume/builder.hcl2spec.go: Language not supported
- builder/instance/builder.hcl2spec.go: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Validate capacity_reservation_market_type | ||
| if c.CapacityReservationMarketType != "" { | ||
| switch c.CapacityReservationMarketType { | ||
| case "interruptible-capacity-reservation", "capacity-block": | ||
| // Valid market types | ||
| default: | ||
| errs = append(errs, fmt.Errorf(`capacity_reservation_market_type only accepts 'interruptible-capacity-reservation' or 'capacity-block' values`)) | ||
| } | ||
| // Market type should only be used with a specific capacity reservation | ||
| if c.CapacityReservationId == "" && c.CapacityReservationGroupArn == "" { | ||
| errs = append(errs, fmt.Errorf(`capacity_reservation_market_type requires either capacity_reservation_id or capacity_reservation_group_arn to be set`)) | ||
| } | ||
| } |
| case "interruptible-capacity-reservation", "capacity-block": | ||
| // Valid market types | ||
| default: | ||
| errs = append(errs, fmt.Errorf(`capacity_reservation_market_type only accepts 'interruptible-capacity-reservation' or 'capacity-block' values`)) |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 14 changed files in this pull request and generated 3 comments.
Files not reviewed (4)
- builder/ebs/builder.hcl2spec.go: Language not supported
- builder/ebssurrogate/builder.hcl2spec.go: Language not supported
- builder/ebsvolume/builder.hcl2spec.go: Language not supported
- builder/instance/builder.hcl2spec.go: Language not supported
| case "interruptible-capacity-reservation", "capacity-block": | ||
| // Valid market types | ||
| default: | ||
| errs = append(errs, fmt.Errorf(`capacity_reservation_market_type only accepts 'interruptible-capacity-reservation' or 'capacity-block' values`)) |
| // Set market type if specified for interruptible capacity reservations or capacity blocks | ||
| if s.CapacityReservationMarketType != "" { | ||
| runOpts.InstanceMarketOptions = &ec2types.InstanceMarketOptionsRequest{ | ||
| MarketType: ec2types.MarketType(s.CapacityReservationMarketType), |
| } | ||
| // Market type should only be used with a specific capacity reservation | ||
| if c.CapacityReservationId == "" && c.CapacityReservationGroupArn == "" { | ||
| errs = append(errs, fmt.Errorf(`capacity_reservation_market_type requires either capacity_reservation_id or capacity_reservation_group_arn to be set`)) |
Summary
capacity_reservation_market_typeconfiguration option to all AWS Packer buildersChanges
CapacityReservationMarketTypefield toRunConfigwith validationStepRunSourceInstanceto apply the market type viaInstanceMarketOptionsTest plan
🤖 Generated with Claude Code