Lab 11: Create Alarm Using Terraform
The Nautilus DevOps team is setting up monitoring in their AWS account. As part of this, they need to create a CloudWatch alarm.
Using Terraform, perform the following:
REQUIREMENTS
-
Create a CloudWatch alarm named
devops-alarm. -
The alarm should monitor CPU utilization of an EC2 instance.
-
Trigger the alarm when CPU utilization exceeds 80%.
-
Set the evaluation period to 5 minutes.
-
Use a single evaluation period.
The Terraform working directory is
/home/bob/terraform. Create themain.tffile (do not create a different.tffile) to provision the instance.
Note: Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal.
Create main.tf
resource "aws_cloudwatch_metric_alarm" "devops-alarm" {
alarm_name = "devops-alarm"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
period = 300
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
statistic = "Average"
threshold = 80
}
terraform init
terraform plan -out kke.plan && terraform apply kke.plan
# or apply forcefully without creating plan and applying it
terraform apply -auto-approve
aws cloudwatch describe-alarms --alarm-names devops