Day 98 of 100 days of devops task

i am at day 98.
i am facing issue, i ec2 instance is taking so much time even lab time is over still it creating ec2 instance . is there any issue in my code i am sharing with this

main.tf

resource “aws_vpc” “devops_priv_vpc” {
cidr_block = var.KKE_VPC_CIDR
tags = {
Name = “devops-priv-vpc”
}
}

resource “aws_subnet” “devops_priv_subnet” {
vpc_id = aws_vpc.devops_priv_vpc.id
cidr_block = var.KKE_SUBNET_CIDR
map_public_ip_on_launch = false

tags = {
    Name = "devops-priv-subnet"
}

}

resource “aws_security_group” “devops_priv_sg”{
name = “devops_priv_sg”
vpc_id = aws_vpc.devops_priv_vpc.id
description = “Security group for devops_priv_sg”

tags = {
    Name = "devops_priv_sg"
}

}

resource “aws_vpc_security_group_ingress_rule” “allow_http” {
security_group_id = aws_security_group.devops_priv_sg.id
from_port = 80
to_port = 80
ip_protocol = “tcp”
cidr_ipv4 = var.KKE_VPC_CIDR
}

resource “aws_vpc_security_group_ingress_rule” “allow_ssh” {
security_group_id = aws_security_group.devops_priv_sg.id
from_port = 22
to_port = 22
ip_protocol = “tcp”
cidr_ipv4 = var.KKE_VPC_CIDR
}

resource “aws_vpc_security_group_egress_rule” “allow_all_outbound” {
security_group_id = aws_security_group.devops_priv_sg.id
from_port = 0
to_port = 0
ip_protocol = “-1”
cidr_ipv4 = “0.0.0.0/0”
}

data “aws_ami” “amazon_linux” {
most_recent = true
owners = [“amazon”]

filter {
    name = "name"
    values = ["amzn2-ami-hvm-*-x86_64-ebs"]
}

}

resource “aws_instance” “devops_priv_ec2” {
ami = data.aws_ami.amazon_linux.id
instance_type = “t2.micro”
subnet_id = aws_subnet.devops_priv_subnet.id
vpc_security_group_ids = [aws_security_group.devops_priv_sg.id]

tags = {
    Name = "devops-priv-ec2"
}

}

variables.tf

variable “KKE_VPC_CIDR” {
type = string
description = “this is vpc CIDR range”
default= “10.0.0.0/16”
}

variable “KKE_SUBNET_CIDR” {
type = string
description = “this is vpc subnet range”
default = “10.0.1.0/24”
}

outputs.tf

output “KKE_vpc_name” {
value = aws_vpc.devops_priv_vpc.tags[“Name”]
description = “this is name of the vpc”
}

output “KKE_subnet_name” {
value = aws_subnet.devops_priv_subnet.tags[“Name”]
description = “this is name of subnet”
}

output “KKE_ec2_private” {
value = aws_instance.devops_priv_ec2.tags[“Name”]
description = “this is name of the ec2 instance”

}

I can’t do that much with the HCL, since pasting it directly into a Discourse edit window corrupts it :frowning: You may want to edit your post and use code blocks, as directed in this doc.

In the meantime, you may also want to compare your code with this solution, which I think works.

1 Like

@sasiram can you try it again? There was a similar issue in Day 100th task which got resolved. I’ve checked it from my side and it worked as expected.

1 Like

@Srikanth_Reddy thank you for availabilty throughout this journey. i have been trying from last 2-3 days. today i just tried with same code and it works.