|
| 1 | +# Target Includes Example |
| 2 | + |
| 3 | +This example demonstrates the concept of using `target_includes` (or similar include mechanisms) in Databricks Asset Bundles to organize job configurations across different environments without duplication. |
| 4 | + |
| 5 | +It addresses the use case described in [GitHub Issue #2878](https://github.com/databricks/cli/issues/2878), which requests the ability to include specific resource files based on target configurations. |
| 6 | + |
| 7 | +## Directory Structure |
| 8 | + |
| 9 | +``` |
| 10 | +target_includes/ |
| 11 | +├── databricks.yml # Main bundle configuration with 3 targets |
| 12 | +├── resources/ |
| 13 | +│ ├── set1/ # Jobs for dev and staging environments |
| 14 | +│ │ ├── job_1.yml |
| 15 | +│ │ └── job_2.yml |
| 16 | +│ └── set2/ # Jobs for staging and prod environments |
| 17 | +│ ├── job_1.yml |
| 18 | +│ └── job_2.yml |
| 19 | +└── README.md |
| 20 | +``` |
| 21 | + |
| 22 | +## Target Configuration |
| 23 | + |
| 24 | +The bundle defines three targets: |
| 25 | + |
| 26 | +- **dev**: Includes only `resources/set1/*.yml` |
| 27 | + - Contains: set1-job-1, set1-job-2 |
| 28 | + - Environment: development |
| 29 | + |
| 30 | +- **staging**: Includes both `resources/set1/*.yml` and `resources/set2/*.yml` |
| 31 | + - Contains: set1-job-1, set1-job-2, set2-job-1, set2-job-2 |
| 32 | + - Environment: staging |
| 33 | + |
| 34 | +- **prod**: Includes only `resources/set2/*.yml` |
| 35 | + - Contains: set2-job-1, set2-job-2 |
| 36 | + - Environment: production |
| 37 | + |
| 38 | + |
| 39 | +## Notes |
| 40 | + |
| 41 | +There are some important aspects of this implementation: |
| 42 | +- The `databricks.yml` file includes all configuration files for all targets (see `include` section). This does not impact which resources will be deployed to each target. |
| 43 | +- For each job in a corresponding configuration file, such as `resources/set1/job_1.yml`, targets are defined where the job should be deployed. YAML anchors are used to avoid duplications between targets. |
| 44 | + |
| 45 | + |
| 46 | +## Usage |
| 47 | + |
| 48 | +```bash |
| 49 | +databricks bundle summary -p u2m -t dev |
| 50 | +``` |
| 51 | + |
| 52 | +Output: |
| 53 | +```bash |
| 54 | +Name: target-includes-example |
| 55 | +Target: dev |
| 56 | +Workspace: |
| 57 | + User: *** |
| 58 | + Path: *** |
| 59 | +Resources: |
| 60 | + Jobs: |
| 61 | + set1-job-1: |
| 62 | + Name: Set1 Job 1 - foo |
| 63 | + URL: (not deployed) |
| 64 | + set1-job-2: |
| 65 | + Name: Set1 Job 2 - foo |
| 66 | + URL: (not deployed) |
| 67 | +``` |
| 68 | + |
| 69 | +```bash |
| 70 | +databricks bundle summary -p u2m -t staging |
| 71 | +``` |
| 72 | + |
| 73 | +Output: |
| 74 | +```bash |
| 75 | +Name: target-includes-example |
| 76 | +Target: staging |
| 77 | +Workspace: |
| 78 | + User: *** |
| 79 | + Path: *** |
| 80 | +Resources: |
| 81 | + Jobs: |
| 82 | + set1-job-1: |
| 83 | + Name: Set1 Job 1 - bar |
| 84 | + URL: (not deployed) |
| 85 | + set1-job-2: |
| 86 | + Name: Set1 Job 2 - bar |
| 87 | + URL: (not deployed) |
| 88 | + set2-job-1: |
| 89 | + Name: Set2 Job 1 - bar |
| 90 | + URL: (not deployed) |
| 91 | + set2-job-2: |
| 92 | + Name: Set2 Job 2 - bar |
| 93 | + URL: (not deployed) |
| 94 | +``` |
| 95 | + |
| 96 | +```bash |
| 97 | +databricks bundle summary -p u2m -t prod |
| 98 | +``` |
| 99 | + |
| 100 | +Output: |
| 101 | +```bash |
| 102 | +Name: target-includes-example |
| 103 | +Target: prod |
| 104 | +Workspace: |
| 105 | + User: *** |
| 106 | + Path: *** |
| 107 | +Resources: |
| 108 | + Jobs: |
| 109 | + set2-job-1: |
| 110 | + Name: Set2 Job 1 - baz |
| 111 | + URL: (not deployed) |
| 112 | + set2-job-2: |
| 113 | + Name: Set2 Job 2 - baz |
| 114 | + URL: (not deployed) |
| 115 | +``` |
0 commit comments