How to configure app properties of multiple FLOGO apps running in TIBCO Cloud Integration (TCI) using Consul KV
Ever wondered how to configure/update app properties like database url, username, password for multiple FLOGO applications running in TIBCO Cloud Integration ? You have come to the right place. Lets see how to solve this problem.
Lets say I have multiple FLOGO applications which use the same db name, host/port, username . password, then we can configure these properties outside of TCI platform at one place instead of updating each app. Consul KV comes to our rescue.
The Consul provides a key/value store for managing app configuration externally. Flogo allows you to fetch values for app properties from Consul and override them at runtime. A Flogo app connects to the Consul server as its client by setting the environment variable, FLOGO_APP_PROPS_CONSUL. At runtime, you must provide the Consul server endpoint in order for your app to connect to a Consul server.
Running and Configuring Consul
To run consul we are going to use the docker image available at DockerHub, that you could find at this location. To do that, we only have to run the following docker run command:
docker run --name=dev-consul --rm -p 8500:8500
-e 'CONSUL_LOCAL_CONFIG={"acl_master_token":"consul", "acl_datacenter":"dc1", "acl_default_policy":"allow", "acl_down_policy":"allow"}'
consul
Access Consul UI : http://localhost:8500
Note that you can use tibagent/tibtunnel to connect to on-prem servers from Tibco Cloud Integration (TCI) and attach Access Keys to your application.
The only configuration that we are going to do is to create a Key/Value pair in order to define the prefix that we are going to use on the Consul service implementation.
To do that, we only have to click on Key/Value and add the following Key Name: dev/ConsulDemo/username and USERNAME_Override_From_Consul as the Key Value and that’s all the configuration on the consul side.
Note that the Key in the Consul KV should match the app property name.
Integrate Consul with TIBCO Cloud Integration
In TIBCO Cloud Integration, in the Environment controls Tab, add the variable name FLOGO_APP_PROPS_CONSUL and value to {“server_address”:<consul server address>,"acl_token":<acl_token>,"key_prefix": “/dev/ConsulDemo”}
Note that key_prefix and acl_token are optional but needed if you have set acl_token and have Keys defined in nested folders in Consul KV.
As you see in the above screenshot, these are the default values for HostPort, username, DBName, password. Now lets say one or more applications are using the same DB app properties, then these can be overridden by configuring the Consul KV and adding FLOGO_APP_PROPS_CONSUL as Engine variable in all your apps as shown above.
At runtime, you will see the updated values getting picked up from Consul -
So you will need to modify at just one place and not each application.
Note that, to pick the updated values at runtime from Consul KV, the application needs to be repushed.