Lab 07: Create AMI 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 an AMI from an existing EC2 instance named
nautilus-ec2using Terraform. -
Name of the AMI should be
nautilus-ec2-ami, make sure AMI is inavailablestate. -
The Terraform working directory is
/home/bob/terraform. Update themain.tffile (do not create a separate.tffile) to create the AMI.Note:Right-click under theEXPLORERsection inVS Codeand selectOpen in Integrated Terminalto launch the terminal.
Create main.tf
resource "aws_ami_from_instance" "nautilus-ec2-ami" {
name = "nautilus-ec2-ami"
source_instance_id = aws_instance.ec2.id
}
terraform init
terraform plan -out kke.plan && terraform apply kke.plan
# or apply forcefully without creating plan and applying it
terraform apply -auto-approve