Terraform vs Ansible (a simple and quick read)
At the offset, it is important to understand the difference between Configuration Management Tool (CMT) and Infrastructure as Code(IAC) Tool.
Ansible, Chef, Puppet etc. are Configuration Management Tools which are primarily designed to install and manage software on existing servers. Like automate processes such as system configuration changes ,rolling updates, deploying application etc.
While Terraform, Cloud Formation Templates, ARM Templates etc. are Infrastructure as Code Tools designed to provision(supply) servers and infrastructure themselves. Like assigning CPU, RAM, HDD, creating, destroying infrastructure etc.
IAC and CMT can be used hand in hand.
For example: You could use Terraform to create a new EC2 instance on AWS. Terraform can then call the Ansible API to install and configure software and applications on the EC2 instances as desired.
Although, in some cases Ansible is considered as an IAC tool, but it does not serve the complete purpose of IAC.