访问资源内的资源variables

我收到错误“错误询问用户input:发生了1个错误:

  • 周期:template_file.init,aws_instance.tcmongodbprimary“

当我尝试访问我刚刚创build的资源时。 以下是我使用的代码

开始 – 创buildMongoDB主实例

资源“aws_instance”“tcmongodbprimary”{

ami =“$ {var.mongo_db_ami}”

instance_type =“$ {var.instance_type}”

security_groups = [“$ {aws_security_group.tcmsg.id}”]

subnet_id =“subnet-f54db7be”

iam_instance_profile =“$ {aws_iam_instance_profile.tcmdbip.name}”

availability_zone =“us-east-1d”

key_name =“$ {var.instance_type_key_name}”

标签{Name =“Terraform Currency MongoDB Primary”}

root_block_device {

volume_type = "gp2" volume_size = 50 delete_on_termination = true 

}

ebs_block_device {

 device_name = "/dev/sdf" volume_type = "gp2" volume_size = 50 delete_on_termination = true 

}

user_data =“$ {template_file.init.rendered}”

}

结束 – 创buildMongoDB主实例

资源“template_file”“init”{

template =“$ {file(”files / attach_ebs.sh“)}”

variables{

 replica_set = "curr_rs" hostip = "${aws_instance.tcmongodbprimary.private_ip}" hostname = "test" 

}

}

当我尝试分配时,在资源“template_file”中出现错误

hostip =“$ {aws_instance.tcmongodbprimary.private_ip}”。 如果这是硬编码,我不会得到任何错误。 我需要在sh文件中执行hostip和hostname。

谢谢