Add azure SQL user with terraform

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-30 03:50:49

问题


is there a possibility to add a sql user to the azure sql via terraform? https://www.mssqltips.com/sqlservertip/5242/adding-users-to-azure-sql-databases/

Or is there a better suggestions how to create a SQL user?

Thanks


回答1:


Yes you can do it from Terraform if that is what you want to happen. I would use a null resource provider in Terraform to execute the commands from the box that is running Terraform. You could use PowerShell, CMD, etc. to connect to the database after it is created and create your user account. Here is an example of how to use the null resource provider.

I would image it would look something like this, in this example I am using the SqlServer PowerShell module.

resource "null_resource" "create-sql-user" {

  provisioner "local-exec" {
    command = "Add-SqlLogin -LoginName ${var.loginName} -LoginType ${var.loginType}"
    interpreter = ["PowerShell", "-Command"]
  }

  depends_on = ["azurerm_sql_database.demo"]
}

You could of course do it with our CLI tools, but this would guarantee it is part of your Terraform deployment.



来源:https://stackoverflow.com/questions/54326033/add-azure-sql-user-with-terraform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!