### Install Terrafmt for Documentation Formatting Source: https://github.com/databricks/terraform-provider-databricks/blob/main/CONTRIBUTING.md Install the `terrafmt` tool using `go install`. This tool is required for running `make fmt-docs` to ensure code examples are consistent. ```bash go install github.com/katbyte/terrafmt@latest ``` -------------------------------- ### Get All Serving Endpoints and Manage Permissions Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/serving_endpoints.md This example demonstrates how to fetch all available serving endpoints using the `databricks_serving_endpoints` data source and then apply specific permissions to each endpoint using the `databricks_permissions` resource. It iterates through each endpoint to assign 'CAN_VIEW', 'CAN_MANAGE', or 'CAN_QUERY' permissions to different groups. ```hcl data "databricks_serving_endpoints" "all" { } resource "databricks_permissions" "ml_serving_usage" { for_each = databricks_serving_endpoints.all.endpoints serving_endpoint_id = each.value.id access_control { group_name = "users" permission_level = "CAN_VIEW" } access_control { group_name = databricks_group.auto.display_name permission_level = "CAN_MANAGE" } access_control { group_name = databricks_group.eng.display_name permission_level = "CAN_QUERY" } } ``` -------------------------------- ### Install Databricks Terraform Provider from Source Source: https://github.com/databricks/terraform-provider-databricks/blob/main/CONTRIBUTING.md Clone the repository, navigate to the directory, and run the installation command. This is typically followed by `terraform init`. ```bash git clone https://github.com/databricks/terraform-provider-databricks.git cd terraform-provider-databricks make install ``` -------------------------------- ### Databricks Budget Resource Example Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/budget.md Example usage of the `databricks_budget` resource to create a budget with display name, alert configurations, and filters. ```hcl resource "databricks_budget" "this" { display_name = "databricks-workspace-budget" alert_configurations { time_period = "MONTH" trigger_type = "CUMULATIVE_SPENDING_EXCEEDED" quantity_type = "LIST_PRICE_DOLLARS_USD" quantity_threshold = "840" action_configurations { action_type = "EMAIL_NOTIFICATION" target = "abc@gmail.com" } } filter { workspace_id { operator = "IN" values = [ 1234567890098765 ] } tags { key = "Team" value { operator = "IN" values = ["Data Science"] } } tags { key = "Environment" value { operator = "IN" values = ["Development"] } } } } ``` -------------------------------- ### Databricks Group Instance Profile Example Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/group_instance_profile.md Example of how to create a databricks_instance_profile, a databricks_group, and then associate them using the databricks_group_instance_profile resource. ```hcl resource "databricks_instance_profile" "instance_profile" { instance_profile_arn = "my_instance_profile_arn" } resource "databricks_group" "my_group" { display_name = "my_group_name" } resource "databricks_group_instance_profile" "my_group_instance_profile" { group_id = databricks_group.my_group.id instance_profile_id = databricks_instance_profile.instance_profile.id } ``` -------------------------------- ### Example for Azure cloud Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/endpoints.md This is an example for listing endpoints in Azure cloud. ```hcl data "databricks_endpoints" "all" { parent = "accounts/123e4567-e89b-12d3-a456-426614174000" } ``` -------------------------------- ### Retrieve All SQL Warehouses Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/sql_warehouse.md This example demonstrates how to retrieve all SQL warehouses in a workspace using the `databricks_sql_warehouses` data source and then iterate through them to get individual warehouse details using the `databricks_sql_warehouse` data source. ```hcl data "databricks_sql_warehouses" "all" { } data "databricks_sql_warehouse" "this" { for_each = data.databricks_sql_warehouses.all.ids id = each.value } ``` -------------------------------- ### Example Changelog Entry Source: https://github.com/databricks/terraform-provider-databricks/blob/main/CONTRIBUTING.md An example of a changelog entry demonstrating the required format for new features or bug fixes. ```markdown * Added support for new feature ([#123](https://github.com/databricks/terraform-provider-databricks/pull/123)). ``` -------------------------------- ### Databricks Pipeline Resource Example Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/pipeline.md This example demonstrates how to configure a databricks_pipeline resource, including cluster settings, libraries, continuous execution, and email notifications. ```hcl resource "databricks_notebook" "ldp_demo" { #... } resource "databricks_repo" "ldp_demo" { #... } resource "databricks_pipeline" "this" { name = "Pipeline Name" catalog = "main" schema = "ldp_demo" configuration = { key1 = "value1" key2 = "value2" } cluster { label = "default" num_workers = 2 custom_tags = { cluster_type = "default" } } cluster { label = "maintenance" num_workers = 1 custom_tags = { cluster_type = "maintenance" } } library { notebook { path = databricks_notebook.ldp_demo.id } } library { file { path = "${databricks_repo.ldp_demo.path}/pipeline.sql" } } library { glob { include = "${databricks_repo.ldp_demo.path}/subfolder/**" } } continuous = false notification { email_recipients = ["user@domain.com", "user1@domain.com"] alerts = [ "on-update-failure", "on-update-fatal-failure", "on-update-success", "on-flow-failure" ] } } ``` -------------------------------- ### Databricks App Resource Example Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/app.md Example of how to define a databricks_app resource, specifying its name, description, and associated resources like SQL warehouses, serving endpoints, and jobs. ```hcl resource "databricks_app" "this" { name = "my-custom-app" description = "My app" resources = [{ name = "sql-warehouse" sql_warehouse = { id = "e9ca293f79a74b5c" permission = "CAN_MANAGE" } }, { name = "serving-endpoint" serving_endpoint = { name = "databricks-meta-llama-3-1-70b-instruct" permission = "CAN_MANAGE" } }, { name = "job" job = { id = "1234" permission = "CAN_MANAGE" } }] } ``` -------------------------------- ### Install a library on all clusters using DBFS file Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/dbfs_file.md This example demonstrates how to upload a wheel file (`.whl`) to DBFS using `databricks_dbfs_file` and then install it on all clusters managed by a `databricks_library` resource. It requires a `databricks_clusters` data source to get the IDs of all clusters. ```hcl data "databricks_clusters" "all" { } resource "databricks_dbfs_file" "app" { source = "${path.module}/baz.whl" path = "/FileStore/baz.whl" } resource "databricks_library" "app" { for_each = data.databricks_clusters.all.ids cluster_id = each.key whl = databricks_dbfs_file.app.dbfs_path } ``` -------------------------------- ### Create Catalog and Grant Privileges Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/grants.md This example demonstrates creating a catalog and then granting various privileges to different user groups. It shows how to manage catalog-level and schema-level privileges. ```hcl resource "databricks_catalog" "sandbox" { name = "sandbox" comment = "this catalog is managed by terraform" properties = { purpose = "testing" } } resource "databricks_grants" "sandbox" { catalog = databricks_catalog.sandbox.name grant { principal = "Data Scientists" privileges = ["USE_CATALOG", "USE_SCHEMA", "CREATE_TABLE", "SELECT"] } grant { principal = "Data Engineers" privileges = ["USE_CATALOG", "USE_SCHEMA", "CREATE_SCHEMA", "CREATE_TABLE", "MODIFY"] } grant { principal = "Data Analyst" privileges = ["USE_CATALOG", "USE_SCHEMA", "SELECT"] } } ``` -------------------------------- ### Create Database Instance and Database Catalog Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/database_database_catalog.md This example first creates a new Database Instance and then proceeds to create a Database Catalog within that newly provisioned instance. It also ensures the database is created if it doesn't exist. ```hcl resource "databricks_database_instance" "instance" { name = "my-database-instance" capacity = "CU_1" } resource "databricks_database_database_catalog" "catalog" { name = "my_registered_catalog" database_instance_name = databricks_database_instance.instance.name database_name = "new_registered_catalog_database" create_database_if_not_exists = true } ``` -------------------------------- ### Install PyPI Library on All Clusters Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/library.md Installs the 'databricks-cli' PyPI package on all clusters using a data source to get cluster IDs. ```hcl data "databricks_clusters" "all" { } resource "databricks_library" "cli" { for_each = data.databricks_clusters.all.ids cluster_id = each.key pypi { package = "databricks-cli" } } ``` -------------------------------- ### Get App Tag Assignment Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/workspace_entity_tag_assignment.md This example shows how to get tag details for a Databricks application. The entity_type should be 'apps', and the entity_id is typically the app name. ```hcl data "databricks_workspace_entity_tag_assignment" "app_tag" { entity_type = "apps" entity_id = "myapp" tag_key = "sensitivity_level" } ``` -------------------------------- ### Databricks MWS Credentials Example Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/mws_credentials.md Example usage of the databricks_mws_credentials resource to register cross-account credentials. This snippet requires AWS IAM role setup and assumes Databricks account ID and a prefix variable. ```hcl variable "databricks_account_id" { description = "Account Id that could be found in the top right corner of https://accounts.cloud.databricks.com/" } variable "prefix" { description = "Names of created resources will be prefixed with this value" } data "databricks_aws_assume_role_policy" "this" { external_id = var.databricks_account_id } resource "aws_iam_role" "cross_account_role" { name = "${var.prefix}-crossaccount" assume_role_policy = data.databricks_aws_assume_role_policy.this.json tags = var.tags } data "databricks_aws_crossaccount_policy" "this" { } resource "aws_iam_role_policy" "this" { name = "${var.prefix}-policy" role = aws_iam_role.cross_account_role.id policy = data.databricks_aws_crossaccount_policy.this.json } resource "databricks_mws_credentials" "this" { provider = databricks.mws credentials_name = "${var.prefix}-creds" role_arn = aws_iam_role.cross_account_role.arn } ``` -------------------------------- ### Example Usage Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/mws_workspaces.md Demonstrates how to use the databricks_mws_workspaces data source to list all workspaces and output their IDs. ```APIDOC ## databricks_mws_workspaces Data Source Lists all [databricks_mws_workspaces](../resources/mws_workspaces.md) in Databricks Account. -> This data source can only be used with an account-level provider! ### Example Usage Listing all workspaces in ```hcl provider "databricks" { // other configuration account_id = "" } data "databricks_mws_workspaces" "all" {} output "all_mws_workspaces" { value = data.databricks_mws_workspaces.all.ids } ``` ## Argument Reference * `provider_config` - (Optional, **Deprecated**) This data source is account-only and has no workspace context, so `provider_config` has no effect and will be removed in a future major release. The block consists of the following field: * `workspace_id` - (Optional, **Deprecated**) Ignored. This data source always operates against the account configured on the provider. ## Attribute Reference -> This resource has an evolving interface, which may change in future versions of the provider. This data source exports the following attributes: * `ids` - name-to-id map for all of the workspaces in the account ``` -------------------------------- ### Get Workspace Setting by Name Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/workspace_setting_v2.md Use this data source to retrieve a workspace setting by its name. The example shows how to fetch the 'llm_proxy_partner_powered' setting and specify its boolean value. ```hcl data "databricks_workspace_setting_v2" "this" { name="llm_proxy_partner_powered" boolean_val={ value=false } } ``` -------------------------------- ### Create a Database Catalog from an Existing Database Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/database_database_catalog.md This example demonstrates how to create a Database Catalog that references an existing database within a specified Database Instance. Ensure the Database Instance and the database already exist. ```hcl resource "databricks_database_database_catalog" "this" { name = "my_registered_catalog" database_instance_name = "my-database-instance" database_name = "databricks_postgres" } ``` -------------------------------- ### Example Usage: Get All Tag Policies Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/tag_policies.md This snippet demonstrates how to retrieve a list of all tag policies configured in the Databricks account using the `databricks_tag_policies` data source and output the results. ```hcl data "databricks_tag_policies" "all" {} output "all_tag_policies" { value = data.databricks_tag_policies.all.tag_policies } ``` -------------------------------- ### Example API Client Implementation Source: https://github.com/databricks/terraform-provider-databricks/blob/main/CONTRIBUTING.md Implements Create, Read, Update, and Delete functions for interacting with the Databricks API for a specific resource. ```go type ExampleApi struct { client *common.DatabricksClient ctx context.Context } func NewExampleApi(ctx context.Context, m interface{}) ExampleApi { return ExampleApi{m.(*common.DatabricksClient), ctx} } func (a ExampleApi) Create(e Example) (string, error) { var id string err := a.client.Post(a.ctx, "/example", e, &id) return id, err } func (a ExampleApi) Read(id string) (e Example, err error) { err = a.client.Get(a.ctx, "/example/"+id, nil, &e) return } func (a ExampleApi) Update(id string, e Example) error { return a.client.Put(a.ctx, "/example/"+string(id), e) } func (a ExampleApi) Delete(id string) error { return a.client.Delete(a.ctx, "/pipelines/"+id, nil) } ``` -------------------------------- ### Retrieve All Metastores using databricks_metastores Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/metastores.md This example demonstrates how to use the databricks_metastores data source to fetch all available metastores and output their IDs. This is useful for managing or referencing multiple metastores within your Databricks environment. ```hcl data "databricks_metastores" "all" {} output "all_metastores" { value = data.databricks_metastores.all.ids } ``` -------------------------------- ### Get Account Setting by Name Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/account_setting_v2.md Use this data source to retrieve a specific account setting by its name. The example shows how to fetch the 'llm_proxy_partner_powered' setting and specify its boolean value. ```hcl data "databricks_account_setting_v2" "this" { name="llm_proxy_partner_powered" boolean_val={ value=false } } ``` -------------------------------- ### Create a Database Catalog and New Database Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/database_database_catalog.md This example creates a Database Catalog and also provisions a new database within the specified Database Instance if it does not already exist. Set `create_database_if_not_exists` to true. ```hcl resource "databricks_database_database_catalog" "this" { name = "my_registered_catalog" database_instance_name = "my-database-instance" database_name = "new_registered_catalog_database" create_database_if_not_exists = true } ``` -------------------------------- ### Get Tag Assignments for a Schema Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/entity_tag_assignments.md This example demonstrates how to fetch tag assignments for a schema within Unity Catalog. Set `entity_type` to 'schemas' and specify the fully qualified schema name. ```hcl data "databricks_entity_tag_assignments" "schema_tags" { entity_type = "schemas" entity_name = "production_catalog.sales_data" } ``` -------------------------------- ### Create a Metastore and Assign it to a Workspace Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/metastore_assignment.md This example demonstrates how to create a new Databricks metastore and then assign it to a workspace using the `databricks_metastore_assignment` resource. Ensure the `databricks_metastore` resource is defined and configured before assigning it. ```hcl resource "databricks_metastore" "this" { name = "primary" storage_root = "s3://${aws_s3_bucket.metastore.id}/metastore" owner = "uc admins" region = "us-east-1" force_destroy = true } resource "databricks_metastore_assignment" "this" { metastore_id = databricks_metastore.this.id workspace_id = local.workspace_id } ``` -------------------------------- ### databricks_disaster_recovery_failover_group Data Source Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/disaster_recovery_failover_group.md Use the `databricks_disaster_recovery_failover_group` data source to get information about a failover group by its fully qualified resource name. This is useful for referencing existing failover group configurations in your Terraform setup. ```APIDOC ## databricks_disaster_recovery_failover_group Data Source This data source can be used to get a single failover group by its fully qualified resource name. -> **Note** This data source can only be used with an account-level provider! ### Example Usage Referring to a failover group by its resource name: ```hcl data "databricks_disaster_recovery_failover_group" "this" { name = "accounts/${var.account_id}/failover-groups/accounting-failover-group" } ``` ## Arguments The following arguments are supported: * `name` (string, required) - Fully qualified resource name in the format accounts/{account_id}/failover-groups/{failover_group_id} ## Attributes The following attributes are exported: * `create_time` (string) - Time at which this failover group was created * `effective_primary_region` (string) - Current effective primary region. Replication flows FROM workspaces in this region. Changes after a successful failover * `etag` (string) - Opaque version string for optimistic locking. Server-generated, returned in responses. Must be provided on Update requests to prevent concurrent modifications * `initial_primary_region` (string) - Initial primary region. Used only in Create requests to set the starting primary region. Not returned in responses * `name` (string) - Fully qualified resource name in the format accounts/{account_id}/failover-groups/{failover_group_id} * `regions` (list of string) - List of all regions participating in this failover group * `replication_point` (string) - The latest point in time to which data has been replicated * `state` (string) - Aggregate state of the failover group. Possible values are: `ACTIVE`, `CREATING`, `CREATION_FAILED`, `DELETING`, `DELETION_FAILED`, `FAILING_OVER`, `FAILOVER_FAILED`, `INITIAL_REPLICATION` * `unity_catalog_assets` (UcReplicationConfig) - Unity Catalog replication configuration * `update_time` (string) - Time at which this failover group was last modified * `workspace_sets` (list of WorkspaceSet) - Workspace sets, each containing workspaces that replicate to each other ### LocationMapping * `name` (string) - Resource name for this location * `uri_by_region` (list of LocationMappingEntry) - URI for each region. Each entry maps a region name to a storage URI ### LocationMappingEntry * `region` (string) - The region name * `uri` (string) - The storage URI for this region ### UcCatalog * `name` (string) - The name of the UC catalog to replicate ### UcReplicationConfig * `catalogs` (list of UcCatalog) - UC catalogs to replicate * `data_replication_workspace_set` (string) - The workspace set whose workspaces will be used for data replication of all UC catalogs' underlying storage * `location_mappings` (list of LocationMapping) - Location mappings - storage URI per region for each location ### WorkspaceSet * `name` (string) - Resource name for this workspace set * `replicate_workspace_assets` (boolean) - Whether to enable control plane DR (notebooks, jobs, clusters, etc.) for this set * `stable_url_names` (list of string) - Resource names of stable URLs associated with this workspace set. Format: accounts/{account_id}/stable-urls/{stable_url_id}. The referenced stable URLs must already exist (via CreateStableUrl) * `workspace_ids` (list of string) - Workspace IDs in this set. The system derives and validates regions. All workspaces must be in the Mission Critical tier ``` -------------------------------- ### Configure RFA Access Request Destinations for a Schema Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/rfa_access_request_destinations.md Example of configuring email, URL, Slack, Microsoft Teams, and generic webhook destinations for a schema. This setup ensures notifications reach the appropriate stakeholders for access requests. ```hcl resource "databricks_rfa_access_request_destinations" "customer_data_table" { destinations = [ { destination_id = "john.doe@databricks.com" destination_type = "EMAIL" }, { destination_id = "https://www.databricks.com/" destination_type = "URL" }, { destination_id = "456e7890-e89b-12d3-a456-426614174001" destination_type = "SLACK" }, { destination_id = "789e0123-e89b-12d3-a456-426614174002" destination_type = "MICROSOFT_TEAMS" }, { destination_id = "012e3456-e89b-12d3-a456-426614174003" destination_type = "GENERIC_WEBHOOK" } ] securable = { type = "SCHEMA" full_name = "main.customer_data" } are_any_destinations_hidden = false } ``` -------------------------------- ### Create Multiple Synced Tables and Bin Pack into One Pipeline Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/database_synced_database_table.md This example demonstrates creating two Synced Database Tables. The first defines a new pipeline, and the second reuses the pipeline ID from the first table for bin packing. ```hcl resource "databricks_database_instance" "instance" { name = "my-database-instance" capacity = "CU_1" } resource "databricks_database_synced_database_table" "synced_table_1" { name = "my_standard_catalog.public.synced_table1" # logical_database_name is required for synced tables created in # standard catalogs. logical_database_name = "databricks_postgres" # database instance name is required for synced tables created in # standard catalogs. database_instance_name = databricks_database_instance.instance.name spec = { scheduling_policy = "SNAPSHOT" source_table_full_name = "source_delta.tpch.customer" primary_key_columns = ["c_custkey"] create_database_objects_if_missing = true new_pipeline_spec = { storage_catalog = "source_delta" storage_schema = "tpch" } } } resource "databricks_database_synced_database_table" "synced_table_2" { name = "my_standard_catalog.public.synced_table2" # logical_database_name is required for synced tables created in # standard catalogs. logical_database_name = "databricks_postgres" # database instance name is required for synced tables created in # standard catalogs. database_instance_name = databricks_database_instance.instance.name spec = { scheduling_policy = "SNAPSHOT" source_table_full_name = "source_delta.tpch.customer" primary_key_columns = ["c_custkey"] create_database_objects_if_missing = true existing_pipeline_id = databricks_database_synced_database_table.synced_table_1.data_synchronization_status.pipeline_id } } ``` -------------------------------- ### Configure Default Catalog and Disable Legacy Features Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/disable_legacy_features_setting.md This example shows how to first set the default catalog to a value other than `hive_metastore` using `databricks_default_namespace_setting`, and then disable legacy features using `databricks_disable_legacy_features_setting`. This is a common setup for new workspaces. ```hcl resource "databricks_default_namespace_setting" "this" { namespace { value = "default_catalog" } } resource "databricks_disable_legacy_features_setting" "this" { disable_legacy_features { value = true } } ``` -------------------------------- ### Create and Grant Privileges to a Service Credential Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/grants.md This example shows how to create a service credential and then grant CREATE_CONNECTION privileges to a principal. ```hcl resource "databricks_credential" "external" { name = aws_iam_role.external_data_access.name aws_iam_role { role_arn = aws_iam_role.external_data_access.arn } purpose = "SERVICE" comment = "Managed by TF" } resource "databricks_grants" "external_creds" { credential = databricks_credential.external.id grant { principal = "Data Engineers" privileges = ["CREATE_CONNECTION"] } } ``` -------------------------------- ### Retrieve Databricks Tables and Grant Permissions Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/tables.md This example demonstrates how to use the databricks_tables data source to get a list of table IDs within a specific catalog and schema. It then iterates over these IDs to grant SELECT and MODIFY privileges to a 'sensitive' group on each table using the databricks_grants resource. ```hcl data "databricks_tables" "things" { catalog_name = "sandbox" schema_name = "things" } resource "databricks_grants" "things" { for_each = data.databricks_tables.things.ids table = each.value grant { principal = "sensitive" privileges = ["SELECT", "MODIFY"] } } ``` -------------------------------- ### Retrieve All Cluster Attributes Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/cluster.md This example demonstrates how to retrieve attributes for all SQL warehouses in a workspace. It first uses the `databricks_clusters` data source to get a list of all cluster IDs, and then iterates over these IDs using `for_each` to fetch detailed information for each cluster using the `databricks_cluster` data source. ```hcl data "databricks_clusters" "all" { } data "databricks_cluster" "all" { for_each = data.databricks_clusters.all.ids cluster_id = each.value } ``` -------------------------------- ### Pre-provisioning Regional Metastores Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/guides/unity-catalog-default.md Shows how to pre-create metastores in specific regions to ensure new workspaces are assigned to the correct, controlled metastore instead of an automatically provisioned one. ```hcl variable "regions" { default = ["ap-northeast-1", "eu-west-1"] } resource "databricks_metastore" "this" { for_each = toset(var.regions) name = "metastore-${each.value}" region = each.value } ``` -------------------------------- ### Terraform Example: Provisioning Cross-Account IAM Role Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/aws_assume_role_policy.md This Terraform configuration demonstrates how to provision a cross-account IAM role for Databricks using the `databricks_aws_assume_role_policy` and `databricks_aws_crossaccount_policy` data sources, along with AWS resources like `aws_iam_policy` and `aws_iam_role`. It also shows the setup for `databricks_mws_credentials` in a multi-workspace environment. ```hcl variable "databricks_account_id" { description = "Account Id that could be found in the top right corner of https://accounts.cloud.databricks.com/" } data "databricks_aws_crossaccount_policy" "this" {} resource "aws_iam_policy" "cross_account_policy" { name = "${var.prefix}-crossaccount-iam-policy" policy = data.databricks_aws_crossaccount_policy.this.json } data "databricks_aws_assume_role_policy" "this" { external_id = var.databricks_account_id } resource "aws_iam_role" "cross_account" { name = "${var.prefix}-crossaccount-iam-role" assume_role_policy = data.databricks_aws_assume_role_policy.this.json description = "Grants Databricks full access to VPC resources" } resource "aws_iam_role_policy_attachment" "cross_account" { policy_arn = aws_iam_policy.cross_account_policy.arn role = aws_iam_role.cross_account.name } // required only in case of multi-workspace setup resource "databricks_mws_credentials" "this" { provider = databricks.mws account_id = var.databricks_account_id credentials_name = "${var.prefix}-creds" role_arn = aws_iam_role.cross_account.arn } ``` -------------------------------- ### Get Databricks Node Type with GPU Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/node_type.md This example demonstrates how to use the databricks_node_type data source to find a node that meets specific criteria, including a minimum number of cores, a specific GB per core ratio, and at least one GPU. It's useful for configuring compute resources for GPU-intensive workloads. ```hcl data "databricks_node_type" "with_gpu" { local_disk = true min_cores = 16 gb_per_core = 1 min_gpus = 1 } data "databricks_spark_version" "gpu_ml" { gpu = true ml = true } resource "databricks_cluster" "research" { cluster_name = "Research Cluster" spark_version = data.databricks_spark_version.gpu_ml.id node_type_id = data.databricks_node_type.with_gpu.id autotermination_minutes = 20 autoscale { min_workers = 1 max_workers = 50 } } ``` -------------------------------- ### Example Usage of databricks_mws_workspaces Data Source Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/mws_workspaces.md This example demonstrates how to configure the Databricks provider at the account level and use the databricks_mws_workspaces data source to retrieve all workspace IDs. The retrieved IDs are then outputted. ```hcl provider "databricks" { // other configuration account_id = "" } data "databricks_mws_workspaces" "all" {} output "all_mws_workspaces" { value = data.databricks_mws_workspaces.all.ids } ``` -------------------------------- ### Retrieve Metastore Information via Terraform Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/metastore.md This example demonstrates how to create an S3 bucket and a Databricks metastore, then use the databricks_metastore data source to fetch and output the metastore's configuration details. ```hcl resource "aws_s3_bucket" "metastore" { bucket = "${var.prefix}-metastore" force_destroy = true } resource "databricks_metastore" "this" { provider = databricks.workspace name = "primary" storage_root = "s3://${aws_s3_bucket.metastore.id}/metastore" owner = var.unity_admin_group force_destroy = true } data "databricks_metastore" "this" { metastore_id = databricks_metastore.this.id } output "some_metastore" { value = data.databricks_metastore.this.metastore_info[0] } ``` -------------------------------- ### Install Python EGG Package (Deprecated) Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/library.md Installs a Python EGG package. This method is deprecated. It first uploads the EGG file to DBFS and then installs it as a library. ```hcl resource "databricks_dbfs_file" "app" { source = "${path.module}/foo.egg" path = "/FileStore/foo.egg" } resource "databricks_library" "app" { cluster_id = databricks_cluster.this.id egg = databricks_dbfs_file.app.dbfs_path } ``` -------------------------------- ### Create a Databricks Lakehouse Monitor (Snapshot) Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/lakehouse_monitor.md This example configures a snapshot Lakehouse Monitor. It requires the table name, assets directory, and output schema name. The `snapshot` block is empty, indicating a basic snapshot configuration. ```hcl resource "databricks_lakehouse_monitor" "testMonitorInference" { table_name = "${databricks_catalog.sandbox.name}.${databricks_schema.things.name}.${databricks_table.myTestTable.name}" assets_dir = "/Shared/provider-test/databricks_lakehouse_monitoring/${databricks_table.myTestTable.name}" output_schema_name = "${databricks_catalog.sandbox.name}.${databricks_schema.things.name}" snapshot {} } ``` -------------------------------- ### Create Service Principal with Administrative Permissions Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/service_principal.md This example shows how to create a service principal and assign it administrative permissions by adding it to the 'admins' group. ```hcl data "databricks_group" "admins" { display_name = "admins" } resource "databricks_service_principal" "sp" { display_name = "Admin SP" } resource "databricks_group_member" "i-am-admin" { group_id = data.databricks_group.admins.id member_id = databricks_service_principal.sp.id } ``` -------------------------------- ### Install CRAN Artifacts Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/cluster.md Install artifacts from CRAN. Optionally specify a 'repo' for a custom CRAN mirror. ```hcl library { cran { package = "rkeops" } } ``` -------------------------------- ### Example Usage of databricks_sql_dashboard Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/sql_dashboard.md This snippet shows how to create a new legacy SQL dashboard with a specified name and parent directory, and assign tags. ```hcl resource "databricks_directory" "shared_dir" { path = "/Shared/Dashboards" } resource "databricks_sql_dashboard" "d1" { name = "My Dashboard Name" parent = "folders/${databricks_directory.shared_dir.object_id}" tags = [ "some-tag", "another-tag", ] } ``` -------------------------------- ### databricks_secret_uc Resource Example Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/secret_uc.md This example demonstrates how to create a secret in Unity Catalog using the databricks_secret_uc resource. ```APIDOC ## databricks_secret_uc Resource ### Description The `databricks_secret_uc` resource allows you to manage secrets within Unity Catalog. Secrets are used to securely store sensitive information like credentials and API keys. ### Arguments * `catalog_name` (string, required) - The name of the catalog where the schema and the secret reside. * `name` (string, required) - The name of the secret, relative to its parent schema. * `schema_name` (string, required) - The name of the schema where the secret resides. * `value` (string, required) - The secret value to store. This field is input-only and is not returned in responses. The maximum size is 60 KiB. * `comment` (string, optional) - User-provided free-form text description of the secret. * `expire_time` (string, optional) - User-provided expiration time of the secret. This field is purely informational. * `owner` (string, optional) - The owner of the secret. Defaults to the creating principal on creation. * `provider_config` (ProviderConfig, optional) - Configure the provider for management through account provider. ### ProviderConfig * `workspace_id` (string, optional) - Workspace ID which the resource belongs to. This workspace must be part of the account which the provider is configured with. ### Attributes * `browse_only` (boolean) - Indicates whether the principal is limited to retrieving metadata for the associated object through the **BROWSE** privilege when **include_browse** is enabled in the request. * `create_time` (string) - The time at which this secret was created. * `created_by` (string) - The principal that created the secret. * `effective_owner` (string) - The effective owner of the secret. * `effective_value` (string) - The secret value. Only populated in responses when you have the **READ_SECRET** privilege and **include_value** is set to true in the request. * `external_secret_id` (string) * `full_name` (string) - The three-level (fully qualified) name of the secret, in the form of **catalog_name.schema_name.secret_name**. * `metastore_id` (string) - Unique identifier of the metastore hosting the secret. * `update_time` (string) - The time at which this secret was last updated. * `updated_by` (string) - The principal that last updated the secret. ### Example Usage ```hcl resource "databricks_secret_uc" "example" { catalog_name = "my_catalog" schema_name = "my_schema" secret { name = "my_secret" value = "secret_value" comment = "My secret for external service authentication" } } ``` ### Import ```hcl import { id = "full_name" to = databricks_secret_uc.this } ``` ```sh terraform import databricks_secret_uc.this "full_name" ``` ``` -------------------------------- ### databricks_disaster_recovery_stable_url Data Source Example Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/data-sources/disaster_recovery_stable_url.md Example of how to reference a stable URL using its resource name in Terraform. ```APIDOC ## databricks_disaster_recovery_stable_url Data Source This data source can be used to get a single stable URL by its fully qualified resource name. -> **Note** This data source can only be used with an account-level provider! ### Example Usage Referring to a stable URL by its resource name: ```hcl data "databricks_disaster_recovery_stable_url" "this" { name = "accounts/${var.account_id}/stable-urls/accounting-stable-url" } ``` ### Arguments The following arguments are supported: * `name` (string, required) - Fully qualified resource name. Format: accounts/{account_id}/stable-urls/{stable_url_id} ### Attributes The following attributes are exported: * `failover_group_name` (string) - Fully qualified resource name of the FailoverGroup this stable URL is currently linked to, in the format `accounts/{account_id}/failover-groups/{failover_group_id}`. Empty when the stable URL is not attached to any failover group * `initial_workspace_id` (string) - The workspace this stable URL is initially bound to. Used only in Create requests to associate the stable URL with a workspace. Not returned in responses * `name` (string) - Fully qualified resource name. Format: accounts/{account_id}/stable-urls/{stable_url_id} * `url` (string) - The stable URL endpoint. Generated on creation and immutable thereafter. For non-Private-Link workspaces this is `https:///?c=`. For Private-Link workspaces this is the per-connection hostname ``` -------------------------------- ### Install Python EGG Library (Deprecated) Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/cluster.md Install a Python EGG artifact on a Databricks cluster. This method is deprecated. ```hcl library { egg = "dbfs:/FileStore/foo.egg" } ``` -------------------------------- ### Creating a Delta Sharing share and add some existing tables to it Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/share.md This example demonstrates how to create a Delta Sharing share and add existing tables to it using the `databricks_share` resource and a `databricks_tables` data source. ```APIDOC ## databricks_share Resource - Example Usage ### Description Creates a Delta Sharing share and adds existing tables to it. ### Resource `databricks_share` ### Arguments * `name` - (Required) The name of the share. * `object` - (Required) A list of objects to include in the share. Each object can be a table, view, volume, or model. * `name` - (Required) The name of the object to share. * `data_object_type` - (Required) The type of the data object (e.g., "TABLE", "VOLUME"). * `shared_as` - (Optional) The name to use when sharing the object. * `string_shared_as` - (Optional) The name to use when sharing a volume. * `history_data_sharing_status` - (Optional) Enables or disables history data sharing for the object. * `partition` - (Optional) Specifies partitions to include in the share. * `value` - (Required) A list of partition values. * `name` - (Required) The name of the partition column. * `op` - (Required) The operator to use for the partition value (e.g., "EQUAL"). * `value` - (Required) The value of the partition. ### Example ```hcl data "databricks_tables" "things" { catalog_name = "sandbox" schema_name = "things" } resource "databricks_share" "some" { name = "my_share" dynamic "object" { for_each = data.databricks_tables.things.ids content { name = object.value data_object_type = "TABLE" } } } ``` ``` -------------------------------- ### Example Resource Models Source: https://github.com/databricks/terraform-provider-databricks/blob/main/CONTRIBUTING.md Defines Go structs for resource models, using JSON tags for serialization and TF tags for Terraform schema properties. ```go type Field struct { A string `json:"a,omitempty"` AMoreComplicatedName int `json:"a_more_complicated_name,omitempty"` } type Example struct { ID string `json:"id"` TheField *Field `json:"the_field"` AnotherField bool `json:"another_field"` Filters []string `json:"filters" tf:"optional"` } ``` -------------------------------- ### Databricks MLflow Model Permissions Example Source: https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/permissions.md Example of configuring MLflow model permissions and importing them using Terraform. ```hcl resource "databricks_mlflow_model" "model" { name = "example_model" description = "MLflow registered model" } resource "databricks_permissions" "model_usage" { registered_model_id = databricks_mlflow_model.model.registered_model_id access_control { group_name = "users" permission_level = "CAN_READ" } } ``` ```bash terraform import databricks_permissions.model_usage /registered-models/ ```