'How to connect to instance using terraform aws_instance resource

I created an aws_instance resource without any issue, but, I want to know how can I enable the SessionManager, the EC2 Instance Connect and EC2 Serial Console using Terraform? Which policies are required? This is because I want to have a way to connect to my EC2 instances using three methods.

I searched a lot over internet, but I couldn't find any related with my issue.

Here's an image with the Menu that I could not connect to.


This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source