Lab 01: Create Key Pair Using Terraform
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. This granular approach enables the team to execute the migration in gradual phases, ensuring smoother implementation and minimizing disruption to ongoing operations. By breaking down the migration into smaller tasks, the Nautilus DevOps team can systematically progress through each stage, allowing for better control, risk mitigation, and optimization of resources throughout the migration process.
For this task, create a key pair using Terraform with the following requirements:
-
Name of the
key pairshould bexfusion-kp. -
Key pair
typemust bersa. -
The private key file should be saved under
/home/bob/xfusion-kp.pem.The Terraform working directory is
/home/bob/terraform. Create themain.tffile (do not create a different.tffile) to accomplish this task.Note:Right-click under theEXPLORERsection inVS Codeand selectOpen in Integrated Terminalto launch the terminal.
Create main.tf
resource "tls_private_key" "xfusion-kp" {
algorithm = "RSA"
rsa_bits= 4096
}
resource "local_file" "private_key" {
content= tls_private_key.xfusion-kp.private_key_pem
filename = "/home/bob/xfusion-kp.pem"
file_permission = "0600"
}
resource "aws_key_pair" "xfusion-kp" {
key_name= "xfusion-kp"
public_key = tls_private_key.xfusion-kp.public_key_openssh
}
terraform init
terraform plan -out create_key_pair.plan
terraform apply create_key_pair.plan