Easy Steps — Configuring Terraform in AWS EC2 instance.
Terraform is one of the most popular IaaC (Infrastructure as a Code) tool. It is very famous as it is compatible with many cloud providers (like aws, gcp and azure). It is very easy to set up and with couple of clicks, you can start exploring with terraform.
Step -1:
Create an EC2 instance ( I am using free tier to play around it)
Step -2: You can install putty and use the key pair to connect AWS EC2 instance, however, you can also access your created ec2 instance from Session Manager. To do the same, create an IAM role and give the full permission to Session Manager and attach that IAM role to your instance. This way, you can access and perform all the steps in Web only. Its cool 😊
IAM Role: For my future exploration, I attached S3 Full access but its not mandatory. And also for prod use case, you may not require SSM full access, See the aws documentation for specific access
Attach the IAM role to EC2 instance:
Step -3: Connect to EC2 instance from System manager. Go to System managers service, click session manager and click start session, select your instance and click start session.
Wonderful work so far… you are able to see connect ec2. If you are not able to see the instance in your target instances, do not worry, wait 5–10 mins and refresh the page.
Step -4:
To connect the ec2-user ( which is the default use), type sudo su — ec2-user
Step -5: To download the terraform ( go to terraform webpage, check the latest version)
wget https://releases.hashicorp.com/terraform/1.3.0/terraform_1.3.0_linux_amd64.zip
Step -6: Unzip the terraform file, run the command — unzip terraform_1.3.0_linux_amd64.zip
Wow, you configured terraform successfully in ec2 instance, very easy.
Step -7: If you want to run terraform command from any path, just move the binary to /usr/bin path by the command — sudo mv terraform /usr/bin
Step -8: Verify Terraform is working fine or not by a sample easy terraform command — terraform -version
You can start creating your infrastructure from your own ec2 instance and learn terraform as well.