From 236dbc602d1f02b87c9bf7ad0beb255bd9f929be Mon Sep 17 00:00:00 2001 From: impactbee Date: Sun, 20 Apr 2025 15:23:46 -0500 Subject: [PATCH 1/3] Adding workspace infra statemigration to Terraform for AWS, GCP, and Azure. --- .../LICENSE.txt | 22 +++++++ .../NOTICE.txt | 17 ++++++ .../README.md | 15 +++++ .../aws/README.md | 34 +++++++++++ .../aws/bash.sh | 20 +++++++ .../aws/main.tf | 30 ++++++++++ .../aws/terraform.tfvars | 11 ++++ .../aws/variables.tf | 54 +++++++++++++++++ .../aws/versions.tf | 14 +++++ .../azure/README.md | 39 ++++++++++++ .../azure/bash.sh | 14 +++++ .../azure/main.tf | 25 ++++++++ .../azure/terraform.tfvars | 11 ++++ .../azure/variables.tf | 59 +++++++++++++++++++ .../azure/versions.tf | 14 +++++ .../gcp/README.md | 31 ++++++++++ .../gcp/bash.sh | 14 +++++ .../gcp/main.tf | 26 ++++++++ .../gcp/terraform.tfvars | 8 +++ .../gcp/variables.tf | 39 ++++++++++++ .../gcp/versions.tf | 13 ++++ 21 files changed, 510 insertions(+) create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/LICENSE.txt create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/NOTICE.txt create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/README.md create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/README.md create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/bash.sh create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/main.tf create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/terraform.tfvars create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/variables.tf create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/versions.tf create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/README.md create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/bash.sh create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/main.tf create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/terraform.tfvars create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/variables.tf create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/versions.tf create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/README.md create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/bash.sh create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/main.tf create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/terraform.tfvars create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/variables.tf create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/versions.tf diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/LICENSE.txt b/2025-04-managing-databricks-accounts-and-workspaces-with-code/LICENSE.txt new file mode 100644 index 0000000..e359785 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/LICENSE.txt @@ -0,0 +1,22 @@ +DB license +Definitions. + +Agreement: The agreement between Databricks, Inc., and you governing the use of the Databricks Services, as that term is defined in the Master Cloud Services Agreement (MCSA) located at www.databricks.com/legal/mcsa. + +Licensed Materials: The source code, object code, data, and/or other works to which this license applies. + +Scope of Use. You may not use the Licensed Materials except in connection with your use of the Databricks Services pursuant to the Agreement. Your use of the Licensed Materials must comply at all times with any restrictions applicable to the Databricks Services, generally, and must be used in accordance with any applicable documentation. You may view, use, copy, modify, publish, and/or distribute the Licensed Materials solely for the purposes of using the Licensed Materials within or connecting to the Databricks Services. If you do not agree to these terms, you may not view, use, copy, modify, publish, and/or distribute the Licensed Materials. + +Redistribution. You may redistribute and sublicense the Licensed Materials so long as all use is in compliance with these terms. In addition: + +You must give any other recipients a copy of this License; +You must cause any modified files to carry prominent notices stating that you changed the files; +You must retain, in any derivative works that you distribute, all copyright, patent, trademark, and attribution notices, excluding those notices that do not pertain to any part of the derivative works; and +If a "NOTICE" text file is provided as part of its distribution, then any derivative works that you distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the derivative works. +You may add your own copyright statement to your modifications and may provide additional license terms and conditions for use, reproduction, or distribution of your modifications, or for any such derivative works as a whole, provided your use, reproduction, and distribution of the Licensed Materials otherwise complies with the conditions stated in this License. + +Termination. This license terminates automatically upon your breach of these terms or upon the termination of your Agreement. Additionally, Databricks may terminate this license at any time on notice. Upon termination, you must permanently delete the Licensed Materials and all copies thereof. + +DISCLAIMER; LIMITATION OF LIABILITY. + +THE LICENSED MATERIALS ARE PROVIDED “AS-IS” AND WITH ALL FAULTS. DATABRICKS, ON BEHALF OF ITSELF AND ITS LICENSORS, SPECIFICALLY DISCLAIMS ALL WARRANTIES RELATING TO THE LICENSED MATERIALS, EXPRESS AND IMPLIED, INCLUDING, WITHOUT LIMITATION, IMPLIED WARRANTIES, CONDITIONS AND OTHER TERMS OF MERCHANTABILITY, SATISFACTORY QUALITY OR FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. DATABRICKS AND ITS LICENSORS TOTAL AGGREGATE LIABILITY RELATING TO OR ARISING OUT OF YOUR USE OF OR DATABRICKS’ PROVISIONING OF THE LICENSED MATERIALS SHALL BE LIMITED TO ONE THOUSAND ($1,000) DOLLARS. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE LICENSED MATERIALS OR THE USE OR OTHER DEALINGS IN THE LICENSED MATERIALS. \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/NOTICE.txt b/2025-04-managing-databricks-accounts-and-workspaces-with-code/NOTICE.txt new file mode 100644 index 0000000..b227381 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/NOTICE.txt @@ -0,0 +1,17 @@ +Copyright (2025) Databricks, Inc. + +This Software includes software developed at Databricks (https://www.databricks.com/) and its use is subject to the included LICENSE file. + +________________ +This Software contains code from the following open source projects, licensed under the Apache 2.0 license (https://www.apache.org/licenses/LICENSE-2.0): + +databricks/terraform-provider-databricks - https://github.com/databricks/terraform-provider-databricks +Copyright 2022 Databricks, Inc. All rights reserved. + +_____________ +This Software contains code from the following open source projects, licensed under the MPL License Agreement: + +hashicorp/terraform-provider-azurerm - https://github.com/hashicorp/terraform-provider-azurerm +Copyright © 2017- Hashicorp, Inc; All Rights Reserved +License - https://github.com/hashicorp/terraform-provider-azurerm/blob/main/LICENSE + diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/README.md b/2025-04-managing-databricks-accounts-and-workspaces-with-code/README.md new file mode 100644 index 0000000..21f881b --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/README.md @@ -0,0 +1,15 @@ +# Terraform Workspace Infrastucture Migration Guide + +## Overview + +This project contain templates can be used to migrate the current infrastructure details of a Databricks workspace into a Terraform project. [Blog post](https://community.databricks.com/t5/technical-blog/bg-p/technical-blog) + +- [AWS](https://github.com/databricks-solutions/databricks-blogposts/tree/main/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws) +- [Azure](https://github.com/databricks-solutions/databricks-blogposts/tree/main/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure) +- [GCP](https://github.com/databricks-solutions/databricks-blogposts/tree/main/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp) + + + + + + diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/README.md b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/README.md new file mode 100644 index 0000000..513a961 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/README.md @@ -0,0 +1,34 @@ +# Overview +This code example is based on this [Databricks Terraform workspace module](https://github.com/databricks/terraform-databricks-examples/blob/main/modules/aws-databricks-workspace/main.tf) and showcases the first step to migrating an existing workspace's infrastructure to Terraform. + + +If your workspace has features not included in this template, such as Private Link or Network Connnectivity Configurations, use the [Deployment section in the Databricks Terraform Provider's documentation](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/mws_workspaces#argument-reference)for the resource syntax to include. + +# Prerequistes +* Databricks Account Admin role and access to the account console. +* (Optional but recommended) A Databricks service principal with account admin role for authentication +* [Terraform CLI installed on your machine](https://developer.hashicorp.com/terraform/install) + + +# Instructions +* Configure Databricks Authentication. If using a service principal, generate an OAuth Token and add to your local .databrickcfg file. See the [documentation for details and alternative authenication methods](https://docs.databricks.com/aws/en/dev-tools/auth/oauth-m2m?language=Terraform). +* Fill out the variables in the terraform.tfvars file with values as specified below. +* Run `terraform init` in your terminal. +* Input variable values in bash.sh file and run `sh bash.sh` in your terminal. +* Run `terraform plan` in your terminal. You should receive a "No changes. Your infrastructure matches the configuration." message. + * Edit main.tf to match discrepanies if you get an execution plan instead. + +# Variables to inlcude in .tfvars file + +### From the Databricks account console +* databricks_account_id (string) - see upper right corner and click on the circular avatar +* workspace_name (string) - from workspace details +* region (string) - from workspace details +* network_name (string) - from network configuration +* vpc_id (string) - from network configuration +* security_group_ids list(string) - from network configuration +* vpc_private_subnets list(string) - from network configuration +* cross_account_role_arn (string) - from credential configuration +* credentials_name (string) - from credential configuration +* root_storage_bucket (string) - from storage credential +* storage_configuration_name (string) - from storage credential \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/bash.sh b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/bash.sh new file mode 100644 index 0000000..dc6240b --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/bash.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Define variables +databricks_account_id="" +storage_configuration_id="" +network_id="" +credentials_id="" +workspace_id="" + +# Run multiple import commands at once + +terraform import databricks_mws_credentials.this "${databricks_account_id}/${credentials_id}" +terraform import databricks_mws_networks.this "${databricks_account_id}/${network_id}" +terraform import databricks_mws_storage_configurations.this "${databricks_account_id}/${storage_configuration_id}" +terraform import databricks_mws_workspaces.this "${databricks_account_id}/${workspace_id}" + + +echo "Terraform import commands completed." + +chmod +x bash.sh \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/main.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/main.tf new file mode 100644 index 0000000..652bd3f --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/main.tf @@ -0,0 +1,30 @@ +resource "databricks_mws_credentials" "this" { + account_id = var.databricks_account_id + role_arn = var.cross_account_role_arn + credentials_name = var.credentials_name +} + +resource "databricks_mws_networks" "this" { + account_id = var.databricks_account_id + network_name = var.network_name + security_group_ids = var.security_group_ids + subnet_ids = var.vpc_private_subnets + vpc_id = var.vpc_id +} + +resource "databricks_mws_storage_configurations" "this" { + account_id = var.databricks_account_id + bucket_name = var.root_storage_bucket + storage_configuration_name = var.storage_configuration_name +} + +resource "databricks_mws_workspaces" "this" { + account_id = var.databricks_account_id + aws_region = var.region + workspace_name = var.workspace_name + + credentials_id = databricks_mws_credentials.this.credentials_id + storage_configuration_id = databricks_mws_storage_configurations.this.storage_configuration_id + network_id = databricks_mws_networks.this.network_id + +} \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/terraform.tfvars b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/terraform.tfvars new file mode 100644 index 0000000..67b2619 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/terraform.tfvars @@ -0,0 +1,11 @@ +region = "" +credentials_name = "" +cross_account_role_arn = "" +databricks_account_id = "" +network_name = "" +security_group_ids = [ "" ] +vpc_id = "" +vpc_private_subnets = [ "" ] +root_storage_bucket = "" +storage_configuration_name = "" +workspace_name = "" \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/variables.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/variables.tf new file mode 100644 index 0000000..1df3142 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/variables.tf @@ -0,0 +1,54 @@ +variable "workspace_name" { + type = string + description = "(Required) Workspace name" +} + +variable "region" { + type = string + description = "(Required) AWS region where the assets will be deployed" +} + +variable "vpc_id" { + type = string + description = "(Required) AWS VPC ID" +} + +variable "security_group_ids" { + type = list(string) + description = "(Required) List of VPC network security group IDs from Databricks Account Console" +} + +variable "vpc_private_subnets" { + type = list(string) + description = "(Required) AWS VPC Subnet IDs from Databricks account console" +} + +variable "databricks_account_id" { + type = string + description = "(Required) Databricks Account ID" +} + +variable "cross_account_role_arn" { + type = string + description = "(Required) AWS cross account role ARN from Databricks account console" +} + +variable "root_storage_bucket" { + type = string + description = "(Required) AWS root storage bucket" +} + +variable "credentials_name" { + type = string + description = "(Required) Credentials name from Databricks account console" +} + +variable "network_name" { + type = string + description = "(Required) Network name from Databricks account console" +} + +variable "storage_configuration_name" { + type = string + description = "(Required) Storage name from Databricks account console" +} \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/versions.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/versions.tf new file mode 100644 index 0000000..dfda60c --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/versions.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + databricks = { + source = "databricks/databricks" + version = ">=1.13.0" + } + + } +} + +provider "databricks" { + host = "https://accounts.cloud.databricks.com" + account_id = var.databricks_account_id +} diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/README.md b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/README.md new file mode 100644 index 0000000..9e79349 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/README.md @@ -0,0 +1,39 @@ +# Overview +This code example is based on this [Databricks Terraform workspace module](https://github.com/databricks/terraform-databricks-examples/tree/main/modules/adb-lakehouse) and showcases the first step to migrating an existing workspace's infrastructure to Terraform. + + +If your workspace has features not included in this template, such as Private Link or Customer-Managed Keys, use the [Deployment section in the Databricks Terraform Provider's documentation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/databricks_workspace)for the resource syntax to include. + +# Prerequistes +* Permissions to view the details of the Databricks workspace in the Azure Portal. +* Workspace admin role. +* (Optional but recommended) A Databricks service principal with workspace admin role for authentication. +* [Terraform CLI installed on your machine](https://developer.hashicorp.com/terraform/install). + + +# Instructions +* Configure [Azure authentication](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs#authenticating-to-azure). +* Review the main.tf file and include any additional configuration. +* Fill out the variables in the terraform.tfvars file with values as specified below. Include new values and variables if added in the previous step. +* Run `terraform init` in your terminal. +* Input variable values in bash.sh file and run `sh bash.sh` in your terminal. +* Run `terraform plan` in your terminal. You should receive a "No changes. Your infrastructure matches the configuration." message. + * Edit main.tf to match discrepanies if you get an execution plan instead. + + + +# Variables to inlcude in .tfvars file + +### From the Azure portal +* workspace_name (string) - from workspace overview +* resource_group_name (string) - from workspace overview +* location (string) - from workspace overview +* managed_resource_group_name (string) - from workspace overview +* sku_type (string) - from workspace overview (premium or standard) +* virtual_network_id (string) - resource ID from virtual network JSON view in the upper right corner +* private_subnet_name (string) - from virtual network subnet setting page +* public_subnet_name (string) - from virtual network subnet setting page +* public_subnet_id (string) - subnet ID from virtual network subnet setting details page +* private_subnet_id (string) - subnet ID from virtual network subnet setting details page +* nat_gateway_id (string) - resource ID from NAT gateway JSON view in the upper right corner + diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/bash.sh b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/bash.sh new file mode 100644 index 0000000..7b3aeac --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/bash.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Define variables +azure_workspace_resource_id="" +public_subnet_resource_id="" +private_subnet_resource_id= "" + +terraform import azurerm_databricks_workspace.this "${azure_workspace_resource_id}" +terraform import azurerm_subnet_nat_gateway_association.private "${private_subnet_resource_id}" +terraform import azurerm_subnet_nat_gateway_association.public "${public_subnet_resource_id}" + +echo "Terraform import commands completed." + +chmod +x bash.sh \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/main.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/main.tf new file mode 100644 index 0000000..68bdbb4 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/main.tf @@ -0,0 +1,25 @@ +resource "azurerm_databricks_workspace" "this" { + name = var.workspace_name + resource_group_name = var.resource_group_name + managed_resource_group_name = var.managed_resource_group_name + location = var.location + sku = var.sku_type + + custom_parameters { + + no_public_ip = true + virtual_network_id = var.virtual_network_id + private_subnet_name = var.private_subnet_name + public_subnet_name = var.public_subnet_name + } +} + +resource "azurerm_subnet_nat_gateway_association" "private" { + subnet_id = var.private_subnet_id + nat_gateway_id = var.nat_gateway_id +} + +resource "azurerm_subnet_nat_gateway_association" "public" { + subnet_id = var.public_subnet_id + nat_gateway_id = var.nat_gateway_id +} \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/terraform.tfvars b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/terraform.tfvars new file mode 100644 index 0000000..2a74818 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/terraform.tfvars @@ -0,0 +1,11 @@ +workspace_name = "" +resource_group_name = "" +managed_resource_group_name = "" +location = "" +sku_type = "" +virtual_network_id = "" +private_subnet_name = "" +public_subnet_name = "" +public_subnet_id = "" +private_subnet_id = "" +nat_gateway_id = "" diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/variables.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/variables.tf new file mode 100644 index 0000000..3fea30b --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/variables.tf @@ -0,0 +1,59 @@ +variable "workspace_name" { + type = string + default = "" + description = "(Required) Workspace Name for this module - if none are provided, the prefix will be used to name the workspace via coalesce()" +} + +variable "private_subnet_name" { + type = string + description = "(Required) Name of subnet for internal cluster communication" +} + +variable "public_subnet_name" { + type = string + description = "(Required Name of subnet for cluster host" +} + +variable "private_subnet_id" { + type = string + description = "(Required) Private subnet resource ID from Azure portal" +} + +variable "public_subnet_id" { + type = string + description = "(Required) Public subnet resource ID from Azure portal" +} + +variable "nat_gateway_id" { + type = string + description = "(Required) NAT Gateway resource ID from Azure portal" +} + +variable "virtual_network_id" { + type = string + description = "(Required) Virtual network resource ID from Azure portal" +} + +variable "sku_type" { + type = string + description = "(Required) Pricing tier from Azure Portal" + validation { + condition = contains(["premium", "standard"], var.sku_type) + error_message = "Invalid instance type. Allowed values are standard or premium." + } +} + +variable "location" { + type = string + description = "(Required) Databricks workspace region" +} + +variable "resource_group_name" { + type = string + description = "(Required) Resource group name from Azure Portal" +} + +variable "managed_resource_group_name" { + type = string + description = "(Required) Databricks managed resource group name from Azure Portal" +} diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/versions.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/versions.tf new file mode 100644 index 0000000..085898a --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/versions.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "=4.1.0" + } + } +} + +provider "azurerm" { + features {} + + subscription_id = "edd4cc45-85c7-4aec-8bf5-648062d519bf" +} \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/README.md b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/README.md new file mode 100644 index 0000000..3dbe587 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/README.md @@ -0,0 +1,31 @@ +# Overview +This code example is based on this [Databricks Terraform workspace module](https://registry.terraform.io/providers/databricks/databricks/latest/docs/guides/gcp-workspace#creating-a-databricks-workspace) and showcases the first step to migrating an existing workspace's infrastructure to Terraform. + + +If your workspace has features not included in this template, such as Private Link or Customer-Managed keys, use the [Deployment section in the Databricks Terraform Provider's documentation](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/mws_workspaces#argument-reference)for the resource syntax to include. + +# Prerequistes +* Databricks Account Admin role and access to the account console. +* (Optional but recommended) A Databricks service principal with account admin role for authentication +* [Terraform CLI installed on your machine](https://developer.hashicorp.com/terraform/install) + + +# Instructions +* Configure Databricks Authentication. If using a service principal, generate an OAuth Token and add to your local .databrickcfg file. See the [documentation for details and alternative authenication methods](https://docs.databricks.com/gcp/en/dev-tools/auth/oauth-m2m?language=Terraform). +* Fill out the variables in the terraform.tfvars file with values as specified below. +* Run `terraform init` in your terminal. +* Input variable values in bash.sh file and run `sh bash.sh` in your terminal. +* Run `terraform plan` in your terminal. You should receive a "No changes. Your infrastructure matches the configuration." message. + * Edit main.tf to match discrepanies if you get an execution plan instead. + +# Variables to inlcude in .tfvars file + +### From the Databricks account console +* databricks_account_id (string) - see upper right corner and click on the circular avatar +* workspace_name (string) - from workspace details +* subnet_region (string) - from network configuration +* network_name (string) - from network configuration +* vpc_id (string) - from network configuration +* subnet_name(string) - from network configuration +* workspace_google_project(string) - from workspace details +* network_google_project(string) - from network configuration \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/bash.sh b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/bash.sh new file mode 100644 index 0000000..c120c51 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/bash.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Define variables +databricks_account_id="" +network_id="" +workspace_id="" + + +terraform import databricks_mws_networks.this "${databricks_account_id}/${network_id}" +terraform import databricks_mws_workspaces.this "${databricks_account_id}/${workspace_id}" + +echo "Terraform import commands completed." + +chmod +x bash.sh \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/main.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/main.tf new file mode 100644 index 0000000..591f080 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/main.tf @@ -0,0 +1,26 @@ +// register VPC +resource "databricks_mws_networks" "this" { + account_id = var.databricks_account_id + network_name = var.network_name + gcp_network_info { + network_project_id = var.network_google_project + vpc_id = var.vpc_id + subnet_id = var.subnet_name + subnet_region = var.subnet_region + } +} + +// create workspace in given VPC +resource "databricks_mws_workspaces" "this" { + account_id = var.databricks_account_id + workspace_name = var.workspace_name + location = var.subnet_region + cloud_resource_container { + gcp { + project_id = var.workspace_google_project + } + } + + network_id = databricks_mws_networks.this.network_id + +} \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/terraform.tfvars b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/terraform.tfvars new file mode 100644 index 0000000..319efd4 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/terraform.tfvars @@ -0,0 +1,8 @@ +subnet_region = "" +databricks_account_id = "" +network_name = "" +vpc_id = "" +subnet_name = "" +network_google_project = "" +workspace_google_project= "" +workspace_name = "" \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/variables.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/variables.tf new file mode 100644 index 0000000..e00e4bc --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/variables.tf @@ -0,0 +1,39 @@ +variable "workspace_name" { + type = string + description = "(Required) Workspace name" +} + +variable "subnet_region" { + type = string + description = "(Required) GCP region where the assets will be deployed" +} + +variable "vpc_id" { + type = string + description = "(Required) GCP VPC ID" +} + +variable "subnet_name" { + type = string + description = "(Required) GCP VPC Subnet name from Databricks account console" +} + +variable "databricks_account_id" { + type = string + description = "(Required) Databricks Account ID" +} + +variable "network_name" { + type = string + description = "(Required) Network name from Databricks account console" +} + +variable "workspace_google_project" { + type = string + description = "(Required) The GCP Project ID from Databricks account console for workspace resources" +} + +variable "network_google_project" { + type = string + description = "(Required) The Network GCP Project ID from Databricks account console's network configuration page" +} \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/versions.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/versions.tf new file mode 100644 index 0000000..c6ca45a --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/versions.tf @@ -0,0 +1,13 @@ +terraform { + required_providers { + databricks = { + source = "databricks/databricks" + } + + } +} + +provider "databricks" { + host = "https://accounts.gcp.databricks.com" + account_id = var.databricks_account_id +} From 83492dfdec3f9e254c067788a0c9d83f08416de9 Mon Sep 17 00:00:00 2001 From: impactbee Date: Fri, 13 Jun 2025 02:46:24 -0500 Subject: [PATCH 2/3] Adding import blocks and clarfiying implementation instructions --- .../README.md | 8 ++--- .../aws/README.md | 34 +++++++++++-------- .../aws/import.tf | 19 +++++++++++ .../aws/main.tf | 1 - .../aws/terraform.tfvars | 18 ++++++---- .../aws/variables.tf | 20 +++++++++++ .../azure/README.md | 20 +++++------ .../azure/import.tf | 14 ++++++++ .../azure/terraform.tfvars | 6 ++-- .../azure/variables.tf | 15 ++++++-- .../azure/versions.tf | 2 +- .../gcp/README.md | 22 ++++++------ .../gcp/import.tf | 9 +++++ .../gcp/main.tf | 2 -- .../gcp/terraform.tfvars | 11 +++--- .../gcp/variables.tf | 10 ++++++ 16 files changed, 155 insertions(+), 56 deletions(-) create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/import.tf create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/import.tf create mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/import.tf diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/README.md b/2025-04-managing-databricks-accounts-and-workspaces-with-code/README.md index 21f881b..d9dcb7e 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/README.md +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/README.md @@ -2,11 +2,11 @@ ## Overview -This project contain templates can be used to migrate the current infrastructure details of a Databricks workspace into a Terraform project. [Blog post](https://community.databricks.com/t5/technical-blog/bg-p/technical-blog) +This project contain templates can be used to migrate the current infrastructure details of a Databricks workspace into a Terraform project. -- [AWS](https://github.com/databricks-solutions/databricks-blogposts/tree/main/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws) -- [Azure](https://github.com/databricks-solutions/databricks-blogposts/tree/main/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure) -- [GCP](https://github.com/databricks-solutions/databricks-blogposts/tree/main/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp) +- [AWS](aws/README.md) +- [Azure](azure/README.md) +- [GCP](gcp/README.md) diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/README.md b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/README.md index 513a961..26d6e2e 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/README.md +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/README.md @@ -14,21 +14,27 @@ If your workspace has features not included in this template, such as Private Li * Configure Databricks Authentication. If using a service principal, generate an OAuth Token and add to your local .databrickcfg file. See the [documentation for details and alternative authenication methods](https://docs.databricks.com/aws/en/dev-tools/auth/oauth-m2m?language=Terraform). * Fill out the variables in the terraform.tfvars file with values as specified below. * Run `terraform init` in your terminal. -* Input variable values in bash.sh file and run `sh bash.sh` in your terminal. -* Run `terraform plan` in your terminal. You should receive a "No changes. Your infrastructure matches the configuration." message. - * Edit main.tf to match discrepanies if you get an execution plan instead. +* Run `terraform plan` in your terminal. You should receive a "Plan: (# of resources added to main.tf) to import, 0 to add, 0 to change, 0 to destroy." message. + +* Run `terraform apply` in your terminal to import the current state of your workspace configuration. # Variables to inlcude in .tfvars file ### From the Databricks account console -* databricks_account_id (string) - see upper right corner and click on the circular avatar -* workspace_name (string) - from workspace details -* region (string) - from workspace details -* network_name (string) - from network configuration -* vpc_id (string) - from network configuration -* security_group_ids list(string) - from network configuration -* vpc_private_subnets list(string) - from network configuration -* cross_account_role_arn (string) - from credential configuration -* credentials_name (string) - from credential configuration -* root_storage_bucket (string) - from storage credential -* storage_configuration_name (string) - from storage credential \ No newline at end of file +* databricks_account_id (string) - see upper right corner and click on the circular avatar. +* workspace_name (string) - from workspace details page. +* region (string) - from the region section in the workspace details page. +* network_name (string) - from network configuration page. Click on the link in the network section of the workspace details page. +* network_id (string) - from network configuration page URL. Click on the link in the network section of the workspace details page. This is the uuid after network-configurations/ +* vpc_id (string) - from network configuration page. Click on the link in the network section of the workspace details page. +* vpc_private_subnets list(string) - from network configuration page. Click on the link in the network section of the workspace details page. +* security_group_ids list(string) - from network configuration page. Click on the link in the network section of the workspace details page. +* cross_account_role_arn (string) - from credential configuration page. Click on the link in the credentials section of the workspace details page. +* credentials_name (string) - from credential configuration page. Click on the link in the credentials section of the workspace details page. +* credentials_id (string) - from credential configuration page URL. Click on the link in the credentials section of the workspace details page. This is the uuid after credential-configurations/ +* root_storage_bucket (string) - bucket name from storage configuration page. Click on the link in the storage section of the workspace details page. +* storage_configuration_name (string) - name from storage configuration page. Click on the link in the storage section of the workspace details page. +* storage_configuration_id (string) - from storage configuration page URL. Click on the link in the storage section of the workspace details page. This is the uuid after storage-configurations/ + +### From the workspace +* workspace_id (string) - 16 digit number from workspace URL after o= diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/import.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/import.tf new file mode 100644 index 0000000..4a20475 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/import.tf @@ -0,0 +1,19 @@ +import { + to = databricks_mws_credentials.this + id = "${var.databricks_account_id}/${var.credentials_id}" +} + +import { + to = databricks_mws_networks.this + id = "${var.databricks_account_id}/${var.network_id}" +} + +import { + to = databricks_mws_storage_configurations.this + id = "${var.databricks_account_id}/${var.storage_configuration_id}" +} + +import { + to = databricks_mws_workspaces.this + id = "${var.databricks_account_id}/${var.workspace_id}" +} diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/main.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/main.tf index 652bd3f..da62edd 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/main.tf +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/main.tf @@ -1,5 +1,4 @@ resource "databricks_mws_credentials" "this" { - account_id = var.databricks_account_id role_arn = var.cross_account_role_arn credentials_name = var.credentials_name } diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/terraform.tfvars b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/terraform.tfvars index 67b2619..c0240bc 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/terraform.tfvars +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/terraform.tfvars @@ -1,11 +1,17 @@ -region = "" -credentials_name = "" -cross_account_role_arn = "" databricks_account_id = "" +workspace_name = "" +workspace_id = "" +region = "" network_name = "" -security_group_ids = [ "" ] +network_id = "" vpc_id = "" -vpc_private_subnets = [ "" ] +vpc_private_subnets = [ "", "" ] +security_group_ids = [ "" ] +cross_account_role_arn = "" +credentials_name = "" +credentials_id = "" + + root_storage_bucket = "" storage_configuration_name = "" -workspace_name = "" \ No newline at end of file +storage_configuration_id = "" \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/variables.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/variables.tf index 1df3142..05cf9a6 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/variables.tf +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/variables.tf @@ -3,6 +3,11 @@ variable "workspace_name" { description = "(Required) Workspace name" } +variable "workspace_id" { + type = string + description = "(Required) Workspace ID" +} + variable "region" { type = string description = "(Required) AWS region where the assets will be deployed" @@ -43,12 +48,27 @@ variable "credentials_name" { description = "(Required) Credentials name from Databricks account console" } +variable "credentials_id" { + type = string + description = "(Required) Credentials ID from Databricks account console" +} + variable "network_name" { type = string description = "(Required) Network name from Databricks account console" } +variable "network_id" { + type = string + description = "(Required) Network configuration ID from Databricks account console" +} + variable "storage_configuration_name" { type = string description = "(Required) Storage name from Databricks account console" +} + +variable "storage_configuration_id" { + type = string + description = "(Required) Storage configuration name from Databricks account console" } \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/README.md b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/README.md index 9e79349..ef571f5 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/README.md +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/README.md @@ -16,9 +16,8 @@ If your workspace has features not included in this template, such as Private Li * Review the main.tf file and include any additional configuration. * Fill out the variables in the terraform.tfvars file with values as specified below. Include new values and variables if added in the previous step. * Run `terraform init` in your terminal. -* Input variable values in bash.sh file and run `sh bash.sh` in your terminal. -* Run `terraform plan` in your terminal. You should receive a "No changes. Your infrastructure matches the configuration." message. - * Edit main.tf to match discrepanies if you get an execution plan instead. +* Run `terraform plan` in your terminal. You should receive a "Plan: (# of resources added to main.tf) to import, 0 to add, 0 to change, 0 to destroy." message. +* Run `terraform apply` in your terminal to import the current state of your workspace configuration. @@ -26,14 +25,15 @@ If your workspace has features not included in this template, such as Private Li ### From the Azure portal * workspace_name (string) - from workspace overview +* workspace_id (string) - resource ID from workspace overview JSON view in the upper right corner. * resource_group_name (string) - from workspace overview * location (string) - from workspace overview * managed_resource_group_name (string) - from workspace overview -* sku_type (string) - from workspace overview (premium or standard) -* virtual_network_id (string) - resource ID from virtual network JSON view in the upper right corner -* private_subnet_name (string) - from virtual network subnet setting page -* public_subnet_name (string) - from virtual network subnet setting page -* public_subnet_id (string) - subnet ID from virtual network subnet setting details page -* private_subnet_id (string) - subnet ID from virtual network subnet setting details page -* nat_gateway_id (string) - resource ID from NAT gateway JSON view in the upper right corner +* sku_type (string) - pricing tier from workspace overview (premium or standard) +* virtual_network_id (string) - resource ID from virtual network JSON view in the upper right corner. Click on the virtual network link in workspace overview page to find the virtual network attached to the workspace. +* private_subnet_name (string) - from workspace overview page. Click on see more if not visible +* public_subnet_name (string) - from workspace overview page. Click on see more if not visible +* public_subnet_id (string) - subnet ID from virtual network subnet setting details page. Click on the subnet link in the workspace overview page and then click on the subnet name to access the subnet setting details page. +* private_subnet_id (string) - subnet ID from virtual network subnet setting details page. Click on the subnet link in the workspace overview page and then click on the subnet name to access the subnet setting details page. +* nat_gateway_id (string) - resource ID from NAT gateway JSON view in the upper right corner. Find the NAT gateway on the subnet settings page in the security section. diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/import.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/import.tf new file mode 100644 index 0000000..9e8fb1e --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/import.tf @@ -0,0 +1,14 @@ +import { + to = azurerm_databricks_workspace.this + id = var.workspace_id +} + +import { + to = azurerm_subnet_nat_gateway_association.private + id = var.private_subnet_id +} + +import { + to = azurerm_subnet_nat_gateway_association.public + id = var.public_subnet_id +} diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/terraform.tfvars b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/terraform.tfvars index 2a74818..f105cc7 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/terraform.tfvars +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/terraform.tfvars @@ -1,11 +1,13 @@ workspace_name = "" +workspace_id = "" resource_group_name = "" managed_resource_group_name = "" location = "" sku_type = "" virtual_network_id = "" private_subnet_name = "" +private_subnet_id = "" public_subnet_name = "" public_subnet_id = "" -private_subnet_id = "" -nat_gateway_id = "" +nat_gateway_id = "" +subscription_id = "" diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/variables.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/variables.tf index 3fea30b..6870ccc 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/variables.tf +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/variables.tf @@ -1,9 +1,14 @@ variable "workspace_name" { type = string - default = "" - description = "(Required) Workspace Name for this module - if none are provided, the prefix will be used to name the workspace via coalesce()" + description = "(Required) Workspace Name" } +variable "workspace_id" { + type = string + description = "(Required) Workspace ID from the URL" +} + + variable "private_subnet_name" { type = string description = "(Required) Name of subnet for internal cluster communication" @@ -57,3 +62,9 @@ variable "managed_resource_group_name" { type = string description = "(Required) Databricks managed resource group name from Azure Portal" } + + +variable "subscription_id" { + type = string + description = "(Required) subscription ID from Azure Portal" +} diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/versions.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/versions.tf index 085898a..b9a7e8b 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/versions.tf +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/versions.tf @@ -10,5 +10,5 @@ terraform { provider "azurerm" { features {} - subscription_id = "edd4cc45-85c7-4aec-8bf5-648062d519bf" + subscription_id = var.subscription_id } \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/README.md b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/README.md index 3dbe587..b271e44 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/README.md +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/README.md @@ -14,18 +14,20 @@ If your workspace has features not included in this template, such as Private Li * Configure Databricks Authentication. If using a service principal, generate an OAuth Token and add to your local .databrickcfg file. See the [documentation for details and alternative authenication methods](https://docs.databricks.com/gcp/en/dev-tools/auth/oauth-m2m?language=Terraform). * Fill out the variables in the terraform.tfvars file with values as specified below. * Run `terraform init` in your terminal. -* Input variable values in bash.sh file and run `sh bash.sh` in your terminal. -* Run `terraform plan` in your terminal. You should receive a "No changes. Your infrastructure matches the configuration." message. - * Edit main.tf to match discrepanies if you get an execution plan instead. +* Run `terraform plan` in your terminal. You should receive a "Plan: (# of resources added to main.tf) to import, 0 to add, 0 to change, 0 to destroy." message. +* Run `terraform apply` in your terminal to import the current state of your workspace configuration. # Variables to inlcude in .tfvars file ### From the Databricks account console * databricks_account_id (string) - see upper right corner and click on the circular avatar -* workspace_name (string) - from workspace details -* subnet_region (string) - from network configuration -* network_name (string) - from network configuration -* vpc_id (string) - from network configuration -* subnet_name(string) - from network configuration -* workspace_google_project(string) - from workspace details -* network_google_project(string) - from network configuration \ No newline at end of file +* workspace_name (string) - from workspace details page +* workspace_id (string) - from URL in workspace details page. This is the number after https://. Alternatively, you can find the workspace id by clicking on the URL. it's the number after o=/ +* workspace_google_project(string) - from workspace details page. This is the Google Cloud Project ID. +* network_id (string) - from network configuration page URL. Click on the link in the network section of the workspace details page. This is the uuid after network-configurations/ +* network_name (string) - from network configuration page. Click on the link in the network section of the workspace details page. +* vpc_id (string) - from network configuration page. Click on the link in the network section of the workspace details page. +* network_google_project(string) - from network configuration page. Click on the link in the network section of the workspace details page. +* subnet_name(string) - from network configuration page. Click on the link in the network section of the workspace details page. +* subnet_region (string) - from network configuration page. Click on the link in the network section of the workspace details page. + diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/import.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/import.tf new file mode 100644 index 0000000..65149a2 --- /dev/null +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/import.tf @@ -0,0 +1,9 @@ +import { + to = databricks_mws_networks.this + id = "${var.databricks_account_id}/${var.network_id}" +} + +import { + to = databricks_mws_workspaces.this + id = "${var.databricks_account_id}/${var.workspace_id}" +} \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/main.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/main.tf index 591f080..b653d20 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/main.tf +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/main.tf @@ -1,4 +1,3 @@ -// register VPC resource "databricks_mws_networks" "this" { account_id = var.databricks_account_id network_name = var.network_name @@ -10,7 +9,6 @@ resource "databricks_mws_networks" "this" { } } -// create workspace in given VPC resource "databricks_mws_workspaces" "this" { account_id = var.databricks_account_id workspace_name = var.workspace_name diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/terraform.tfvars b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/terraform.tfvars index 319efd4..f885ed7 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/terraform.tfvars +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/terraform.tfvars @@ -1,8 +1,11 @@ -subnet_region = "" databricks_account_id = "" +workspace_name = "" +workspace_id = "" +workspace_google_project= "" +network_id = "" network_name = "" vpc_id = "" -subnet_name = "" network_google_project = "" -workspace_google_project= "" -workspace_name = "" \ No newline at end of file +subnet_name = "" +subnet_region = "" + diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/variables.tf b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/variables.tf index e00e4bc..89e99d0 100644 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/variables.tf +++ b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/variables.tf @@ -3,6 +3,11 @@ variable "workspace_name" { description = "(Required) Workspace name" } +variable "workspace_id" { + type = string + description = "(Required) Workspace ID from URL" +} + variable "subnet_region" { type = string description = "(Required) GCP region where the assets will be deployed" @@ -28,6 +33,11 @@ variable "network_name" { description = "(Required) Network name from Databricks account console" } +variable "network_id" { + type = string + description = "(Required) Network ID from Databricks account console" +} + variable "workspace_google_project" { type = string description = "(Required) The GCP Project ID from Databricks account console for workspace resources" From 62f51f6459d3b75003357d91faead2e1b70223ac Mon Sep 17 00:00:00 2001 From: Eri Adepoju Date: Fri, 13 Jun 2025 01:34:51 -0700 Subject: [PATCH 3/3] Deleting the bash scripts --- .../aws/bash.sh | 20 ------------------- .../azure/bash.sh | 14 ------------- .../gcp/bash.sh | 14 ------------- 3 files changed, 48 deletions(-) delete mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/bash.sh delete mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/bash.sh delete mode 100644 2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/bash.sh diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/bash.sh b/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/bash.sh deleted file mode 100644 index dc6240b..0000000 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/aws/bash.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Define variables -databricks_account_id="" -storage_configuration_id="" -network_id="" -credentials_id="" -workspace_id="" - -# Run multiple import commands at once - -terraform import databricks_mws_credentials.this "${databricks_account_id}/${credentials_id}" -terraform import databricks_mws_networks.this "${databricks_account_id}/${network_id}" -terraform import databricks_mws_storage_configurations.this "${databricks_account_id}/${storage_configuration_id}" -terraform import databricks_mws_workspaces.this "${databricks_account_id}/${workspace_id}" - - -echo "Terraform import commands completed." - -chmod +x bash.sh \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/bash.sh b/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/bash.sh deleted file mode 100644 index 7b3aeac..0000000 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/azure/bash.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Define variables -azure_workspace_resource_id="" -public_subnet_resource_id="" -private_subnet_resource_id= "" - -terraform import azurerm_databricks_workspace.this "${azure_workspace_resource_id}" -terraform import azurerm_subnet_nat_gateway_association.private "${private_subnet_resource_id}" -terraform import azurerm_subnet_nat_gateway_association.public "${public_subnet_resource_id}" - -echo "Terraform import commands completed." - -chmod +x bash.sh \ No newline at end of file diff --git a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/bash.sh b/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/bash.sh deleted file mode 100644 index c120c51..0000000 --- a/2025-04-managing-databricks-accounts-and-workspaces-with-code/gcp/bash.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Define variables -databricks_account_id="" -network_id="" -workspace_id="" - - -terraform import databricks_mws_networks.this "${databricks_account_id}/${network_id}" -terraform import databricks_mws_workspaces.this "${databricks_account_id}/${workspace_id}" - -echo "Terraform import commands completed." - -chmod +x bash.sh \ No newline at end of file