简体   繁体   English

部署 Azure SQL 数据对象 使用 Terraform 使用 Azure Devops CICD

[英]Deploy Azure SQL Data Objects Using Terraform using Azure Devops CICD

I have deployed Azure SQL Server and Database successfully using Terraform. Now I want to deploy SSDT File (all the objects in the existing database using Terraform.)我已经使用 Terraform 成功部署了 Azure SQL 服务器和数据库。现在我想部署 SSDT 文件(现有数据库中的所有对象使用 Terraform。)

I am unable to find.tf code to deploy below Database objects in Repository.我无法在存储库中的数据库对象下找到要部署的 find.tf 代码。

存储库中的数据库文件

You will not find such resource as this is not the scope of the Terraform. Howeer you can still do workaround and use null_resource你不会找到这样的资源,因为这不是 Terraform 的 scope。但是你仍然可以解决问题并使用null_resource

resource "null_resource" "database-initialization" {

  triggers = {
    filename_sha1 = "${sha1(file("filename.sql"))}"
  }

  provisioner "local-exec" {
    command = <<EOT

        sqlcmd -U $SQL_ADMIN_LOGIN -S ${data.azurerm_sql_server.sql.fqdn} -P $SQL_FOUNDATION_ADMIN_PASSWORD -d ${var.db_name} -i "filename.sql"
        
    EOT
  }
}

You can use in similar way sqlpackage to deploy for instance DACPAC.您可以以类似的方式使用 sqlpackage 来部署 DACPAC。 However, what you need to is calculate first hash of the files you want to run and use this as triggers it will cause to triggers resource each time when file is changed.但是,您需要首先计算要运行的文件的 hash,并将其用作触发器,每次更改文件时都会触发资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM