Below is the code i have given but getting an error:-
data “aws_ami” “ami”{
most_recent = true
owners = [“xxxxxxxxxxx612”]
filter{
name = “image_id”
values = [“amazn2-ami-hvm-*-x86_64-ebs”]
}
}
resource “aws_instance” “myec2server”{
ami = “${data.aws_ami.image_id}”
instance_type = “t2.micro”
// key_name = data.aws_key_pair.mykey
subnet_id = “subnet-0b7b185d847c9323e”
tags = {
Name = “MK”
Error: Reference to undeclared resource
│
│ on ec2.tf line 19, in resource “aws_instance” “myec2server”:
│ 19: ami = “${data.aws_ami.image_id}”
│
│ A data resource “aws_ami” “image_id” has not been declared in the root module.