For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-databricks-cluster-aws-attributes.md. A documentation index is available at /llms.txt.
This product is not supported for your selected Datadog site. ().

Metadata

Id: terraform-databricks-cluster-aws-attributes

Provider: Databricks

Platform: Terraform

Severity: Low

Category: Best Practices

Learn More

Description

One or more AWS attribute best practices are not followed for this Databricks cluster.

The rule flags databricks_cluster resources when:

  • aws_attributes.availability is set to SPOT
  • aws_attributes.first_on_demand is missing or set to 0
  • aws_attributes.zone_id is not equal to auto

Compliant Code Examples

resource "databricks_cluster" "negative" {
  cluster_name            = "Shared Autoscaling"
  spark_version           = data.databricks_spark_version.latest.id
  node_type_id            = data.databricks_node_type.smallest.id
  autotermination_minutes = 20
  autoscale {
    min_workers = 1
    max_workers = 50
  }
  aws_attributes {
    availability           = "SPOT_WITH_FALLBACK"
    zone_id                = "auto"
    first_on_demand        = 1
    spot_bid_price_percent = 100
  }
}
# first_on_demand is set via a local value reference (local.first_on_demand),
# not a literal. Terraform's databricks provider reports first_on_demand as
# null in planned_values pre-apply for any non-literal expression here,
# regardless of what it resolves to -- indistinguishable, in planned_values
# alone, from first_on_demand never being configured at all. The rule
# confirms via _dd_tfplan_meta.configuration_expressions that
# first_on_demand was actually written by the user (as a reference, not a
# constant_value), so it correctly stays silent instead of flagging this as
# an unconfigured/zero first_on_demand. See negative2.json for the plan-JSON
# side (a real `terraform plan` for this exact configuration).
locals {
  first_on_demand = 1
}

resource "databricks_cluster" "negative2" {
  cluster_name            = "data"
  spark_version           = "13.3.x-scala2.12"
  node_type_id            = "i3.xlarge"
  autotermination_minutes = 20
  autoscale {
    min_workers = 1
    max_workers = 50
  }
  aws_attributes {
    availability           = "SPOT_WITH_FALLBACK"
    zone_id                = "auto"
    first_on_demand        = local.first_on_demand
    spot_bid_price_percent = 100
  }
}

Non-Compliant Code Examples

resource "databricks_cluster" "positive1" {
  cluster_name            = "data"
  spark_version           = data.databricks_spark_version.latest.id
  node_type_id            = data.databricks_node_type.smallest.id
  autotermination_minutes = 20
  autoscale {
    min_workers = 1
    max_workers = 50
  }
  aws_attributes {
    availability           = "SPOT"
    zone_id                = "auto"
    first_on_demand        = 1
    spot_bid_price_percent = 100
  }
}
resource "databricks_cluster" "positive2" {
  cluster_name            = "data"
  spark_version           = data.databricks_spark_version.latest.id
  node_type_id            = data.databricks_node_type.smallest.id
  autotermination_minutes = 20
  autoscale {
    min_workers = 1
    max_workers = 50
  }
  aws_attributes {
    availability           = "SPOT_WITH_FALLBACK"
    zone_id                = "auto"
    first_on_demand        = 0
    spot_bid_price_percent = 100
  }
}
resource "databricks_cluster" "positive3" {
  cluster_name            = "data"
  spark_version           = data.databricks_spark_version.latest.id
  node_type_id            = data.databricks_node_type.smallest.id
  autotermination_minutes = 20
  autoscale {
    min_workers = 1
    max_workers = 50
  }
  aws_attributes {
    availability           = "SPOT_WITH_FALLBACK"
    zone_id                = "auto"
    spot_bid_price_percent = 100
  }
}