Provision and Binding Database
tip
This section requires your platform engineers have already enabled terraform addon.
This tutorial will talk about how to provision and consume Alibaba Cloud RDS (and OSS) by Terraform.
Let’s deploy the application below to provision Alibaba Cloud OSS and RDS cloud resources, and consume them by the web component.
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: webappspec:components:- name: express-servertype: webserviceproperties:image: zzxwill/flask-web-application:v0.3.1-crossplaneport: 80traits:- type: service-bindingproperties:envMappings:# environments refer to db-conn secretDB_PASSWORD:secret: db-conn # 1) If the env name is the same as the secret key, secret key can be omitted.endpoint:secret: db-connkey: DB_PUBLIC_HOS # 2) If the env name is different from secret key, secret key has to be set.username:secret: db-connkey: DB_USER# environments refer to oss-conn secretBUCKET_NAME:secret: oss-conn- name: sample-dbtype: alibaba-rdsproperties:instance_name: sample-dbaccount_name: oamtestpassword: U34rfwefwefffakedwriteConnectionSecretToRef:name: db-conn- name: sample-osstype: alibaba-ossproperties:bucket: vela-website-0911acl: privatewriteConnectionSecretToRef:name: oss-conn
The component sample-db will generate secret db-conn with these keys, and the component sample-oss will generate secret oss-conn. These secrets are binded to the Envs of component express-server by trait Service Binding. Then the component can consume instances of OSS and RDS.
Deploy and verify the application.
$ vela lsAPP COMPONENT TYPE TRAITS PHASE HEALTHY STATUS CREATED-TIMEwebapp express-server webservice service-binding running healthy 2021-09-08 16:50:41 +0800 CST├─ sample-db alibaba-rds running healthy 2021-09-08 16:50:41 +0800 CST└─ sample-oss alibaba-oss running healthy 2021-09-08 16:50:41 +0800 CST
$ vela port-forward webappForwarding from 127.0.0.1:8080 -> 80Forwarding from [::1]:8080 -> 80Forward successfully! Opening browser ...

Last updated on Feb 9, 2023 by dependabot[bot]