I have used the following code:
module "instance" {
for_each = var.worker_private_ip
source = "../../modules/ec2"
env = var.env
project_name = var.project_name
ami = var.ami
instance_type = var.instance_type
subnet_id = module.vpc.subnet_id
vpc_security_group_ids = [module.security_group.security_group_id]
private_ip = each.value
key_name = var.public_key_name
user_data = file("${path.module}/startup.sh.tpl")
}
When I send terraform plan/apply command, I receive an error
path.module is "."
ā Invalid value for "path" parameter: no file exists at "./startup.sh.tpl";
So, terraform searching for file in current directory, but I expect for searching in (../../modules/ec2/)
I have startup.sh.tpl file in module folder and if I set user_data to:
user_data = file("../../modules/ec2/startup.sh.tpl")
everything is fine, also if I move sciprt to current directory everything ok too, plan and apply commands are correct
What am I doing wrong? Why ${path.module} points to the current directory ".", but not to ../../modules/ec2/?