Launching EC2 instances along with key-pair and security group- an intro to Terraform
Hello, readers. This is my first blog and we start off with Terraform. I'll talk about Terraform in brief, and then moving onto the launching of EC2 instances. Then we will be seeing the addition of key pairs and security groups to the instance we created, which will then be followed by the creation of an EBS volume of size 1GB, which will then be attached to the instance.
What is Terraform?
Terraform is Infrastructure as code for managing, Building infrastructure from code. Terraform can manage existing and popular cloud service providers(AWS, AZURE, GCP, Alibaba) as well as custom in-house solutions. It is one of the famous DevOps tools in the market.
Suppose you need EC2 Instance with that EC2 Instances, 1 Security Group, 1 Keypair etc, So you’ll manually create it in AWS Console/CLI/SDK. Now in case, you need the same thing, many times in your requirements, so this will be hectic work for you. So this is where Terraform comes, you write code once, use it or modify it accordingly, as many times.
Create/Launch Application using Terraform
Below is the Flow for the application launch:
1. Create a key pair
2. Create a security group
3. Launch an instance using the above-created key pair and security group.
4. Create an EBS volume of 1 GB.
5. The final step is to attach the above-created EBS volume to the instance you created in the previous steps.
Step 1: Creating Key Pair
First, add a provider clause that specifies your region.
Now add the clause for key pair
For public key pair generation, use the website
https://asecuritysite.com/encryption/ssh
Step 2: Create a security group
This will create a security group name My Security Group having ingress port 80,22 allowed to internet and allow egress of all ports.
This will create an ec2 instance with the name as MyFirstos having key and security groups that we created in earlier steps.
Step 4 & 5: Launching EBS volume and attaching same to that instance
This will create an EBS volume with the name myebsvol and the same EBS volume is also attached to the instance which we created.
A simultaneous view of the terminal is also displayed below, for the execution of Terraform on the above code.
I hope the post was easy to follow!
Comments
Post a Comment