# Enforce Policy Compliance For Cluster

Launch stage: GA

`POST /api/2.0/policies/clusters/enforce-compliance`

Updates a cluster to be compliant with the current version of its policy.

 If a cluster is updated while in a `TERMINATED` state, it will remain `TERMINATED`.
 The next time the cluster is started, the new attributes will take effect.

 For clusters in other states, the behavior depends on the `enforce_mode` used.

 Clusters created by the Databricks Jobs, SDP, or Models services cannot be enforced by this API.
 Instead, use the "Enforce job policy compliance" API to enforce policy compliance on jobs.

API scopes: clusters

## Request body

- `cluster_id` (string, optional)
  The ID of the cluster you want to enforce policy compliance on.
- `validate_only` (boolean, optional)
  If set, previews the changes that would be made to a cluster
   to enforce compliance but does not update the cluster.
  Default: `false`
- `enforce_mode` (string, optional)
  Determines how changes should be made to clusters that are not in `TERMINATED` state.
  
   - `ENFORCE_IMMEDIATELY`: If the cluster is in a `RUNNING` state, it will be restarted so
     that the new attributes can take effect. For other states aside from `TERMINATED` state,
     the request will be rejected.
   - `WAIT_FOR_TERMINATION`: The cluster is not immediately edited. Instead, a pending enforcement
     is scheduled to update the cluster when it terminates or restarts. When this occurs,
     `enforce_result` will contain `DEFERRED`. Only workspace admins can use this mode.
  
   Regardless of the enforce mode, clusters in `TERMINATED` state are immediately edited.
  Possible values: `ENFORCE_MODE_UNSPECIFIED`, `ENFORCE_IMMEDIATELY`, `WAIT_FOR_TERMINATION`
  Default: `ENFORCE_IMMEDIATELY`

## Returns

- `has_changes` (boolean, optional)
  Whether any changes have been made to the cluster settings for the cluster
   to become compliant with its policy.
- `changes` (array of object, optional)
  A list of changes that have been made to the cluster settings for
   the cluster to become compliant with its policy.
  - `field` (string, optional)
    The field where this change would be made.
    Example: `spark_version`
  - `previous_value` (string, optional)
    The previous value of this field before enforcing policy compliance
     (either a number, a boolean, or a string) converted to a string.
     This is intended to be read by a human. The type of the field
     can be retrieved by reading the settings field in the API response.
    Example: `10.4.x-scala2.12`
  - `new_value` (string, optional)
    The new value of this field after enforcing policy compliance
     (either a number, a boolean, or a string) converted to a string.
     This is intended to be read by a human. The typed new value of this field
     can be retrieved by reading the settings field in the API response.
    Example: `14.3.x-scala2.12`
- `enforce_result` (string, optional)
  Describes whether changes have been applied to the cluster.
  Possible values: `ENFORCE_RESULT_UNSPECIFIED`, `NO_CHANGES`, `APPLIED`, `DEFERRED`

## Response

```json
{
  "has_changes": true,
  "changes": [
    {
      "field": "spark_version",
      "previous_value": "10.4.x-scala2.12",
      "new_value": "14.3.x-scala2.12"
    }
  ],
  "enforce_result": "string"
}
```

