// Module included in the following assemblies:
//
// * machine_management/cluster_api_machine_management/cluster_api_provider_configurations/cluster-api-config-options-aws.adoc
// There are parallel features in Azure so this module is set up for reuse.

ifeval::["{context}" == "cluster-api-config-options-aws"]
:aws:
endif::[]

:_mod-docs-content-type: CONCEPT
[id="machine-feature-agnostic-capacity-reservation_{context}"]
= Capacity Reservation configuration options

[role="_abstract"]
{product-title} version {product-version} and later supports
ifdef::azure[on-demand Capacity Reservation with Capacity Reservation groups on {azure-full} clusters.]
ifdef::aws[Capacity Reservations on {aws-full} clusters, including On-Demand Capacity Reservations and Capacity Blocks for ML.]

You can deploy machines on any available resources that match the parameters of a capacity request that you define.
These parameters specify the 
ifdef::azure[VM size,]
ifdef::aws[instance type,]
region, and number of instances that you want to reserve.
If your 
ifdef::azure[{azure-short} subscription quota]
ifdef::aws[Capacity Reservation]
can accommodate the capacity request, the deployment succeeds.

include::snippets/apply-machine-configuration-method.adoc[tag=method-machine-template]

ifdef::azure[]
[NOTE]
====
You cannot change an existing Capacity Reservation configuration for a machine set. 
To use a different Capacity Reservation group, you must replace the machine set and the machines that the previous machine set deployed.
====
endif::azure[]

.Sample Capacity Reservation configuration
[source,yaml]
----
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: AWSMachineTemplate
# ...
spec:
  template:
    spec:
      capacityReservationId: <capacity_reservation>
      capacityReservationPreference: <reservation_preference>
      marketType: <market_type>
# ...
----

where:

`spec.template.spec.capacityReservationId`:: Specifies the ID of the 
ifdef::azure[Capacity Reservation group]
ifdef::aws[Capacity Block for ML or On-Demand Capacity Reservation]
that you want to deploy machines on.
ifdef::aws[]
`spec.template.spec.capacityReservationPreference`:: Specifies your preferred capacity reservation behavior.
The following values are valid:
+
--
`CapacityReservationsOnly`:: Use this option to require a matching capacity reservation.
If no matching capacity reservation is available, the instance fails to launch.
`Open`:: Use this option to allow using an open capacity reservation that matches the availability zone and instance type.
`None`:: Use this option to prohibit using a capacity reservation.
You might use this option to help keep capacity reservations available for workloads that you want to use them.
--
`spec.template.spec.marketType`:: Specifies the market type to use.
The following values are valid:
+
--
`CapacityBlock`:: Use this market type with Capacity Blocks for ML.
`OnDemand`:: Use this market type with On-Demand Capacity Reservations.
`Spot`:: Use this market type with Spot Instances.
This option is not compatible with Capacity Reservations.
--
endif::aws[]
For more information, including limitations and suggested use cases for this offering, see
// Comment in Azure link when Azure assembly with module include is created.
//ifdef::azure[link:https://learn.microsoft.com/en-us/azure/virtual-machines/capacity-reservation-overview[On-demand Capacity Reservation] in the {azure-full} documentation.]
ifdef::aws[On-Demand Capacity Reservations and Capacity Blocks for ML ({aws-short} documentation).]

ifeval::["{context}" == "cluster-api-config-options-aws"]
:!aws:
endif::[]
