Write the modules for ec2, security group , vpc , subnet etc with var files inside modules of each resources and then call those modules from main.tf file
terraform init
To initialize the main.tf file with the above cmd .....,
once initialized then follow the below steps
terraform plan
The above cmd used to tell the plan of what resources are to be created
terraform validate
To validate if any errors it will show in this step
terraform apply
Resources wll be created with the above cmd