Task18: The Nautilus DevOps team has been tasked with setting up an EC2 instance for their application. To ensure the application performs optimally, they also need to create a CloudWatch alarm to monitor the instance’s CPU utilization. The alarm should trigger if the CPU utilization exceeds 90% for one consecutive 5-minute period. To send notifications, use the SNS topic named datacenter-sns-topic
, which is already created. 1. Launch EC2 Instance: Create an EC2 instance named datacenter-ec2
using any appropriate Ubuntu AMI (you can use AMI ami-0c02fb55956c7d316
). 2. Create CloudWatch Alarm: Create a CloudWatch alarm named datacenter-alarm
with the following specifications: * Statistic: Average * Metric: CPU Utilization * Threshold: >= 90% for 1 consecutive 5-minute period * Alarm Actions: Send a notification to the datacenter-sns-topic
SNS topic. 3. Update the main.tf
file (do not create a separate .tf file) to create a EC2 Instance and CloudWatch Alarm. 4. Create an outputs.tf
file to output the following values: * KKE_instance_name
for the EC2 instance name. * KKE_cloudwatch_alarm_name
for the CloudWatch alarm name.
My solution: main.tf
resource “aws_sns_topic” “sns_topic” {
name = “datacenter-sns-topic”
}
resource “aws_instance” “datacenter-ec2” {
ami = “ami-0c02fb55956c7d316”
instance_type = “t2.micro”
tags = {
Name = “datacenter-ec2”
}
}
resource “aws_cloudwatch_metric_alarm” “datacenter-alarm” {
alarm_name = “datacenter-alarm”
comparison_operator = “GreaterThanOrEqualToThreshold”
evaluation_periods = 1
metric_name = “CPUUtilization”
namespace = “AWS/EC2”
period = 300
statistic = “Average”
threshold = 90
alarm_description = “This metric monitors ec2 cpu utilization”
actions_enabled = “true”
alarm_actions = [aws_sns_topic.sns_topic.arn]
dimensions = {
InstanceId = aws_instance.datacenter-ec2.id
}
}
My verification:
bob@iac-server ~/terraform via default ➜ terraform output
KKE_cloudwatch_alarm_name = “datacenter-alarm”
KKE_instance_name = “datacenter-ec2”
bob@iac-server ~/terraform via default ➜ aws cloudwatch describe-alarms --alarm-names datacenter-alarm
{
“MetricAlarms”: [
{
“AlarmName”: “datacenter-alarm”,
“AlarmArn”: “arn:aws:cloudwatch:us-east-1:000000000000:alarm:datacenter-alarm”,
“AlarmDescription”: “This metric monitors ec2 cpu utilization”,
“AlarmConfigurationUpdatedTimestamp”: “2025-07-12T22:54:40.469943Z”,
“ActionsEnabled”: true,
“OKActions”: [],
“AlarmActions”: [
“arn:aws:sns:us-east-1:000000000000:datacenter-sns-topic”
],
“InsufficientDataActions”: [],
“StateValue”: “INSUFFICIENT_DATA”,
“StateReason”: “Unchecked: Initial alarm creation”,
“StateUpdatedTimestamp”: “2025-07-12T22:54:40.469943Z”,
“MetricName”: “CPUUtilization”,
“Namespace”: “AWS/EC2”,
“Statistic”: “Average”,
“Dimensions”: [
{
“Name”: “InstanceId”,
“Value”: “i-2914216f29911d940”
}
],
“Period”: 300,
“EvaluationPeriods”: 1,
“Threshold”: 90.0,
“ComparisonOperator”: “GreaterThanOrEqualToThreshold”,
“TreatMissingData”: “missing”,
“StateTransitionedTimestamp”: “2025-07-12T22:54:40.469943Z”
}
],
“CompositeAlarms”: []
}
But Task18 verification failed with below message:
Terraform output does not contain the correct instance or alarm name.
Please check and help in identifying what might be the issue in my solution.