Terraform: Output a field from a module
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}"
}
The module itself knows nothing of the name blah-asg
- that's just in the script that's calling it - indeed it could be called multiple times with different names and parameters.
The output should just reference things within the module the same way you would elsewhere in that same module. For instance, if you wanted to output the arn of the following resource:
resource "aws_lb" "test" {
# ...
}
You would use:
output "blah-es-asg" {
value = "${aws_lb.test.arn}"
}
Note that the output is defined along side the rest of the module code, not in the script that's calling it.
This output can then by used by the script calling the module as ${module.blah-asg.blah-es-asg}