Ansible is a configuration tool and Terraform is an orchestration tool. Ansible provides support for mutable infrastructure whereas Terraform provides support for immutable infrastructure. Ansible uses a procedural whereas Terraform uses declarative language. Ansible provides partial VM provisioning networking, and storage management whereas Terraform provides comprehensive. Ansible provides complete support for packaging and templating whereas Terraform provides partial. Ansible does not have lifecycle management whereas Terraform is heavily dependent.
Both have their own uses. In short, use Ansible foe configuration management and Terraform for orchestration.
If you want to learn more about Terraform, then register for this AWS DevOps Training by Intellipaat.
Also, watch this video on AWS Terraform Tutorial: