Create EC2 Instance Using Terraform Kodekloud Engineer Task Success

Ticker

6/recent/ticker-posts

Create EC2 Instance Using Terraform Kodekloud Engineer Task Success

 Question :  The Nautilus DevOps team is strategizing the migration of a portion of their infrastructure to the AWS cloud. Recognizing the scale of this undertaking, they have opted to approach the migration in incremental steps rather than as a single massive transition.  

To achieve this, they have segmented large tasks into smaller, more manageable units.  

For this task, create an EC2 instance using Terraform with the following requirements:  

    The name of the instance must be `datacenter-ec2`.

    Use the Amazon Linux `ami-0c101f26f147fa7fd` to launch this instance.

    The Instance type must be `t2.micro`.

    Create a new RSA key named `datacenter-kp`.

    Attach the `default` (available by default) security group.

    The Terraform working directory is /home/bob/terraform. Create the main.tf file (do not create a different .tf file) to provision the instance.

    Note: Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal. 



Please Note:-  Perform the below commands based on your question server,  user name & other details that might differ as per the task.

Solution:  

1. In VS Code Editor create a new file  main.tf 

      (Refer Video below for better understanding )


Code you will get on Git Lab repository 

https://gitlab.com/nb-tech-support/devops/-/blob/master/Terraform

resource "tls_private_key" "datacenter_kp" {
  algorithm = "RSA"
  rsa_bits  = 4096
}

resource "aws_key_pair" "datacenter_kp" {
  key_name   = "datacenter-kp"
  public_key = tls_private_key.datacenter_kp.public_key_openssh
}

data "aws_security_group" "default" {
  name = "default"
}

resource "aws_instance" "datacenter_ec2" {
  ami                    = "ami-0c101f26f147fa7fd"
  instance_type          = "t2.micro"
  key_name               = aws_key_pair.datacenter_kp.key_name
  vpc_security_group_ids = [data.aws_security_group.default.id]

  tags = {
    Name = "datacenter-ec2"
  }
}

2  Execute given below command one another.

terraform init

terraform plan

terraform apply



3. Click on Finish & Confirm to complete the task successful

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , 

please go through and share your comments. Like and share the knowledge

















Post a Comment

0 Comments

Latest Posts

Create EC2 Instance Using Terraform  Kodekloud Engineer Task Success