x300n
x300n

Reputation: 331

How to do terraform continuous deployment of large codebases faster?

We have a large infrastructure codebase in terraform and ansible. Some tasks require small changes like adding/modifying a role/playbook. Merge requests however run and deploy the entire stage of 1) provision vm > 2) Install software > 3) configure VM with playbook changes.

The problem with step 2 is that it takes a significant amount of time to complete before getting to actully running the playbook, everytime.

I am curious to learn a better way of CD, thanks.

Upvotes: 0

Views: 168

Answers (2)

Martin Atkins
Martin Atkins

Reputation: 74299

One common approach to the situation you've described is to pre-build custom virtual machine images that already contain the software you'll need at runtime, and then the final configuration step can focus only on adding in any final configuration settings that can be learned only at runtime, such as the network location of some other service that software in the VM might depend on.

One way to achieve this is to use HashiCorp Packer in a separate build step to derive a custom machine image from a base image that's already available. Packer has the option of running Ansible as a way to prepare an image, so if you already have your software installation steps (step 2) defined as an Ansible playbook then you could use a subset of your steps as machine image steps and then have your existing step 3 run Ansible again only to finalize the running machine.

This approach would be effective only if you create new VMs more often than you change the software to be installed, because it relies on the ability to amortize the cost of building the image across multiple VM boots. If you need to change the installed software for every change anyway then there isn't really any generalized way to optimize, since you can only change the order you do the steps in, not how often you'd run each step.

Upvotes: 1

Mohammed Almusaddar
Mohammed Almusaddar

Reputation: 787

You are combining both Infrastructure as code and configuration as code. It's a good pattern to split both Ansible and Terraform. so first provision using Terraform. then Configure using Ansible. There should be a decoupling between Terraform and Ansible.

Upvotes: 0

Related Questions