我正在尝试使用 terraform 创建 Google 云 sql 表。
但是,似乎只能通过 terraform 创建 google cloud sql 实例和 sql 数据库,并且使用 cloudshell 我们可以创建 sql 表。
但我尝试仅使用 terraform 创建表,无论是直接使用 terraform 脚本中的 sql 脚本,还是仅从 terraform 脚本中引用 sql 脚本,这些 sql 脚本将存储在某个位置,例如云存储。
任何相关的线索/建议都会非常有帮助。
提前致谢。
最佳答案
您可以尝试Provisioners
这是 Postgres 的一个简单示例
resource "google_sql_database_instance" "default" {
[...]
provisioner "local-exec" {
command = "PGPASSWORD=<password> psql -f schema.sql -p <port> -U <username> <databasename>"
}
}
Provisioners can be used to model specific actions on the local machine or on a remote machine in order to prepare servers or other infrastructure objects for service.
schema.sql 将保存您的表定义。
您也可以用同样的方式为 MySQL 更新此命令。确保您的本地或 CI/CD 计算机安装了 MySQL cli,以便从那里它将连接到数据库实例并创建表。
关于google-cloud-platform - 使用 Terraform 创建 Google Cloud sql 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70492187/