我们已经使用 terraform-aws-rds-aurora Terraform 模块成功创建了 Aurora Serverless Cluster v2。现在,我们想在集群设置后运行初始化脚本来创建数据库并向用户授予权限。脚本如下:
-- Create databases
CREATE DATABASE IF NOT EXISTS db1;
CREATE DATABASE IF NOT EXISTS db2;
CREATE DATABASE IF NOT EXISTS db3;
-- Create user and grant permissions
CREATE USER 'user'@'localhost' IDENTIFIED BY 'userpass';
-- Grant permissions on db1
GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD, INDEX, LOCK TABLES ON db1.* TO 'user'@'localhost';
-- Grant permissions on db2
GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD, INDEX, LOCK TABLES ON db2.* TO 'user'@'localhost';
-- Grant permissions on db3
GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD, INDEX, LOCK TABLES ON db3.* TO 'user'@'localhost';
我们如何将此初始化脚本的执行集成到我们的 Terraform 代码中,特别是在设置 Aurora Serverless Cluster v2 之后?是否有任何 Terraform 资源或模块可以帮助实现这一点?