Another useful construct that Terraform provides are outputs. In an output, you define which data you want to be returned by the module. Add the following line to the very bottom of the ./modules/application/application.tf
file:
output "hostname" { value = "${aws_instance.app-server.private_dns}" }
Now you can use this output inside template.tf
like this:
module "crazy_foods" { source = "./modules/application" vpc_id = "${aws_vpc.my_vpc.id}" subnet_id = "${aws_subnet.public.id}" name = "CrazyFoods ${module.mighty_trousers.hostname}" }
Besides the obvious ability to get data from the module, there is another use case for module outputs: forcing dependencies. Here is the graph before passing the output to second module:
Here is the graph with dependency forced:
That's completely different level of graph-beauty, I hope you agree. But sometimes, as we discussed previously, we have to do it. For example...