NewCompare CPU & GPU pricing across AWS, Azure & GCP
Terraform

Workload Policies

Configure workload rightsizing policies and attach them to clusters with Terraform.

Workload Policies

devzero_workload_policy defines how workloads should be rightsized — CPU and memory vertical scaling, horizontal scaling, and the triggers that activate them. devzero_workload_policy_target attaches a policy to one or more clusters with optional namespace, kind, and workload filters.

WorkloadPolicy

Example

resource "devzero_workload_policy" "cost_saving" {
  name                    = "cost-saving-policy"
  description             = "Rightsize non-critical workloads"
  action_triggers         = ["on_detection", "on_schedule"]
  cron_schedule           = "*/15 * * * *"
  detection_triggers      = ["pod_creation", "pod_update", "pod_evict"]
  loopback_period_seconds = 86400
  cooldown_minutes        = 300
  min_data_points         = 20
  min_change_percent      = 0.2

  cpu_vertical_scaling = {
    enabled                    = true
    target_percentile          = 0.75
    min_request                = 25
    max_scale_up_percent       = 1000
    max_scale_down_percent     = 1
    min_data_points            = 20
    adjust_req_even_if_not_set = true
    limits_removal_enabled     = true
  }

  memory_vertical_scaling = {
    enabled                    = true
    target_percentile          = 1
    min_request                = 134217728
    max_scale_up_percent       = 1000
    max_scale_down_percent     = 1
    overhead_multiplier        = 0.3
    limits_adjustment_enabled  = true
    limit_multiplier           = 1
    min_data_points            = 20
    adjust_req_even_if_not_set = true
    limits_removal_enabled     = false
  }

  enable_pmax_protection = true
  pmax_ratio_threshold   = 3
}

Required Arguments

ParameterTypeDescription
namestringHuman-friendly name for the policy

Optional Arguments

ParameterTypeDescription
descriptionstringFree-form description
action_triggerslist(string)When to act: "on_detection", "on_schedule"
cron_schedulestring5-field cron expression — required when "on_schedule" is set
detection_triggerslist(string)What triggers detection: "pod_creation", "pod_update", "pod_evict"
loopback_period_secondsnumberHistorical data window in seconds
startup_period_secondsnumberGrace period after pod starts before scaling
cooldown_minutesnumberMinimum wait time between scaling applications
min_data_pointsnumberGlobal minimum data points required before any recommendation
min_change_percentnumberGlobal minimum change threshold for applying recommendations
min_vpa_window_data_pointsnumberMinimum data points in VPA analysis window
drift_delta_percentnumberPercentage drift from baseline that triggers VPA refresh
stability_cv_maxnumberMaximum coefficient of variation to consider stable
hysteresis_vs_targetnumberHysteresis threshold vs target for HPA coordination
live_migration_enabledboolAllow live migration when applying recommendations
scheduler_pluginslist(string)Kubernetes scheduler plugins to activate
defragmentation_schedulestringCron expression for background defragmentation
enable_pmax_protectionboolRaise requests to cover observed peak usage when peak-to-recommendation ratio exceeds pmax_ratio_threshold (default: false)
pmax_ratio_thresholdnumberPeak-to-recommendation ratio that activates pmax protection (default: 3.0)
cpu_vertical_scalingobjectCPU vertical scaling configuration (see Vertical Scaling)
memory_vertical_scalingobjectMemory vertical scaling configuration (see Vertical Scaling)
gpu_vertical_scalingobjectGPU vertical scaling configuration (see Vertical Scaling)
gpu_vram_vertical_scalingobjectGPU VRAM vertical scaling configuration (see Vertical Scaling)
horizontal_scalingobjectHorizontal scaling configuration (see Horizontal Scaling)

Read-Only

AttributeTypeDescription
idstringUnique identifier of the workload policy

Vertical Scaling

Used by cpu_vertical_scaling, memory_vertical_scaling, gpu_vertical_scaling, and gpu_vram_vertical_scaling.

