databricks / terraform-provider-databricks

Databricks Terraform Provider
https://registry.terraform.io/providers/databricks/databricks/latest
Other
460 stars 394 forks source link

[ISSUE] Issue with `databricks_jobs` resource: default for `source` ignored #3951

Open fjakobs opened 3 months ago

fjakobs commented 3 months ago

If I explicitly define the source value for a job resource and then later comment out the source attribute then it doesn't revert to the default value. Instead, it's always a no-op.

Configuration

terraform {
    required_providers {
        databricks = {
            source  = "databricks/databricks"
            "version": "1.40.0"
        }
    }
}

provider "databricks" {
    host = "XXXX"
}

resource "databricks_job" "this" {
    name = "fabian_job_debug"

    task {
        task_key = "python1"
        spark_python_task {
          python_file = "/Workspace/Shared/test.py"
          source = "GIT"
        }
        job_cluster_key = "job_cluster"
    }

    task {
        task_key = "python2"
        spark_python_task {
          python_file = "/Workspace/Shared/test.py"
          source = "WORKSPACE"
        }
        job_cluster_key = "job_cluster"
    }

    task {
        task_key = "python3"
        spark_python_task {
          python_file = "/Workspace/Shared/test.py"
        }
        job_cluster_key = "job_cluster"
    }

    job_cluster {
      job_cluster_key = "job_cluster"
      new_cluster {
        autoscale {
            min_workers = 1
            max_workers = 8
        }
        node_type_id = "Standard_D3_v2"
        spark_version = "13.3.x-scala2.12"
      }
    }

    git_source {
        branch = "master"
        provider = "awsCodeCommit"
        url = "https://git-codecommit.us-west-2.amazonaws.com/v1/repos/TEST_REPO"
    }
}

output "url" {
  value = databricks_job.this.url
}

Expected Behavior

When I comment out the source attributes then the value for source should be the default (whatever that is).

Actual Behavior

Commenting the source attributes has no effect. The value remains unchanged and Terraform considers this as "no change".

Steps to Reproduce

  1. terraform apply the code above
  2. Comment our the source attributes`
  3. terraform apply again

Terraform and provider versions

Terraform v1.5.7
on darwin_arm64
+ provider registry.terraform.io/databricks/databricks v1.40.0

Your version of Terraform is out of date! The latest version
is 1.9.5. You can update by downloading from https://www.terraform.io/downloads.html

Would you like to implement a fix?

no

mgyucht commented 1 month ago

The issue here has to do with the fact that this field is optional & computed. This means that the user doesn't need to specify a value for it, and in this case, the provider can define a value. A user removing the value for this then doesn't result in any plan.

Instead, this field needs to be made not computed, so that the provider can determine that the field has been removed. The server-side value could be stored elsewhere in the state to make it easily accessible if needed. Then, it will be possible to differentiate this case. This is similar to how we are dealing with databricks_share, which has similar issues with computed attributes.