my directory structure
.├── README.md├── ec2│ ├── ec2.tf│ ├── outputs.tf│ └── vars.tf├── main.tf
main.tf
provider "aws" { region = "us-east-1"}module "ec2" { source = "./ec2"}
ec2/ec2.tf
data "aws_ami""example" { most_recent = true owners = ["amazon"] filter { name = "image-id" values = ["ami-0323c3dd2da7fb37d"] } filter { name = "root-device-type" values = ["ebs"] } filter { name = "virtualization-type" values = ["hvm"] }}resource "aws_instance""web" { ami = data.aws_ami.example.id instance_type = "t2.micro" subnet_id = var.subnet_id tags = { Name = "HelloWorld" }}
ec2/avrs.tf
variable "subnet_id" { default = {}}
when i try to pass the subnet_id from outside i'm getting error.
terraform plan -var subnet_id=$subnet_name
Error: Value for undeclared variableA variable named "subnet_id" was assigned on the command line, but the rootmodule does not declare a variable of that name. To use this value, add a"variable" block to the configuration.
if any of you have idea about this issue please help me.