Skip to content

Commit b720b2d

Browse files
vladmldadrianburusdbt
authored andcommitted
Migrate job resource sign 54 (#383)
* Add basic foundation for the migration * Add basic conformance test * Add resource model * Add schema implementation * Make doc and validate the differences * Add read resource * Add delete method * Add create method * Add update method * Add missing code from sdkv2 * Add incremental changes for job tests * Add schema fixes * Going over changed code * Remove call to read method * Basic tests are passing * Progress on testing * Update doc * Add conformance tests * Remove from sdk provider * Add more conformance tests
1 parent ea8cb35 commit b720b2d

10 files changed

Lines changed: 1233 additions & 856 deletions

File tree

docs/resources/job.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
page_title: "dbtcloud_job Resource - dbtcloud"
33
subcategory: ""
44
description: |-
5-
5+
Managed a dbt Cloud job.
66
---
77

88
# dbtcloud_job (Resource)
@@ -112,7 +112,7 @@ resource "dbtcloud_job" "downstream_job" {
112112
- `execute_steps` (List of String) List of commands to execute for the job
113113
- `name` (String) Job name
114114
- `project_id` (Number) Project ID to create the job in
115-
- `triggers` (Map of Boolean) Flags for which types of triggers to use, the values are `github_webhook`, `git_provider_webhook`, `schedule` and `on_merge`. All flags should be listed and set with `true` or `false`. When `on_merge` is `true`, all the other values must be false.<br>`custom_branch_only` used to be allowed but has been deprecated from the API. The jobs will use the custom branch of the environment. Please remove the `custom_branch_only` from your config. <br>To create a job in a 'deactivated' state, set all to `false`.
115+
- `triggers` (Attributes) Flags for which types of triggers to use, the values are `github_webhook`, `git_provider_webhook`, `schedule` and `on_merge`. All flags should be listed and set with `true` or `false`. When `on_merge` is `true`, all the other values must be false.<br>`custom_branch_only` used to be allowed but has been deprecated from the API. The jobs will use the custom branch of the environment. Please remove the `custom_branch_only` from your config. <br>To create a job in a 'deactivated' state, set all to `false`. (see [below for nested schema](#nestedatt--triggers))
116116

117117
### Optional
118118

@@ -124,7 +124,7 @@ resource "dbtcloud_job" "downstream_job" {
124124
- `errors_on_lint_failure` (Boolean) Whether the CI job should fail when a lint error is found. Only used when `run_lint` is set to `true`. Defaults to `true`.
125125
- `generate_docs` (Boolean) Flag for whether the job should generate documentation
126126
- `is_active` (Boolean) Should always be set to true as setting it to false is the same as creating a job in a deleted state. To create/keep a job in a 'deactivated' state, check the `triggers` config.
127-
- `job_completion_trigger_condition` (Block Set, Max: 1) Which other job should trigger this job when it finishes, and on which conditions (sometimes referred as 'job chaining'). (see [below for nested schema](#nestedblock--job_completion_trigger_condition))
127+
- `job_completion_trigger_condition` (Block List) Which other job should trigger this job when it finishes, and on which conditions (sometimes referred as 'job chaining'). (see [below for nested schema](#nestedblock--job_completion_trigger_condition))
128128
- `job_type` (String) Can be used to enforce the job type betwen `ci`, `merge` and `scheduled`. Without this value the job type is inferred from the triggers configured
129129
- `num_threads` (Number) Number of threads to use in the job
130130
- `run_compare_changes` (Boolean) Whether the CI job should compare data changes introduced by the code changes. Requires `deferring_environment_id` to be set. (Advanced CI needs to be activated in the dbt Cloud Account Settings first as well)
@@ -137,12 +137,24 @@ resource "dbtcloud_job" "downstream_job" {
137137
- `schedule_type` (String) Type of schedule to use, one of every_day/ days_of_week/ custom_cron
138138
- `self_deferring` (Boolean) Whether this job defers on a previous run of itself
139139
- `target_name` (String) Target name for the dbt profile
140-
- `timeout_seconds` (Number) Number of seconds to allow the job to run before timing out
140+
- `timeout_seconds` (Number, Deprecated) [Deprectated - Moved to execution.timeout_seconds] Number of seconds to allow the job to run before timing out
141141
- `triggers_on_draft_pr` (Boolean) Whether the CI job should be automatically triggered on draft PRs
142142

143143
### Read-Only
144144

145-
- `id` (String) The ID of this resource.
145+
- `id` (Number) The ID of this resource
146+
- `job_id` (Number) Job identifier
147+
148+
<a id="nestedatt--triggers"></a>
149+
### Nested Schema for `triggers`
150+
151+
Optional:
152+
153+
- `git_provider_webhook` (Boolean) Whether the job runs automatically on PR creation
154+
- `github_webhook` (Boolean) Whether the job runs automatically on PR creation
155+
- `on_merge` (Boolean) Whether the job runs automatically once a PR is merged
156+
- `schedule` (Boolean) Whether the job runs on a schedule
157+
146158

147159
<a id="nestedblock--job_completion_trigger_condition"></a>
148160
### Nested Schema for `job_completion_trigger_condition`

pkg/framework/objects/group/resource.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func (r *groupResource) Read(
5959
return
6060
}
6161

62-
state.ID = types.Int64Value(int64(*retrievedGroup.ID))
6362
state.ID = types.Int64Value(int64(*retrievedGroup.ID))
6463
state.Name = types.StringValue(retrievedGroup.Name)
6564
state.AssignByDefault = types.BoolValue(retrievedGroup.AssignByDefault)

pkg/framework/objects/job/model.go

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type JobSchedule struct {
4848

4949
type JobDataSourceModel struct {
5050
Execution *JobExecution `tfsdk:"execution"`
51-
TimeoutSeconds types.Int64 `tfsdk:"timeout_seconds"`
51+
TimeoutSeconds types.Int64 `tfsdk:"timeout_seconds"`
5252
GenerateDocs types.Bool `tfsdk:"generate_docs"`
5353
RunGenerateSources types.Bool `tfsdk:"run_generate_sources"`
5454
ID types.Int64 `tfsdk:"id"`
@@ -73,27 +73,64 @@ type JobDataSourceModel struct {
7373

7474
// TODO remove this in the next major release
7575
type SingleJobDataSourceModel struct {
76-
Execution *JobExecution `tfsdk:"execution"`
77-
TimeoutSeconds types.Int64 `tfsdk:"timeout_seconds"`
78-
GenerateDocs types.Bool `tfsdk:"generate_docs"`
79-
RunGenerateSources types.Bool `tfsdk:"run_generate_sources"`
80-
ID types.Int64 `tfsdk:"id"`
81-
JobId types.Int64 `tfsdk:"job_id"`
82-
ProjectID types.Int64 `tfsdk:"project_id"`
83-
EnvironmentID types.Int64 `tfsdk:"environment_id"`
84-
Name types.String `tfsdk:"name"`
85-
Description types.String `tfsdk:"description"`
86-
DbtVersion types.String `tfsdk:"dbt_version"`
87-
ExecuteSteps []types.String `tfsdk:"execute_steps"`
88-
DeferringJobId types.Int64 `tfsdk:"deferring_job_id"`
89-
DeferringEnvironmentID types.Int64 `tfsdk:"deferring_environment_id"`
90-
SelfDeferring types.Bool `tfsdk:"self_deferring"`
91-
Triggers *JobTriggers `tfsdk:"triggers"`
92-
Settings *JobSettings `tfsdk:"settings"`
93-
Schedule *JobSchedule `tfsdk:"schedule"`
94-
JobType types.String `tfsdk:"job_type"`
95-
TriggersOnDraftPr types.Bool `tfsdk:"triggers_on_draft_pr"`
96-
Environment *JobEnvironment `tfsdk:"environment"`
76+
Execution *JobExecution `tfsdk:"execution"`
77+
TimeoutSeconds types.Int64 `tfsdk:"timeout_seconds"`
78+
GenerateDocs types.Bool `tfsdk:"generate_docs"`
79+
RunGenerateSources types.Bool `tfsdk:"run_generate_sources"`
80+
ID types.Int64 `tfsdk:"id"`
81+
JobId types.Int64 `tfsdk:"job_id"`
82+
ProjectID types.Int64 `tfsdk:"project_id"`
83+
EnvironmentID types.Int64 `tfsdk:"environment_id"`
84+
Name types.String `tfsdk:"name"`
85+
Description types.String `tfsdk:"description"`
86+
DbtVersion types.String `tfsdk:"dbt_version"`
87+
ExecuteSteps []types.String `tfsdk:"execute_steps"`
88+
DeferringJobId types.Int64 `tfsdk:"deferring_job_id"`
89+
DeferringEnvironmentID types.Int64 `tfsdk:"deferring_environment_id"`
90+
SelfDeferring types.Bool `tfsdk:"self_deferring"`
91+
Triggers *JobTriggers `tfsdk:"triggers"`
92+
Settings *JobSettings `tfsdk:"settings"`
93+
Schedule *JobSchedule `tfsdk:"schedule"`
94+
JobType types.String `tfsdk:"job_type"`
95+
TriggersOnDraftPr types.Bool `tfsdk:"triggers_on_draft_pr"`
96+
Environment *JobEnvironment `tfsdk:"environment"`
9797
JobCompletionTriggerCondition []*JobCompletionTriggerCondition `tfsdk:"job_completion_trigger_condition"`
98-
RunCompareChanges types.Bool `tfsdk:"run_compare_changes"`
98+
RunCompareChanges types.Bool `tfsdk:"run_compare_changes"`
99+
}
100+
101+
type JobResourceModel struct {
102+
// Execution *JobExecution `tfsdk:"execution"` // has timeout-seconds
103+
TimeoutSeconds types.Int64 `tfsdk:"timeout_seconds"` // moved under execution , add deprecation message
104+
GenerateDocs types.Bool `tfsdk:"generate_docs"` // exists
105+
RunGenerateSources types.Bool `tfsdk:"run_generate_sources"` // exists
106+
ID types.Int64 `tfsdk:"id"` // will hold job id?
107+
JobId types.Int64 `tfsdk:"job_id"` // for framework
108+
ProjectID types.Int64 `tfsdk:"project_id"` // exists
109+
EnvironmentID types.Int64 `tfsdk:"environment_id"` // exists
110+
Name types.String `tfsdk:"name"` // exists
111+
Description types.String `tfsdk:"description"` // exists
112+
DbtVersion types.String `tfsdk:"dbt_version"` // exists
113+
ExecuteSteps []types.String `tfsdk:"execute_steps"` // exists
114+
DeferringEnvironmentID types.Int64 `tfsdk:"deferring_environment_id"` // exists
115+
Triggers *JobTriggers `tfsdk:"triggers"` // exists
116+
// Settings *JobSettings `tfsdk:"settings"` // has no of threads and target name
117+
// Schedule *JobSchedule `tfsdk:"schedule"` // has cron expression
118+
JobType types.String `tfsdk:"job_type"` // exists
119+
TriggersOnDraftPr types.Bool `tfsdk:"triggers_on_draft_pr"` // exists
120+
// Environment *JobEnvironment `tfsdk:"environment"`
121+
JobCompletionTriggerCondition []*JobCompletionTriggerCondition `tfsdk:"job_completion_trigger_condition"` // exists
122+
RunCompareChanges types.Bool `tfsdk:"run_compare_changes"` // exists
123+
IsActive types.Bool `tfsdk:"is_active"`
124+
TargetName types.String `tfsdk:"target_name"` // add deprecated
125+
NumThreads types.Int64 `tfsdk:"num_threads"` // add deprecated moved to settings
126+
RunLint types.Bool `tfsdk:"run_lint"`
127+
ErrorsOnLintFailure types.Bool `tfsdk:"errors_on_lint_failure"`
128+
ScheduleType types.String `tfsdk:"schedule_type"`
129+
ScheduleInterval types.Int64 `tfsdk:"schedule_interval"`
130+
ScheduleHours []types.Int64 `tfsdk:"schedule_hours"`
131+
ScheduleDays []types.Int64 `tfsdk:"schedule_days"`
132+
ScheduleCron types.String `tfsdk:"schedule_cron"` // add deprecated move to schedule
133+
DeferringJobId types.Int64 `tfsdk:"deferring_job_id"` // add deprecated move to deferring_job_definition_id
134+
SelfDeferring types.Bool `tfsdk:"self_deferring"`
135+
CompareChangesFlags types.String `tfsdk:"compare_changes_flags"`
99136
}

0 commit comments

Comments
 (0)