Skip to content

feat: add cost_optimization_features to dbtcloud_job + fix CI/Merge SAO and deferral bugs #664

@trouze

Description

@trouze

Summary

Three tightly coupled changes to dbtcloud_job that should ship together: a new attribute for controlling State-Aware Orchestration (SAO), and two bug fixes for CI/Merge jobs that were causing API errors and silent data loss.

1. New attribute: cost_optimization_features

Adds a cost_optimization_features set attribute as the preferred way to enable SAO, replacing the existing force_node_selection bool (which is now deprecated).

resource "dbtcloud_job" "example" {
  name           = "Production Run"
  dbt_version    = "latest-fusion"  # required for SAO
  execute_steps  = ["dbt build"]

  # New way — enable SAO
  cost_optimization_features = ["state_aware_orchestration"]

  # Old way (deprecated, still works)
  # force_node_selection = false
}

Valid values for cost_optimization_features: state_aware_orchestration

2. Bug fix: CI/Merge jobs no longer error with SAO validation (405)

Problem: The API rejects any explicit force_node_selection value for CI/Merge jobs with 405: State aware orchestration is not available for CI or Merge jobs. The provider was sending force_node_selection=false for these jobs even when the user hadn't set it, because the field was Computed: true and defaulted to unknown.

Fix: Skip sending force_node_selection entirely when the plan value is null or unknown.

3. Bug fix: CI/Merge jobs no longer silently drop deferring_environment_id

Problem: CreateJob contained logic that explicitly zeroed out deferring_environment_id and deferring_job_id for CI/Merge jobs. This is incorrect — deferral for artifact access is valid and separate from SAO.

Fix: Remove the zeroing logic. CI/Merge jobs now correctly preserve deferring_environment_id.

Tests added

  • TestAccDbtCloudJobResourceCIWithDeferral
  • TestAccDbtCloudJobResourceMergeWithDeferral
  • TestAccDbtCloudJobResourceCINoForceNodeSelection
  • TestAccDbtCloudJobResourceMergeNoForceNodeSelection
  • TestAccDbtCloudJobResourceCostOptimizationFeatures

Files

  • pkg/dbt_cloud/job.go
  • pkg/framework/objects/job/model.go
  • pkg/framework/objects/job/resource.go
  • pkg/framework/objects/job/schema.go
  • pkg/framework/objects/job/resource_acceptance_cost_optimization_test.go (new)

Source

Developed on branch fix/provider-bug-wsargent. PR description with full detail is in PR_DESCRIPTION.md on that branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions