Good evening,
I’m trying to complete this lab but it fails with “Resources have not been created using ‘terraform’.”
main.tf
# EC2 Instance
resource "aws_instance" "devops-ec2" {
ami = "ami-0c101f26f147fa7fd"
instance_type = "t2.micro"
key_name = "devops-kp"
security_groups = [aws_default_security_group.default.id]
tags = {
Name = "devops-ec2"
}
}
# Default SC
resource "aws_default_security_group" "default" {
vpc_id = aws_aws_default_vpc.default.id
}
# Default VPC
resource "aws_default_vpc" "default" {
tags = {
Name = "Default VPC"
}
}
# EC2 key-pair
resource "aws_key_pair" "devops-kp" {
key_name = "devops-kp"
public_key = tls_private_key.key.public_key_openssh
}
# TLS provider. TLS key
resource "tls_private_key" "key" {
algorithm = "RSA"
rsa_bits = 4096
}
The following Terraform commands were used:
terraform initterraform fmtterraform validateterraform planterraform apply --auto-approve
No error shows in the terminal and I can verify that the instance exists with aws ec2 describe-instances.
What am I doing wrong?
