Cant solve a " not been declared in the root module " ERROR

i have a single folder in which i have 2 files

  1. config.yml

in my config.yml the data is -

ami: ami-12345678
instance_type: t2.micro
name: my-instance

in my i have -

provider “aws” {
region = “us-east-2”
access_key= “AKIASDBYCJ62########”
secret_key= “B48Vgh4nRaTMuQDpki8ih2/TYR1M####@@@@#@#@”

locals {
my_yaml_data = yamldecode(file(“./config.yml”))

resource “aws_instance” “my_instance” {

source = “./config.yml”

ami = config.yml.ami
instance_type = config.yml.instance_type
name =

NOW when i do terraform plan i get a error =

  • Reference to undeclared resource , A managed resource “config” “yml” has not been declared in the root module.

i did everything but i cant solve this error. i;m new to terraform and yml data parcing

Welcome to the forum - please reformat your message

You just made up some imaginary syntax here. config.yml should be local.my_yaml_data.

i’m a fresher and terraform is new to me
i apologies for any silly mistakes.

yes sir it worked!
thank you alot…
i’ll be a good journey
learning terraform