Terraform-driven Blue-Green Deployment of Cloud Foundry Application on IBM Cloud
IBM Cloud Terraform Provider has a rich set of resources around Cloud Foundry Application. Blue-green deployment is a pretty common
deployment technique to reduce the downtime and risk. The provider doesn’t support this technique out of box. It does provide necessary
resources to help you perform the deployment. We will follow the steps outlined here.
To demonstrate the technique we will use a simple python application.
The repo has two tags v0.1.0 and v0.2.0. The former will be used for the Blue deployment and the latter for the Green deployment.
Preparation for the deployment
- Download the Terraform binary zip. Unzip it and keep the binary in path ex- /usr/local/bin.
- Download the IBM Cloud provider binary zip. Unzip it and keep the binary in path in the same directory where you placed Terraform binary in previous step. You can also build the binary yourself. Please look into documentation.
- Issue below commands to download and configure terraform configuration files.
$ git clone https://github.com/ashishth09/blue-green-deployment
$ cd blue-green-deployment
$ export BM_API_KEY=bx_api_keyIncremental deployment
Blue deployment
This is for the deployment of the first version of the app. App will be accessible at https://my-welcome-app.mybluemix.net
$ git checkout blue
$ terraform apply -var org=org -var space=spaceAfter this step
- Blue is now running on IBM Cloud .
- The CF Router sends all traffic for my-welcome-app.mybluemix.net to Blue.
Green deployment
Get Harini Reddy’s stories in your inbox
Join Medium for free to get updates from this writer.
This is for the deployment of the second version of the app. App will be accessible at https://my-welcome-app-temp.mybluemix.net
$ git checkout blue-green
$ git diff blue blue-green #To see how the configuration has changed.
$ terraform apply -var org=org -var space=spaceAfter this steps:
- Two instances of our application are now running on IBM Cloud: the original Blue and the updated Green.
- The CF Router continues sending all traffic for my-welcome-app.mybluemix.net to Blue. The router now also sends any traffic for my-welcome-app-temp.mybluemix.net to Green.
Load balancing between Blue and Green
This is when Blue and Green are load balanced. Green is accessible at my-welcome-app.mybluemix.net and my-welcome-app-temp.mybluemix.net
$ git checkout blue-green-lb
$ git diff blue-green blue-green-lb #To see how the configuration has changed.
$ terraform apply -var org=org -var space=spaceAfter this steps:
- The CF Router continues sending traffic for my-welcome-app.mybluemix.net to Green.
- Within a few seconds, the CF Router begins load balancing traffic for my-welcome-app.mybluemix.net between Blue and Green.
Making blue in-accessible
Blue is no more accessible. Green continues to be accessible at two routes
$ git checkout green-only-with-2-routes
$git diff blue-green-lb green-only-with-2-routes #To see how the configuration has changed.
$ terraform apply -var org=org -var space=spaceAfter this steps:
- The CF Router stops sending traffic to Blue. Now all traffic for my-welcome-app.mybluemix.net is sent to Green.
Remove Temporary Route to Green
Green is accessible only at original route my-welcome-app.mybluemix.net
$ git checkout green-original-route-only
$ git diff green-only-with-2-routes green-original-route-only #To see how the configuration has changed.
$ terraform apply -var org=org -var space=space





