Reputation: 763
I'm using Terraform with the AWS provider (v3.37.0) to create an RDS instance:
resource "aws_db_instance" "rds" {
identifier = "my_db"
engine = "sqlserver-se"
engine_version = "14.00.3401.7.v1"
name = null
username = "${somewhere/in/ssm}"
password = "${somewhere/in/ssm}"
}
I wish to create a database alongside this RDS instance, so the documentation (https://registry.terraform.io/providers/hashicorp/aws/3.37.0/docs/resources/db_instance) states that I need to assign a value to the variable name
, which I cannot, since the engine that I'm using (SQL Server) doesn't support that.
Is there another way to create that database inside this instance within Terraform?
I was thinking of using the local-exec
provisioner or a community provider, but:
local-exec
provider, I don't know what I would put in the command. Would the following work, for example?resource "aws_db_instance" "rds" {
identifier = "my_db"
engine = "sqlserver-se"
engine_version = "14.00.3401.7.v1"
name = null
username = "${somewhere/in/ssm}"
password = "${somewhere/in/ssm}"
provisioner "local-exec" {
command = "USE master; CREATE DATABASE db-name"
}
}
Upvotes: 0
Views: 1208
Reputation: 238687
I don't know what I would put in the command
You need to use full mssql-cli
command (or any other programming interface to mssql) which will execute on your computer and create your database. This means you have to have it installed first. For example, you can develop a python script which will connect and create your database. Then you invoke the python script from your local-exec
.
Upvotes: 0