cancel
Showing results for 
Search instead for 
Did you mean: 
Administration & Architecture
Explore discussions on Databricks administration, deployment strategies, and architectural best practices. Connect with administrators and architects to optimize your Databricks environment for performance, scalability, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 

Enforcing Tags on SQL Warehouses

Michael_Appiah
Contributor II

Is there a way to enforce tags on SQL Warehouses? Regular cluster policies do not apply to SQL Warehouses and budget policies do not cover SQL Warehouses either, which I find quite surprising given the fact that budget policies are documented as "Attribute serverless usage with budget policies". I would have expected that to cover serverless SQL Warehouses as well, but the docs only describe how to use budget policies with serverless Notebooks, Jobs, Pipelines and Endpoints but not serverless SQL Warehouses. Is there a way or workaround to enforce tags on SQL Warehouses?

 

1 ACCEPTED SOLUTION

Accepted Solutions

nayan_wylde
Honored Contributor II

@Michael_Appiah Yes the default tag policies doesn't apply on warehouse. The solution that I can recommend is assign a tag block if you are deploying using terraform, asset bundle etc to deploy the warehouse. The other solution that I use is I run a notebook using SDK that list all warehouses and checks if the tags are present if not it will assign tags. 

from databricks.sdk import WorkspaceClient

# Initialize the workspace client
w = WorkspaceClient()

# Define the default tags to apply
default_tags = {
    "owner": "",
    "team": "",
    "environment": "production"
}

# List all SQL warehouses
warehouses = w.warehouses.list()

# Loop through and update warehouses without tags
for warehouse in warehouses:
    if not warehouse.tags:  # Check if tags are missing or empty
        print(f"Updating warehouse: {warehouse.name} (ID: {warehouse.id})")
        w.warehouses.edit(
            id=warehouse.id,
            tags=default_tags
        )
    else:
        print(f"Warehouse already has tags: {warehouse.name} (ID: {warehouse.id})")

 

View solution in original post

7 REPLIES 7

kamal_ch
Databricks Employee
Databricks Employee

Hi Michael,

You can add tags using Advanced options when creating the Warehouse:

https://docs.databricks.com/aws/en/compute/sql-warehouse/create#advanced-options

Regards

Kamal

 

Hi @kamal_ch 

thanks for your answer. I understand that tags can be added under the "advanced options" when creating the warehouse. But how can I enforce that every developer sets specific tags when creating warehouses?
So I basically what I am looking for is almost like a compute policy for SQL warehouses which allows admins to enforce that tags must be set when creating a new SQL warehouse. Is there a way to do this today or is there anything on the roadmap?

Regards

Michael

Michael_Appiah
Contributor II

Hi @kamal_ch , 

thanks for your answer. I am aware that tags can be added. However, I want to enforce that warehouses cannot be created without adding tags. The goal is to allow users to create warehouses while making sure they are properly tagged. So like when using cluster policies which allow you to enforce that tags are added to new compute resources users create. Unfortunately I havent found any option to enforce tagging of SQL warehouses. Do you know of any ways to do that?

BS_THE_ANALYST
Esteemed Contributor

@Michael_Appiah this isn't any area I'm familiar with but I thought I'd try and get the ball rolling. 

Have you looked into this https://docs.databricks.com/aws/en/admin/clusters/policy-definition . It could be a red herring from me, but your article is looking at budget policies, whereas this is cluster policies. Perhaps these are kinder to SQL warehouses.

BS_THE_ANALYST_0-1756118038219.png

 

It looks, to me at least (I'm probably being naive), that there's some padlocks on these icons, perhaps this means they can be fixed. Perhaps this can be driven from the user dynamically?

There's a cool parameter: 

BS_THE_ANALYST_1-1756118142683.png

 Could use that for cost centre etc?

BS_THE_ANALYST_2-1756118207335.png

Hopefully that's useful! Not my area of expertise but always happy to have a stab at it 🤣.

All the best,
BS

Hi @BS_THE_ANALYST ,

thanks for your answer and for "having a stab at it" 😄 

I'm aware of cluster policies. The issue is that currently cluster policies cannot be applied to SQL warehouses only to job and all-purpose clusters. I would need cluster policies to cover SQL warehouses as well so that I can enforce tagging on SQL warehouses. The information that I have been able to get from Databricks now, is that they are aware of the issue and are lookgin into it. So hopefully, we can get to see something on the roadmap soon. 

Cheers
Michael

nayan_wylde
Honored Contributor II

@Michael_Appiah Yes the default tag policies doesn't apply on warehouse. The solution that I can recommend is assign a tag block if you are deploying using terraform, asset bundle etc to deploy the warehouse. The other solution that I use is I run a notebook using SDK that list all warehouses and checks if the tags are present if not it will assign tags. 

from databricks.sdk import WorkspaceClient

# Initialize the workspace client
w = WorkspaceClient()

# Define the default tags to apply
default_tags = {
    "owner": "",
    "team": "",
    "environment": "production"
}

# List all SQL warehouses
warehouses = w.warehouses.list()

# Loop through and update warehouses without tags
for warehouse in warehouses:
    if not warehouse.tags:  # Check if tags are missing or empty
        print(f"Updating warehouse: {warehouse.name} (ID: {warehouse.id})")
        w.warehouses.edit(
            id=warehouse.id,
            tags=default_tags
        )
    else:
        print(f"Warehouse already has tags: {warehouse.name} (ID: {warehouse.id})")

 

Hi @nayan_wylde ,

thanks for the input. I think that is a good workaround until tags on warehouses can be enforced natively.
I appreciate it. 

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now