examples/jamstack: implemented database integration with RDS
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
41
examples/jamstack/database.cue
Normal file
41
examples/jamstack/database.cue
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"dagger.io/aws/rds"
|
||||
)
|
||||
|
||||
database: {
|
||||
let slug = name
|
||||
dbType: "mysql"
|
||||
|
||||
db: rds.#CreateDB & {
|
||||
config: infra.awsConfig
|
||||
name: slug
|
||||
dbArn: infra.rdsInstanceArn
|
||||
"dbType": dbType
|
||||
secretArn: infra.rdsAdminSecretArn
|
||||
}
|
||||
|
||||
user: rds.#CreateUser & {
|
||||
config: infra.awsConfig
|
||||
dbArn: infra.rdsInstanceArn
|
||||
"dbType": dbType
|
||||
secretArn: infra.rdsAdminSecretArn
|
||||
username: slug
|
||||
// FIXME: make it secure (generate infra side?)
|
||||
password: base64.Encode(null, "pwd-\(slug)")
|
||||
grantDatabase: db.out
|
||||
}
|
||||
|
||||
instance: rds.#Instance & {
|
||||
config: infra.awsConfig
|
||||
dbArn: infra.rdsInstanceArn
|
||||
}
|
||||
|
||||
hostname: instance.hostname
|
||||
port: instance.port
|
||||
dbName: db.out
|
||||
username: user.out
|
||||
password: user.password
|
||||
}
|
Reference in New Issue
Block a user