You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+66-10Lines changed: 66 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
`dbt-jobs-as-code` is a tool built to handle dbt Cloud Jobs as a well-defined YAML file. Being standard YAML, it is possible to use YAML anchors to reduce duplicate configuration across jobs.
4
4
5
+
There is also a templating capability to use the same YAML file to update different dbt Cloud projects and/or environments (see [templating](#templating-jobs-yaml-file)).
6
+
5
7
A given dbt Cloud project can use both jobs-as-code and jobs-as-ui at the same time, without any conflict.
6
8
7
9
The way we differentiate jobs defined from code from the ones defined from the UI is that the code ones have a name ending with `[[<identifier>]]`.
@@ -12,21 +14,22 @@ The way we differentiate jobs defined from code from the ones defined from the U
12
14
13
15
## Why not Terraform
14
16
15
-
Terrraform is widely used to manage infrastructure as code. And a [Terraform provider](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest) exists for dbt Cloud, able to manage dbt Cloud jobs (as well as projects, environments etc...).
17
+
Terrraform is widely used to manage infrastructure as code. And a comprehensive [Terraform provider](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest) exists for dbt Cloud, able to manage dbt Cloud jobs (as well as most of the rest of the dbt Cloud configuration like projects, environments, warehouse connections etc...).
16
18
17
-
Using Terraform requires some knowledge about the tool and requires managing/storing/sharing a state file, containing information about the state of the application.
19
+
Terraform is much more powerful but using it requires some knowledge about the tool and requires managing/storing/sharing a state file, containing information about the state of the application.
18
20
19
21
With this package's approach, people don't need to learn another tool and can configure dbt Cloud using YAML, a language used across the dbt ecosystem:
20
22
21
23
-**no state file required**: the link between the YAML jobs and the dbt Cloud jobs is stored in the jobs name, in the `[[<identifier>]]` part
22
24
-**YAML**: dbt users are familiar with YAML and we created a JSON schema allowing people to verify that their YAML files are correct
25
+
- by using filters like `--project-id`, `--environment-id` or `--limit-projects-envs-to-yml` people can limit the projects and environments checked by the tool, which can be used to "promote" jobs between different dbt Cloud environments
23
26
24
27
## Usage
25
28
26
29
### Installation
27
30
28
31
- Create a Python virtual environment and activate it
29
-
- Run `pip install git+https://github.com/dbt-labs/dbt-jobs-as-code.git` (or `pip install git+https://github.com/dbt-labs/dbt-jobs-as-code.git@v0.4.0` to install a specific release)
32
+
- Run `pip install git+https://github.com/dbt-labs/dbt-jobs-as-code.git` (or `pip install git+https://github.com/dbt-labs/dbt-jobs-as-code.git@v0.6.0` to install a specific release)
30
33
31
34
The CLI is now available as `dbt-jobs-as-code`
32
35
@@ -49,6 +52,7 @@ Validates that the YAML file has the correct structure
49
52
50
53
- it is possible to run the validation offline, without doing any API call
51
54
- or online using `--online`, in order to check that the different IDs provided are correct
55
+
- it supports templating the jobs YAML file (see [templating](#templating-jobs-yaml-file))
52
56
53
57
#### `plan`
54
58
@@ -57,9 +61,12 @@ Command: `dbt-jobs-as-code plan <config_file.yml>`
57
61
Returns the list of actions create/update/delete that are required to have dbt Cloud reflecting the configuration file
58
62
59
63
- this command doesn't modify the dbt Cloud jobs
60
-
- this command also accepts a list of project IDs or environments IDs to limit the command for: `dbt-jobs-as-code plan <config_file.yml> -p 1234 -p 2345 -e 4567 -e 5678`
61
-
- it is possible to limit for specific projects and/or specific environments
62
-
- when both projects and environments are provided, the command will run for the jobs that are both part of the environment ID(s) and the project ID(s) provided
64
+
- this command can be restricted to specific projects and environments
65
+
- it accepts a list of project IDs or environments IDs to limit the command for: `dbt-jobs-as-code plan <config_file.yml> -p 1234 -p 2345 -e 4567 -e 5678`
66
+
- it is possible to limit for specific projects and/or specific environments
67
+
- when both projects and environments are provided, the command will run for the jobs that are both part of the environment ID(s) and the project ID(s) provided
68
+
- or it accepts the flag `--limit-projects-envs-to-yml` to only check jobs that are in the projects and environments listed in the jobs YAML file
69
+
- it supports templating the jobs YAML file (see [templating](#templating-jobs-yaml-file))
Create/update/delete jobs and env vars overwrites in jobs to align dbt Cloud with the configuration file
69
76
70
77
- ⚠️ this command will modify your dbt Cloud jobs if the current configuration is different from the YAML file
71
-
- this command also accepts a list of project IDs or environments IDs to limit the command for: `dbt-jobs-as-code sync <config_file.yml> -p 1234 -p 2345 -e 4567 -e 5678`
72
-
- it is possible to limit for specific projects and/or specific environments
78
+
- this command can be restricted to specific projects and environments
79
+
- it accepts a list of project IDs or environments IDs to limit the command for: `dbt-jobs-as-code sync <config_file.yml> -p 1234 -p 2345 -e 4567 -e 5678`
80
+
- it is possible to limit for specific projects and/or specific environments
81
+
environment ID(s) and the project ID(s) provided
82
+
- or it accepts the flag `--limit-projects-envs-to-yml` to only check jobs that are in the projects and environments listed in the jobs YAML file
83
+
- it supports templating the jobs YAML file (see [templating](#templating-jobs-yaml-file))
73
84
74
85
#### `import-jobs`
75
86
@@ -85,7 +96,7 @@ To move some ui-jobs to jobs-as-code, perform the following steps:
85
96
86
97
- run the command to import the jobs
87
98
- copy paste the job/jobs into a YAML file
88
-
- change the `import_` id of the job in the YML file to another unique identifier
99
+
- change the `import_` id of the job in the YAML file to another unique identifier
89
100
- rename the job in the UI to end with `[[new_job_identifier]]`
90
101
- run a `plan` command to verify that no changes are required for the given job
91
102
@@ -107,14 +118,59 @@ This command can be used to deactivate both the schedule and the CI triggers for
107
118
108
119
### Job Configuration YAML Schema
109
120
110
-
The file `src/schemas/load_job_schema.json` is a JSON Schema file that can be used to verify that the YAML config files syntax is correct.
121
+
The file `src/schemas/load_job_schema.json` is a JSON Schema file that can be used to verify that the YAML config files syntax is correct and to provide completion suggestions for the different fields supported.
111
122
112
123
To use it in VSCode, install [the extension `YAML`](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) and add the following line at the top of your YAML config file (change the path if need be):
- and add the parameter `--vars-yml` (or `-v`) pointing to a YAML file containing values for your variables
138
+
139
+
The file called in `--vars-yml` needs to be a valid YAML file like the following:
140
+
141
+
```yml
142
+
project_id: 123
143
+
environment_id: 456
144
+
```
145
+
146
+
There are some example of files under `example_jobs_file/jobs_templated...`. Those examples also show how we can use Jinja logic to set some parameters based on our variables.
147
+
148
+
When using templates, you might also want to use the flag `--limit-projects-envs-to-yml`. This flag will make sure that only the projects and environments of the rendered YAML files will be checked to see what jobs to create/delete/update.
149
+
150
+
Templating also allows people to version control those YAML files and to have different files for different development layers, like:
As a reminder using `--project-id` and/or `--environment-id` is not compatible with using `--limit-projects-envs-to-yml`.
172
+
We can only restricts by providing the IDs or by forcing to restrict on the environments and projects in the YML file.
173
+
118
174
## Running the tool as part of CI/CD
119
175
120
176
An example of GitHub Action is provided in the [example_cicd folder](https://github.com/dbt-labs/dbt-jobs-as-code/blob/HEAD/example_cicd). This example requires having set the GitHub secret `DBT_API_KEY`.
0 commit comments