Creating your first Terraform infrastructure on AWS (Amazon Web Services)

by Ismail.EL
0 comment

1. About Terraform & AWS

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. … Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure.

Amazon Web Services (AWS) is het public cloud-platform van Amazon, het bekende Amerikaanse e-commercebedrijf.

2. Adience

This article is prepared for anyone who want to begin learning to use terraform to create a resources in AWS provider cloud.

In this post, i will show you how to build a simple EC2 instance using Terraform on AWS platforme

3. Prerequisites

  • An activate accounte in AWS plateform -> you can get a free account offerd by amazon web service -> https://aws.amazon.com/free/
  • Basic knowledges about terraform

4. Setup AWS Account

In my case i will use us-east-1 region to create any resources in aws

-> Create a new user in the IAM Section on AWS here.

-> Select Programmatic access below and enter your user details.

-> Click next and create a group if is not already created

select group and click Next

-> Enter Tag if you want to add (it’s optionnal) , finnaly click “Create user”

Once the user is created you will get an Access key ID and Secret access key. Store these in a safe location as you will need these later. See below for an example.

5. Install Terraform

Check if terraform is installed with success

Once you have successfully installed Terraform, continue to the next section.

6. Deploy your first instance using Terraform

Let’s create a file called first_instance.tf, and put the codes above inside

  • we use the AWS provider plugin from Terraform
  • We provide the access key/secret for our user that we created
  • ami: is the image id tha you can find in this link
  • We specify the region in which we want to create our instance (in my case i use us-east-1)

let’s run the “terraform init” command in terminal to create a first resource (instance) in aws platforme

Once the command “terraform init” is finished successfully we will run the command “terraform plan” to see what our code will do

and finally what remains to launch the command “Terraform Apply” to start the code and create our instance

as you can see in the screen below our instance has been created successfully

We can check it in our consol management

7. Destroy instance created

To destroy all the resources we have created in our Terraform infrastructure, we can simply run “terraform destroy”

8. Conclusion

In this post, i have explained how to build and destroy your first instance in aws cloud provider using terraform tool
If you have any questions or feedback, feel free to leave a comment.
As always, if you found this post useful, then click like and share it 🙂

22790cookie-checkCreating your first Terraform infrastructure on AWS (Amazon Web Services)

Related Posts

Leave a Comment