How to create EC2 instance in AWS EC2 with the IAM role attached

I want to Create the following resources using Terraform:

An S3 bucket

An IAM role

An IAM policy attached to the role that allows it to perform any S3 actions on that bucket and the objects in it

An EC2 instance with the IAM role attached

Create a and document all assumptions made. Login to the EC2 instance and validate access to the bucket using the role.