Consider a terraform module:
module "blah-asg" {
source = "asg"
asg_max_size = 1
asg_min_size = "${var.min_blah}"
...
}
How do I output
variables from it?
output "blah-es-asg" {
value = "${asg.blah-asg.arn}"
}
Which failed with
Error getting plugins: module root: 1 error(s) occurred: * output 'blah-asg': unknown resource 'asg.blah' referenced in variable asg.blah-asg.arn
How can I output module fields in Terraform?
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}"
}
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}"
}