dbt-labs / terraform-provider-dbtcloud

dbt Cloud Terraform Provider
https://registry.terraform.io/providers/dbt-labs/dbtcloud
MIT License
88 stars 19 forks source link

dbtcloud_job doesn't apply changes to scheduled_days when the schedule_type is custom_cron #317

Open osmus-leo opened 1 day ago

osmus-leo commented 1 day ago

Describe the bug

Terraform is repeatedly removing the schedule_days attribute from the dbtcloud_job resource during each terraform apply. When the schedule_days attribute is uncommented and specified, Terraform attempts to remove these days on every apply,

Error message

Terraform keeps removing the contents of scheduled days on every terraform apply

Terraform will perform the following actions:

  # module.projects["git"].dbtcloud_job.deploy_prod will be updated in-place
  ~ resource "dbtcloud_job" "deploy_prod" {
        id                       = "XXXXXX"
        name                     = "PROD - Full deploy"
      ~ schedule_days            = [
          - 0,
          - 1,
          - 2,
          - 3,
          - 4,
          - 5,
          - 6,
        ]
        # (21 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Resource configuration

resource "dbtcloud_job" "deploy_prod" {
  name = "PROD - Full deploy"
  execute_steps = [
    "dbt run"
  ]
  project_id = dbtcloud_project.primary.id
  triggers = {
    "git_provider_webhook" = false,
    "github_webhook"       = false,
    "schedule"             = true,
    "on_merge"             = false,
  }
  #schedule_days = [0, 1, 2, 3, 4, 5, 6]
  schedule_cron = "30 4 * * *"
  schedule_type = "custom_cron" 
  environment_id = dbtcloud_environment.primary_prod.environment_id
  generate_docs  = true
  num_threads    = 4
  dbt_version    = "versionless"
}

Expected behavior

scheduled days are removed

Config (please complete the following information):

Providers required by configuration:
.
├── provider[registry.terraform.io/dbt-labs/dbtcloud] ~> 0.0
├── provider[registry.terraform.io/hashicorp/tfe] ~> 0.0
├── provider[registry.terraform.io/microsoft/azuredevops] ~> 1.0
├── provider[registry.terraform.io/hashicorp/aws]
└── module.projects
    ├── provider[registry.terraform.io/hashicorp/aws] ~> 5.0
    ├── provider[registry.terraform.io/dbt-labs/dbtcloud] ~> 0.0
    ├── provider[registry.terraform.io/hashicorp/tfe] ~> 0.0
    └── provider[registry.terraform.io/microsoft/azuredevops] ~> 1.0

Providers required by state:

    provider[registry.terraform.io/dbt-labs/dbtcloud]

    provider[registry.terraform.io/hashicorp/aws]

    provider[registry.terraform.io/hashicorp/tfe]

    provider[registry.terraform.io/microsoft/azuredevops]

Additional context

Notice that in the state below the scheduled days is always an empty list.

    {
      "module": "module.projects[\"git\"]",
      "mode": "managed",
      "type": "dbtcloud_job",
      "name": "deploy_prod",
      "provider": "provider[\"registry.terraform.io/dbt-labs/dbtcloud\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "dbt_version": "versionless",
            "deferring_environment_id": 0,
            "deferring_job_id": 0,
            "description": "",
            "environment_id": 14003,
            "execute_steps": [
              "dbt run"
            ],
            "generate_docs": true,
            "id": "212706",
            "is_active": true,
            "job_completion_trigger_condition": [],
            "name": "PROD - Full deploy",
            "num_threads": 4,
            "project_id": 6537,
            "run_compare_changes": false,
            "run_generate_sources": false,
            "schedule_cron": "30 4 * * *",
            "schedule_days": [],
            "schedule_hours": [],
            "schedule_interval": 1,
            "schedule_type": "custom_cron",
            "self_deferring": false,
            "target_name": "default",
            "timeout_seconds": 0,
            "triggers": {
              "git_provider_webhook": false,
              "github_webhook": false,
              "on_merge": false,
              "schedule": true
            },

if you uncomment the scheduled days scheduled_days = [0, 1, 2, 3, 4, 5, 6] terraform keeps trying to add those days at every apply

b-per commented 14 hours ago

Thanks for the report, we'll have a look.

b-per commented 9 hours ago

OK, so, when using schedule_type = "custom_cron", schedule_days is not relevant so, even if we send it, the API gets back to us without schedule_days.

Would it work if we were raising an error when both schedule_type = "custom_cron" and schedule_days are defined in the config?

The provider as-is actually works fine to me (even if we could raise more error/warning). In dbt Cloud, schedule_days is actually set empty if the job is configured to use cron.