How to Grant Access to Azure SQL Databases Using Entra ID and Terraform?

0
8
Asked By TechieSparkle29 On

Hi folks! I'm currently setting up Azure SQL Server and databases and need some help with permissions. I've designated an Entra ID group as the admin for my SQL Server and created five databases inside it using Terraform. Now, I want to give access to another Entra ID group that isn't the admin group to these databases.

My main questions are:
1. Can I do this through Azure IAM/RBAC?
2. I want to automate the access configuration with Terraform, but my Terraform service principal isn't part of the admin group. I checked the Azure RBAC roles, but none seem to suit database-level access. Also, just to make sure I'm clear, being an admin of the SQL Server doesn't automatically grant access to the individual databases, correct? Any suggestions would be really helpful!

2 Answers

Answered By CloudNinja42 On

You might consider using a bacpac file stored in blob storage for your database setup, which can help manage permissions. Alternatively, using an automation runbook that connects to the database and adjusts permissions could work too—just make sure the automation's managed identity is part of the admin group.

DevGuru8 -

This sounds like a solid plan! Keeping your database schema and security settings under source control and deploying via CI/CD is definitely a best practice.

Answered By CodeMaster77 On

You can't manage database-level permissions in Azure SQL using RBAC or Terraform. Instead, you have to do this using T-SQL commands, which can be triggered through PowerShell if needed. Also, yes, while the server admin has full access to all databases, remember that the 'owner' role in RBAC is tied to just the server resource itself, not the databases within it. Just keep that in mind!

CuriousDev14 -

Thanks for clarifying! So, if I want my Terraform service principal to execute those T-SQL commands, I'd need to give it admin rights on the SQL Server, right? Seems limiting having only one admin group!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.