100 days of DevOps | Day 100 - EC2 instance creation is taking over 45 mins and still not created

I have attached terraform log screenshot. The task asks me to create an EC2 and cloudwatch alram for it to send a notification to SNS topic(which is already created at the start of the lab), when said EC2 CPU usage is over 90 percent for 5 consecutive mins.

I have compare the my terraform code to other users’ ones and it’s the same, but when i type terraform apply command, it was stuck in EC2 creation step.

Please note that, the following code is from starting another lab, so EC2 names and sns-topic names are different from the screenshot pictures but everything else is the same.

main.tf

resource "aws_sns_topic" "sns_topic" {
  name = "xfusion-sns-topic"
}

data "aws_sns_topic" "existing_topic" {
  name = "xfusion-sns-topic"
}

resource "aws_instance" "datacenter_ec2" {
  ami           = "ami-0c02fb55956c7d316"
  instance_type = "t2.micro"

  tags = {
    Name = "xfusion-ec2"
  }
}

resource "aws_cloudwatch_metric_alarm" "datacenter_alarm" {
  alarm_name          = "xfusion-alarm"
  comparison_operator = "GreaterThanOrEqualToThreshold"
  evaluation_periods  = 1
  metric_name         = "CPUUtilization"
  namespace           = "AWS/EC2"
  period              = 300
  statistic           = "Average"
  threshold           = 90

  alarm_actions = [data.aws_sns_topic.existing_topic.arn]

  dimensions = {
    InstanceId = aws_instance.datacenter_ec2.id
  }
}

outputs.tf

output "KKE_instance_name" {
  value = aws_instance.xfusion-ec2.tags["Name"]
}

output "KKE_alarm_name" {
  value = aaws_cloudwatch_metric_alarm.xfusion-alarm.alarm_name
}

It might be more productive to post your HCL code. You can post it into this issue (please use a code block so it’s not corrupted), or create a github repo or gist and give us a link to it, so we can look at your code.

1 Like

Thank you for pointing that out, i have updated the post with HCL code, Please kindly take a look, sir.

Hello,

I am facing the exact same issue as the original poster. My terraform apply has been stuck on the EC2 instance creation step for over 45 minutes as well.

I suspect it might be an issue with the Cloud Platform environment/resource availability rather than the HCL code itself, given that multiple users are experiencing the same delay with verified code.

Here is the link to my Terraform HCL code for your review:
github task file

Please let me know if you discover any underlying platform issues.

Thank you!

1 Like

I suppose issue is with the ami-id mentioned in the question. I’ll inform the team about this issue.

1 Like

Hi @mackio and @hritikraj8804 ,

This issue has been resolved. Please give it another try. cc @rob_kodekloud and @Srikanth_Reddy

Regards,

1 Like

I’ve tried it and can confirm that I didn’t face the issue this time.

1 Like

I can confirm too. I have done the day 100 and finished the challenge.

Thank you so much for the swift replies and help @Tej-Singh-Rana and @Srikanth_Reddy