Complete the code to specify the instance type for right-sizing an EC2 instance.
resource "aws_instance" "example" { ami = "ami-0c55b159cbfafe1f0" instance_type = "[1]" }
The m5.large instance type is a balanced choice for right-sizing, offering good CPU and memory for many workloads.
Complete the code to define the desired CPU utilization target for an Auto Scaling group policy.
resource "aws_autoscaling_policy" "cpu_target" { name = "cpu-target" autoscaling_group_name = aws_autoscaling_group.example.name policy_type = "TargetTrackingScaling" target_tracking_configuration { predefined_metric_specification { predefined_metric_type = "ASGAverageCPUUtilization" } target_value = [1] } }
A target CPU utilization of 50.0 percent is a common right-sizing goal to balance performance and cost.
Fix the error in the launch configuration by selecting the correct block to specify the root block device size.
resource "aws_launch_configuration" "example" { name_prefix = "example-" image_id = "ami-0c55b159cbfafe1f0" instance_type = "t3.medium" [1] { volume_size = 30 } }
The root_block_device block correctly specifies the root volume size for the instance.
Fill both blanks to create a CloudWatch alarm that triggers when CPU utilization exceeds a threshold.
resource "aws_cloudwatch_metric_alarm" "high_cpu" { alarm_name = "high_cpu_alarm" comparison_operator = "[1]" evaluation_periods = 2 metric_name = "CPUUtilization" namespace = "AWS/EC2" period = 300 statistic = "Average" threshold = [2] alarm_description = "Alarm when CPU exceeds threshold" dimensions = { InstanceId = aws_instance.example.id } }
The alarm triggers when CPU utilization is GreaterThanThreshold 80 percent, indicating high usage.
Fill all three blanks to define an Auto Scaling group with a desired capacity and health check type.
resource "aws_autoscaling_group" "example" { name = "example-asg" max_size = 5 min_size = 1 desired_capacity = [1] launch_configuration = aws_launch_configuration.example.name health_check_type = "[2]" health_check_grace_period = [3] vpc_zone_identifier = ["subnet-12345678"] }
The desired capacity is set to 3, health check type to EC2, and grace period to 300 seconds for proper right-sizing and health monitoring.