ParameterTypeDescription
enabledboolEnable or disable vertical scaling for this resource
target_percentilenumberUsage percentile to target (e.g. 0.75 for P75, 1 for P100)
min_requestnumberLower bound for resource requests (millicores for CPU, bytes for memory)
max_requestnumberUpper bound for resource requests
overhead_multipliernumberExtra headroom added to recommendations as a fraction (e.g. 0.3 for 30%)
limit_multipliernumberHow much higher limits should be vs requests (e.g. 2.0 = 2× the request)
limits_adjustment_enabledboolAdjust container limits as well as requests
limits_removal_enabledboolRemove resource limits from workloads (CPU only — memory limits removal is not supported)
max_scale_up_percentnumberMaximum percent to scale up in one step
max_scale_down_percentnumberMaximum percent to scale down in one step
min_data_pointsnumberMinimum data points required before a recommendation
adjust_req_even_if_not_setboolSuggest resource requests even if the workload currently has none set (default: false)

Horizontal Scaling

ParameterTypeDescription
enabledboolEnable horizontal scaling
min_replicasnumberMinimum number of replicas
max_replicasnumberMaximum number of replicas
primary_metricstringPrimary metric for HPA decisions
target_utilizationnumberTarget utilization for primary metric (0.0–1.0)
max_replica_change_percentnumberMaximum percent replica change in one step
min_data_pointsnumberMinimum data points required for HPA decisions

Import

terraform import devzero_workload_policy.example <workload_policy_id>

WorkloadPolicyTarget

devzero_workload_policy_target attaches a devzero_workload_policy to one or more clusters. You can optionally filter by workload kind, namespace, and name patterns.

Example

resource "devzero_workload_policy_target" "production" {
  name        = "production-target"
  description = "Apply cost-saving policy to production deployments"
  policy_id   = devzero_workload_policy.cost_saving.id
  cluster_ids = [devzero_cluster.production.id]
  priority    = 1
  enabled     = true

  kind_filter = ["Deployment", "StatefulSet"]

  namespace_pattern = {
    pattern = "^prod-"
    flags   = "i"
  }

  workload_selector = {
    match_labels = {
      app = "my-service"
    }
  }
}

Arguments

ParameterTypeRequiredDescription
namestringYesHuman-friendly name for the target
policy_idstringYesID of the devzero_workload_policy to attach
cluster_idslist(string)YesList of cluster IDs to apply the policy to
descriptionstringNoFree-form description
enabledboolNoWhether the target is active (default: true)
prioritynumberNoEvaluation priority when multiple targets overlap — higher values take precedence
workload_nameslist(string)NoExplicit list of workload names to include
node_group_nameslist(string)NoRestrict matching to specific node groups
kind_filterlist(string)NoWorkload kinds to include (see below)
name_patternobjectNoRegex-based workload name matching (pattern, flags)
namespace_patternobjectNoRegex-based namespace name matching (pattern, flags)
namespace_selectorobjectNoLabel selector for namespaces (match_labels, match_expressions)
workload_selectorobjectNoLabel selector for workloads (match_labels, match_expressions)

Supported kind filter values: Pod, Deployment, StatefulSet, DaemonSet, Job, CronJob, ReplicaSet, ReplicationController, Rollout

name_pattern / namespace_pattern

ParameterTypeDescription
patternstringRegular expression (RE2 syntax). Example: ^api-(staging|prod)-.*$
flagsstringRegex flags: "i" (case-insensitive), "m" (multi-line)

namespace_selector / workload_selector

ParameterTypeDescription
match_labelsmap(string)Exact label key/value pairs that must match
match_expressionslist(object)Advanced label selector requirements

Each match_expressions entry:

ParameterTypeDescription
keystringLabel key to evaluate
operatorstringIn, NotIn, Exists, or DoesNotExist
valueslist(string)Values for In/NotIn; omit for Exists/DoesNotExist

Read-Only

AttributeTypeDescription
idstringUnique identifier of the workload policy target

Import

terraform import devzero_workload_policy_target.example <workload_policy_target_id>

On this page