The MTA deployment descriptor allows for fixed or dynamically generated values to be shared between the described entities (modules & resources). For one module/resource to consume exposed variables from another, it has to declare its dependency to it in the requires
element. As in MTAs apps are defined as modules, this mechanism can be used to share the url of one app in the environment of another:
modules:
- name: providing-module
type: application
properties:
my-generated-user: ${generated-user}
provides:
- name: module-1-provided
properties:
user: ${generated-user} # the ${generated-user} parameter has an unique generated value for each module
config: "static-string"
url: ${default-url}
#...
- name: consuming-module
type: application
requires:
- name: module-1-provided
properties:
m1-user: ~{module-1-provided/user}
m1-config: '~{module-1-provided/config}-with-suffix'
m1-url: ~{module-1-provided/url}
#...
-
Understanding how Cloud Foundry applications are modeled in an MTA
You can directly deploy the built app of this example from the current directory and the modeled mtad.yaml deployment descriptor:
$ cf deploy ./
Deploying multi-target app archive ********/sharing-values-between-apps/my-mta.mtar in org deploy-service / space ******** as ********...
Uploading 1 files...
********/sharing-values-between-apps/my-mta.mtar
OK
Deploying in org "deploy-service" and space "********"
...
Process finished.
Alternatively, you can build & deploy the MTA from mta.yaml. To build and deploy an MTA from a mta.yaml development descriptor, run the commands described below.
First build & assemble the MTA archive:
$ mbt build
[2020-04-02 23:47:34] INFO Cloud MTA Build Tool version 1.0.8
[2020-04-02 23:47:34] INFO generating the "Makefile_20200402234734.mta" file...
...
[2020-04-02 23:47:34] INFO the MTA archive generated at: ...
Then deploy the assembled package:
$ cf deploy mta_archives/my-mta_0.0.0-SNAPSHOT.mtar
...
Check the actual app url:
$ cf app providing-module | grep routes
routes: deploy-service-********-providing-module.cfapps.sap.hana.ondemand.com
Let’s see the generated user value:
$ cf env providing-module | grep my-generated-user
my-generated-user: u]rPqDU-70y(-E0c
Finally, let’s see how the second app consumed the provided values:
$ cf env consuming-module | grep m1
m1-config: static-string-with-suffix
m1-url: https://deploy-service-********-providing-module.cfapps.sap.hana.ondemand.com
m1-user: u]rPqDU-70y(-E0c