Terraform Modules
https://www.terraform.io/docs/modules/index.html
Modules are used to create reusable components in Terraform as well as for basic code organization
- some interesting public modules https://github.com/terraform-community-modules
- two documentation links http://blog.lusis.org/blog/2015/10/12/terraform-modules-for-fun-and-profit/ and http://www.avitzurel.com/blog/2016/01/05/using-modules-in-terraform/
Read my guide published on linux academy
https://linuxacademy.com/howtoguides/posts/show/topic/12369-how-to-introduction-to-terraform-modules
Read a Value inside a module
If you want to create a resource in your project that depends from a value inside a module you need to use the output configuration to extract the value from the module.
In my example I want create a dns record with the dns name of an ELB created inside a module called FrontEnd
- main project code
module "FrontEnd" {
source = .....
boxname = "FrontEnd"
.....
}
resource "aws_route53_record" "entrypoint" {
zone_id = "xxxxxxxxxxxxxxxxxxx"
name = "entrypoint.mydomain.net"
type = "CNAME"
ttl = "1"
records = ["${module.FrontEnd.dns_elb}"]
}
- module code
resource "aws_elb" "ELB" {
name = "${var.boxname}-ELB"
......
}
output "dns_elb" {
value = "${aws_elb.ELB.dns_name}"
}
versione della pagina: 3, ultima modifica: 14 Dec 2016 09:35