使用 terraform 添加 azure SQL 用户

Add azure SQL user with terraform

是否可以通过 terraform 将 sql 用户添加到 azure sql? https://www.mssqltips.com/sqlservertip/5242/adding-users-to-azure-sql-databases/

或者对于如何创建 SQL 用户有更好的建议吗?

谢谢

是的,如果您希望发生这种情况,您可以从 Terraform 执行此操作。我会使用 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 如何使用空资源提供程序。

我想它看起来像这样,在这个例子中我使用的是 SqlServer PowerShell 模块。

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"]
}

您当然可以使用我们的 CLI 工具来完成,但这将保证它是您 Terraform 部署的一部分。