使用 terraform 添加 azure SQL 用户 [英] Add azure SQL user with terraform

查看:31
本文介绍了使用 terraform 添加 azure SQL 用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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/

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

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

谢谢

推荐答案

是的,如果这是您想要发生的事情,您可以从 Terraform 进行.我会在 Terraform 中使用 null 资源 提供程序来执行来自运行 Terraform 的框.您可以在创建数据库后使用 PowerShell、CMD 等连接到数据库并创建您的用户帐户.这是一个示例,说明如何使用空资源提供程序.

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.

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

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

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

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

这篇关于使用 terraform 添加 azure SQL 用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