Terraform is a tool to create infrastructure as code. It can take JSON or YAML configuration files to provision servers, install applications and services on those servers and tie everything together. Terraform will then manage the lifecycle of these resources: it will safely make changes to the environment, record what has happened, and then make a plan for next steps if this change was successful or if there was an error. We compare Terraform with other tools in the Infrastructure as Code space such as CloudFormation, Chef and Ansible.
You may also want to look at our infrastructure comparison project, where we analyze different technologies in the area of infrastructure, again looking at pros and cons of each technology.
To understand what Terraform can do, please consult the following resources: – The official documentation: https://www.terraform.io/docs/index.html – The official examples: https://github.com/terraform-open-solutions/terraform-examples – The “community documentation” here: https://www.terraform.io/docs/community
Ansible is an automation package that is written in Python and functions similar to Terraform. It can be used to provision servers, install applications and services and tie everything together. However, as of version 2.0, it only supports management of OpenStack clouds (using either Heat or Quantum). It also does not support doing things that are not possible with OpenStack, e.g. managing AWS resources or setting up EC2 instances which don’t run the OpenStack cloud orchestration layer.
Terraform is a tool created by Hashicorp that allows you to provision infrastructure and applications in the cloud quite easily. It has built-in support for infrastructure as code (IaC) which allows it to manage existing cloud-based resources such as AWS, Azure, Rackspace or any other IaaS provider. The level of abstraction also makes it easier to create different types of environments and apply configurations at different levels (e.g. dev, staging, prod). The main downside is it’s still quite a new tool and lacks some key management features (e.g. YAML support), although most of those issues have been fixed in newer versions.
As for OpenStack, Terraform supports it out of the box, provided that you have the necessary module installed. You can also run it on your own private (non-OpenStack) AWS infrastructure.
Comparison of Terraform and Ansible
The biggest difference between the two tools is that Terraform can be used with any cloud provider (and also on-premises resources) while Ansible can only manage providers which include OpenStack, AWS and Rackspace. Terraform has an extensive plugin system, allowing it to take advantage of other cloud providers where Ansible is limited to just OpenStack. Terraform can be more easily set up as a service and managed by others, while Ansible requires you to install it and run it manually. Terraform has more functionality built in, e.g. provisioning LAMP stacks or supporting Docker containers – Ansible does not support the creation of these resources.
See the references sections at the end for a miscellaneous collection of comparisons and reviews, as well as specific comparisons for cloud services.
References [REF1] – Terraform v/s Ansible [REF2] – Choosing between Puppet, Chef and Ansible [REF3] – Red Hat Ansible Review [REF4] – Red Hat Ansible Overview [REF5] – Red Hat Ansible Review
When to use Terraform vs Ansible
If you are only interested in managing OpenStack clouds, then it makes sense to use Ansible. If you want to manage non-OpenStack infrastructures (or even if you just have an existing AWS infrastructure that you wish to migrate), then Terraform is the way to go. Terraform can also be used to create new infrastructure that can run OpenStack clouds, while Ansible is only capable of managing existing infrastructure.
In the end, the choice will largely be determined by how much you need to manage, and how diverse that management needs are. If you have the flexibility to use Terraform or Ansible, then it makes sense to make this choice.
If your goal is to create a OpenStack cloud, then Ansible will be a good choice because it can also be used to support non-OpenStack infrastructures. Additionally, Ansible has remote execution capabilities that help with scaling and other common issues.
Terraform is a good choice if you need to create an OpenStack as well as other infrastructure types, including AWS and other cloud platforms. Additionally, Terraform has support for cloud platforms that are not OpenStack compliant.
Pros and cons of Terraform vs Ansible
Terraform supports a larger number of cloud providers (at the time of writing it supports AWS, Digital Ocean, Azure, Google Compute Engine, OpenStack and Rackspace), as well as on-premises resources. Terraform also has extensive documentation and an ecosystem of tools that plug into it or are built on top of it. Terraform has a much larger number of plug-in modules for various tasks, allowing for more flexibility. It also has a sandbox mode that allows you to do some basic things before you commit to creating configuration files for production. This can help get you up and running quickly with Terraform.
On the other hand, Ansible has less functionality than something like Terraform, so it will take more time to get something up and running. While Ansible has many modules that can be used with it, they are not as well tested or maintained as those in Terraform. Benchmarks have shown that Ansible is significantly slower than Terraform. Ansible also has a much smaller ecosystem of tools and plugins, although that is improving with the release of Ansible Tower.
Conclusion: This comes down to your use case and your security requirements, but for most cases it will be better to use Terraform.