Skip to content

Latest commit

 

History

History

keep-existing-env

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Keeping existing CF App environment variables during update

Overview

This example shows how to preserve manually set app environment variables during MTA deployment. This strategy may be useful, for instance, when an operator modifies an app configuration. The modifications should remain even if the configuration isn’t maintained in a particular *.mtaext extension descriptor, which is provided during deployment.

It is modeled via a module level parameter keep-existing:…​

modules:
  - name:...
    parameters:
      keep-existing:
        env:true
Note
See mta.yaml or mtad.yaml in the current directory.

Official Documentation

Try it out

Initial deployment

You can deploy it directly from an mtad.yaml file:

$ cf deploy ./ -f ;

Or build an MTAR archive from an mta.yaml:

$ mbt build -p cf -t . ;

And then deploy the built MTAR archive:

$ cf deploy a.cf.app_0.0.0.mtar -f ;

Examine the initial state

$ cf env cf-app-keeping-env-changes
...
User-Provided:
...
managed-env-variable: original-env-var-val
$ cf env cf-app-resetting-env
...
User-Provided:
...
managed-env-variable: original-env-var-val

Manually set a new env variable

$ cf set-env cf-app-keeping-env-changes new-env-variable new-env-var-val
$ cf set-env cf-app-keeping-env-changes managed-env-variable changed-env-var-val
$ cf set-env cf-app-resetting-env new-env-variable new-env-var-val
$ cf set-env cf-app-resetting-env managed-env-variable changed-env-var-val

Examine the change

$ cf env cf-app-keeping-env-changes
...
User-Provided:
...
managed-env-variable: changed-env-var-val
new-env-variable: new-env-var-val
$ cf env cf-app-resetting-env
...
User-Provided:
...
managed-env-variable: changed-env-var-val
new-env-variable: new-env-var-val

Re-deply to simulate update

$ cf deploy -f ;

Or

$ cf deploy a.cf.app_0.0.0.mtar -f ;

Check out the result

$ cf env cf-app-keeping-env-changes
...
User-Provided:
...
managed-env-variable: original-env-var-val
new-env-variable: new-env-var-val
$ cf env cf-app-resetting-env
...
User-Provided:
...
managed-env-variable: original-env-var-val

Note that app cf-app-keeping-env-changes has the new-env-variable var kept, but has the value of managed-env-variable reset as defined in the mtad.yaml.

App cf-app-resetting-env has lost the custom env variable and also has the managed-env-variable value reset.

Clean up resources

It is recommended to stop or undeploy your MTAs when they are no longer needed. In order to do so, run the following command:

$ cf undeploy <mta-id> -f --delete-services