我有一个平面结构的所有.tf文件,并希望迁移到一个基于文件夹(即module)的设置,以便我的代码更加清晰。
例如,我将实例和弹性IP (eip)定义移动到单独的文件夹中。
/terraform
../instance
../instance.tf
../eip
../eip.tf在我的instance.tf里
resource "aws_instance" "rancher-node-production" {}在我的eip.tf里
module "instance" {
source = "../instance"
}
resource "aws_eip" "rancher-node-production-eip" {
instance = "${module.instance.rancher-node-production.id}"但是,当运行terraform plan时
错误:资源‘aws_eip.rancher-节点-生产-eip’配置:“rancher-节点-production.id”不是模块“实例”的有效输出。
发布于 2018-04-26 16:20:12
将模块看作是您无法“到达”的黑匣子。要从模块中获取数据,该模块需要使用output导出该数据。因此,在您的示例中,需要将rancher-node-production id声明为instance模块的输出。
如果您查看所得到的错误,这正是它的意思:rancher-node-production.id不是模块的有效输出(因为您从未将它定义为输出)。
不管怎么说,这就是它的样子。
# instance.tf
resource "aws_instance" "rancher-node-production" {}
output "rancher-node-production" {
value = {
id = "${aws_instance.rancher-node-production.id}"
}
}希望能帮你解决这个问题。
https://stackoverflow.com/questions/50040451
复制相似问题