Provision a Database and Import a SQL File for initialization
This tutorial will talk about how to provision a relational database with SQL file imported, and bootstrap an application which depends on the database.
Favorite Links is an interesting project which can store all
your favorite web links in one application. It is using Node.js and MySQL. It has been built into a container image
oamdev/nodejs-mysql-links:v0.0.1
. Let's bootstrap the application and see how to provision a database, and import a SQL
file (which means to create tables, and insert data into them if needed).
Currently, it only works on Alibaba Cloud ComponentDefinition alibaba-rds-preview is the feature preview for Alibaba Cloud RDS, and will be merged into alibaba-rds later.
#
How it worksFeel free to skip this section if you are not interested.
Alibaba Cloud RDS Preview supports importing SQL file when create an RDS instance with these properties:
Name | Description | Type | Required | Default |
---|---|---|---|---|
sql_file | The name of SQL file in the bucket, like db.sql | string | false | |
sql_bucket_name | The bucket name of the SQL file. like oss://example | string | false | |
sql_bucket_endpoint | The endpoint of the bucket. like oss-cn-hangzhou.aliyuncs.com | string | false |
After an RDS database is created, the SQL file from OSS bucket will be imported into the database by the power of Terraform
local-exec
provisioner
which is referenced by Alibaba Cloud RDS Preview ComponentDefinition.
#
PrerequisitesEnable addon terraform-alibaba
Remember to store the SQL file in an Alibaba Cloud OSS bucket
Let's say we have an OSS bucket oss://favorite-links
which contains a SQL file db.sql
in it, and the bucket endpoint
is oss-cn-hongkong.aliyuncs.com
.
#
Provision cloud resourcesUse the following Application to provision a database links
, import the SQL file db.sql
, and bootstrap the application
Favorite Links.
After the application is successfully deployed, you can access the web application by the following URL: