Configuring modules

Let's list the data we need to pass to the module:

  • Name of the application
  • VPC ID
  • Subnet ID

That should be sufficient for now. Update the module inside template.tf to look as follows:

module "mighty_trousers" { 
  source = "./modules/application" 
  vpc_id = "${aws_vpc.my_vpc.id}" 
  subnet_id = "${aws_subnet.public.id}" 
  name = "MightyTrousers" 
} 

Passing data like this is not enough, though. We need to define variables inside the module template. The thing is, our tempate.tf is a module itself, a special module named root module. That's what you saw on the last graph we drew--resources were coming from the root module. So, we were actually already using modules all this time, and every module, including the root module, can be configured ...

Get Getting Started with Terraform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.