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 with variables.
Note
We did not look much into Terraform variables in general till now, and most of the content on this topic is explained in Chapter 4, Storing and Supplying Configuration. For now, let's get...