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

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}"
}
Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License