HiveBrain v1.2.0
Get Started
← Back to all entries
patternterraformMinor

Does terraform support blue green deployments and roll backs out of the box

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
thebluerolldeploymentsdoesandgreenboxoutbacks

Problem

I have been trying use terraform for a while . any suggestions/tips on how I can handle blue green deployments . I see how terraform enables it with auto scale groups on aws . But I’d like run some Cucumber acceptance tests on the new Asg before routing traffic to it . Is there a way in terraform to retain the old asg for a period , if In case I need to do a rollback . Can this be accomplished with terraform ... thanks in advance .

Solution

It all depends on how you are deploying your code.

(First, IMHO, I don't think that Terraform is the right hammer for this operation. Terraform responsibility is to build the necessary infrastructure for your application, not to be the tool used for deploying it. But, as always, "the right/best one" will depend on lots of factors and, depending on the case/scale, it may be the "good enough" solution)

My suggestion would be, in summary:

  • Deploy your application in the "unused" environment



  • Test it



  • Change the domain name to point to it



Assuming you have 2 AutoScaling groups already configured. One called asg-blue and the other called asg-green. And that the current version resides on asg-blue and in terraform you have an aws_route53_record pointing to it. You would need to follow these steps, each one with a terraform apply before the next:

  • Deploy the newer version of your application on asg-green



  • I.e. update everything that is needed to deploy your application version. It may be the AMI you point on your Launch Configuration or any other way that you do exclusively using Terraform.



  • Test that everything is running as expected



  • Here you could use the domain-name provided for each ASG/ELB or one already configured on terraform



  • Update the domain name to pont to asg-green ASG/ELB on the aws_route53_record



  • Reduce the number of machines needed on asg-blue to don't use too many resources



  • Depending on your case you can configure for 0 machines



This way you can have your B/G deployment, but for every deployment you'd need at least two manual interventions in your terraform (the deployment of the new version and updating the domain name).

But with this strategy you should take a lot of care to not deploy on the current ASG being used.

Of course if your terraform/aws fu is good, instead of reusing ASGs, you could delete and create them as needed.

Hope that this help in having a "big picture" of the entire process. But I'd suggest that you research and start using tools more focused on deployment, like AWS CodeDeploy.

Context

StackExchange DevOps Q#3142, answer score: 8

Revisions (0)

No revisions yet.