Skip to content

Commit 5a29dfa

Browse files
MyroslavLevchykMyroslavLevchyk
authored andcommitted
feat: added workspace base environments
1 parent 12fbd26 commit 5a29dfa

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ No modules.
376376
| [databricks_database_instance.this](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/database_instance) | resource |
377377
| [databricks_disable_legacy_dbfs_setting.this](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/disable_legacy_dbfs_setting) | resource |
378378
| [databricks_entitlements.this](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/entitlements) | resource |
379+
| [databricks_environments_default_workspace_base_environment.this](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/environments_default_workspace_base_environment) | resource |
380+
| [databricks_environments_workspace_base_environment.this](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/environments_workspace_base_environment) | resource |
379381
| [databricks_group.this](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/group) | resource |
380382
| [databricks_ip_access_list.allowed_list](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/ip_access_list) | resource |
381383
| [databricks_mount.adls](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/mount) | resource |
@@ -417,6 +419,7 @@ No modules.
417419
| <a name="input_sql_endpoint"></a> [sql\_endpoint](#input\_sql\_endpoint) | Set of objects with parameters to configure SQL Endpoint and assign permissions to it for certain custom groups | <pre>set(object({<br/> name = string<br/> cluster_size = optional(string, "2X-Small")<br/> min_num_clusters = optional(number, 0)<br/> max_num_clusters = optional(number, 1)<br/> auto_stop_mins = optional(string, "30")<br/> enable_photon = optional(bool, false)<br/> enable_serverless_compute = optional(bool, false)<br/> spot_instance_policy = optional(string, "COST_OPTIMIZED")<br/> warehouse_type = optional(string, "PRO")<br/> permissions = optional(set(object({<br/> group_name = string<br/> permission_level = string<br/> })), [])<br/> }))</pre> | `[]` | no |
418420
| <a name="input_suffix"></a> [suffix](#input\_suffix) | Optional suffix that would be added to the end of resources names. | `string` | `""` | no |
419421
| <a name="input_workspace_admin_token_enabled"></a> [workspace\_admin\_token\_enabled](#input\_workspace\_admin\_token\_enabled) | Boolean flag to specify whether to create Workspace Admin Token | `bool` | n/a | yes |
422+
| <a name="input_workspace_base_environments"></a> [workspace\_base\_environments](#input\_workspace\_base\_environments) | Workspace base environments configuration.<br/>Base environments require environment definition files (YAML) to exist and be accessible before Terraform creates the base environment resources.<br/>Prerequisites:<br/>- CPU environment files can be stored either in a workspace directory or in a Databricks volume.<br/>- GPU environment files can only be stored in a workspace directory.<br/>Examples:<br/>- Workspace path: /Workspace/path/to/environment.yaml<br/>- Volume path: /Volumes/<catalog>/<schema>/<volume>/environment.yaml<br/>set\_as\_default specifies whether the environment should be used as the workspace default environment. | <pre>map(object({<br/> display_name = string<br/> filepath = string<br/> base_environment_type = optional(string, "CPU")<br/> set_as_default = optional(bool, false)<br/> }))</pre> | `{}` | no |
420423

421424
## Outputs
422425

variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,26 @@ When set to true:
293293
- Note: This setting only takes effect when disabling access. Re-enabling must be done manually via the Databricks UI.
294294
DESCRIPTION
295295
}
296+
297+
# Workspace environments
298+
variable "workspace_base_environments" {
299+
description = <<DESCRIPTION
300+
Workspace base environments configuration.
301+
Base environments require environment definition files (YAML) to exist and be accessible before Terraform creates the base environment resources.
302+
Prerequisites:
303+
- CPU environment files can be stored either in a workspace directory or in a Databricks volume.
304+
- GPU environment files can only be stored in a workspace directory.
305+
Examples:
306+
- Workspace path: /Workspace/path/to/environment.yaml
307+
- Volume path: /Volumes/<catalog>/<schema>/<volume>/environment.yaml
308+
set_as_default specifies whether the environment should be used as the workspace default environment.
309+
DESCRIPTION
310+
type = map(object({
311+
display_name = string
312+
filepath = string
313+
base_environment_type = optional(string, "CPU")
314+
set_as_default = optional(bool, false)
315+
}))
316+
317+
default = {}
318+
}

workspace_environments.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
resource "databricks_environments_workspace_base_environment" "this" {
2+
for_each = var.workspace_base_environments
3+
4+
display_name = each.value.display_name
5+
filepath = each.value.filepath
6+
base_environment_type = each.value.base_environment_type
7+
}
8+
9+
resource "databricks_environments_default_workspace_base_environment" "this" {
10+
count = (
11+
contains(keys(var.workspace_base_environments), "cpu") ||
12+
contains(keys(var.workspace_base_environments), "gpu")
13+
) ? 1 : 0
14+
15+
cpu_workspace_base_environment = (
16+
try(var.workspace_base_environments.cpu.set_as_default, false)
17+
? databricks_environments_workspace_base_environment.this["cpu"].name
18+
: null
19+
)
20+
21+
gpu_workspace_base_environment = (
22+
try(var.workspace_base_environments.gpu.set_as_default, false)
23+
? databricks_environments_workspace_base_environment.this["gpu"].name
24+
: null
25+
)
26+
}

0 commit comments

Comments
 (0)