DEV Community

warris oladipupo
warris oladipupo

Posted on

How to lunch AWS EC2 instance using Terraform

step 1 : install terraform on your machine or computer
step 2 : check the version of your terrform from either the command prompt or your VScode terminal;
step 3: set up your region, aws access key and secret access key from your aws
step 4: after you've done that , the first thing you need for your terraform is a provider( which is aws in this course) there are many providers but we are choosing AWS. on your Vscode , create a provider.tf file.

Image description

step 5: provide the access keys and secret keys in your provider.tf file.

step 6: then initialize your terraform by typing "terraform init" in your VScode terminal

Image description

step 7: to check if your terraform is valid type "terraform validate"

Image description

step 8:now creating an EC2 instance, you need to create an EC2.tf file on your VScode.

step 9: put your resources inside the EC2.tf file

Image description

step 10: provide the ami and the region you are using from AWS

Image description

Image description
the first picture is to show the ami i am using while the second is to show the region i am using.

step 11: after that , the next thing is to plan by typing "terraform plan" in your VScode terminal.

Image description

step 12: to activate the plan and get terraform running , type "terraform apply" and your aws will start creating.

Image description

step 13: then go back to your AWS and check the instance state if it's running

Top comments (0)