Terraform vs Ansible: When and how to use infrastructure tools as code - Byzov, Ivan (Technologies and Engineering, 2025)
In the world of IT infrastructure management, the concept of infrastructure as code has firmly established itself. Two popular tools for implementing this approach – Terraform and Ansible – are widely used by DevOps professionals to automate and manage cloud and on-premises resources. Although both tools perform analogous tasks, they have distinct principles of operation, architecture, and application scenarios. The purpose of this study was to provide the key differences between Terraform and Ansible, their strengths and weaknesses, and use cases for each of these tools. Recommendations for choosing a tool depending on specific tasks were offered. Terraform, as a declarative style tool, enables users to describe the end state of the infrastructure, after which it automatically brings it to that state. Ansible, on the other hand, supports both declarative and imperative approaches, making it flexible for managing server configurations and performing orchestration. The study presented practical examples of using both tools. The first example demonstrated how Terraform can be used to automatically deploy cloud infrastructure in Hetzner Cloud. In this example, actions with a cloud service took place using declarative configuration files. The second example described how Ansible can be used to configure servers and how to automate server tasks. The study included scientific aspects related to the evaluation of IaC effectiveness, specifically formulas for calculating the time of application of changes in the infrastructure. The use of formulas helped to quantify the time and overall efficiency of work in the infrastructure to increase overall transparency and control over management processes. Thus, understanding the scenarios in which each tool is most effective will help engineers properly organise infrastructure management processes.