使用Terraform管理Databricks工作区
方法管理Databricks工作区中的资源Databricks Terraform提供商.
下面的配置块初始化最常见的变量,databricks_spark_version,databricks_node_type,databricks_current_user.
Terraform {required_providers {databricks = {source = "databricks/databricks"}}} provider "databricks" {} data "databricks_current_user" "me" {} data "databricks_spark_version" "latest" {} data "databricks_node_type" " minimal " {local_disk = true}
标准功能
这些资源不需要管理特权。更多的文档可以在专门的页面上找到databricks_token,databricks_notebook,databricks_job,databricks_cluster.
资源"databricks_token" "pat" {comment = "从${abspath(path.module)}创建的" lifetime_seconds = 3600}资源"databricks_notebook" "this" {path = "${data.databricks_current_user.me. txt "home}/Terraform" language = "PYTHON" content_base64 = base64encode(<<-EOT token = dbutils.secrets.get('${databricks_secret_range .this.name}', '${databricks_secret.token.key}') print(f' this should be redacted: {token}') EOT)} resource "databricks_job" "this" {name = "Terraform Demo (${data.databricks_current_user.me. alphannumeric})" new_cluster {num_workers = 1 spark_version = data.databricks_spark_version.latest. txt "Id node_type_id = data.databricks_node_type. least。Id} notebook_task {notebook_path = databricks_记事本。email_notifications {}} resource "databricks_cluster" "this" {cluster_name = "Exploration (${data.databricks_current_user.me. alphannumeric})" spark_version = data.databricks_spark_version.latest. path} email_notifications {}} resource "databricks_cluster" "this" {cluster_name = "Exploration (${data.databricks_current_user.me. alphannumeric})"Id instance_pool_id = databricks_instance_pool.smallest_nodes。Id autotermination_minutes = 20 autoscale {min_workers = 1 max_workers = 10}}输出"notebook_url" {value = databricks_记事本。Url}输出"job_url" {value = databricks_job.this。url}
工作区安全
管理安全性需要管理权限。更多的文档可以在专门的页面上找到databricks_secret_acl,databricks_group,databricks_user,databricks_group_member,databricks_permissions.
资源"databricks_secret_acl" "spectator " {principal = databricks_group.spectator。display_name scope = databricks_secret_scope.this.name permission = "READ"} resource "databricks_group" " audience " {display_name = " audience (by ${data.databricks_current_user.me. alphannumeric})"} resource "dummy" {user_name = "dummy+${data.databricks_current_user. me.alphannumeric}@example.com" display_name = "dummy ${data.databricks_current_user.me. "字母数字}"}resource "databricks_group_member" "a" {group_id = databricks_group.spectator .}"Id member_id = databricks_user.dummy。Id} resource "databricks_permissions" "notebook" {notebook_path = databricks_notebook.this. Id} resource "databricks_permissions" "notebook" {notebook_path = databricks_notebook.this. Id}Id access_control {user_name = databricks_user.dummy。user_name permission_level = "CAN_RUN"} access_control {group_name = databricks_group.spectator . user_name permission_level = "CAN_RUN"}display_name permission_level = "CAN_READ"}} resource "databricks_permissions" "job" {job_id = databricks_job.this. {job_id = "CAN_READ"}}Id access_control {user_name = databricks_user.dummy。user_name permission_level = "IS_OWNER"} access_control {group_name = databricks_group.spectator . user_name permission_level = "IS_OWNER"}display_name permission_level = "CAN_MANAGE_RUN"}} resource "databricks_permissions" "cluster" {cluster_id = databricks_cluster.this. display_name permission_level = "CAN_MANAGE_RUN"}}Id access_control {user_name = databricks_user.dummy。user_name permission_level = "CAN_RESTART"} access_control {group_name = databricks_group.spectator . user_name permission_level = "CAN_RESTART"}display_name permission_level = "CAN_ATTACH_TO"}}resource "databricks_permissions" "policy" { cluster_policy_id = databricks_cluster_policy.this.id access_control { group_name = databricks_group.spectators.display_name permission_level = "CAN_USE" } } resource "databricks_permissions" "pool" { instance_pool_id = databricks_instance_pool.smallest_nodes.id access_control { group_name = databricks_group.spectators.display_name permission_level = "CAN_ATTACH_TO" } }
存储
根据您的喜好和需求,可以这样做
管理JAR、Wheel和Egg库databricks_dbfs_file资源。
属性列出DBFS上的条目databricks_dbfs_file_paths数据源。
方法获取小文件的内容databricks_dbfs_file数据源。
高级配置
更多文档可在专用页面databricks_workspace_conf.
数据"http" "my" {url = "https://ifconfig。{custom_config = {"enableIpAccessLists": "true"}}