Terraform:从模块输出一个字段 [英] Terraform: Output a field from a module
本文介绍了Terraform:从模块输出一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑一个 terraform 模块:
Consider a terraform module:
module "blah-asg" {
source = "asg"
asg_max_size = 1
asg_min_size = "${var.min_blah}"
...
}
我的问题
我如何输出
变量从中?
output "blah-es-asg" {
value = "${asg.blah-asg.arn}"
}
失败了
获取插件时出错:模块根目录:发生 1 个错误:* 输出blah-asg":变量 asg.blah-asg.arn 中引用的未知资源asg.blah"
Error getting plugins: module root: 1 error(s) occurred: * output 'blah-asg': unknown resource 'asg.blah' referenced in variable asg.blah-asg.arn
我的问题
如何在 Terraform 中输出模块字段?
My question
How can I output module fields in Terraform?
推荐答案
所以首先需要在模块asg
中设置输出:
So first, you need to set the output in the module asg
:
$ cat asg/output.tf
output "blah-es-asg" {
value = "${aws_autoscaling_group.blah-asg.arn}"
}
然后你用 source = "asg"
调用模块:
Then you call the module with source = "asg"
:
module "blah-asg" {
source = "asg"
asg_max_size = 1
asg_min_size = "${var.min_blah}"
...
}
你现在可以用这种格式在当前代码中输出它:
You can output it in current code with this format now:
output "blah-es-asg" {
value = "${module.blah-asg.blah-es-asg}"
}
这篇关于Terraform:从模块输出一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文