Review Project
Let’s explore the generated app folder.
App Modules
Let’s check out the app/modules/example
folder.
main.tf
resource "random_pet" "this" {
length = var.length
}
variables.tf
variable "length" {
type = number
description = "number of words"
default = 2
}
You can see that the starter example module creates a random_pet
resource.
Stack Modules
Next let’s look at the generated app/stacks/demo
that was created:
app/stacks/demo/main.tf
module "pet" {
source = "../../modules/example"
length = var.length
}
You can see that it’s just another terraform module, that will use the app/modules/example
module to create the random_pet
.
Modules vs Stacks
Both modules and stacks are terraform modules. The difference is organizational and how they are meant to be used.
- Modules are reusable pieces of code. Generally, it contains non-business specific logic.
- Stacks are meant to be used to group together modules. Generally, this is where business-specific logic goes.
For example, the app1
stack could be designed to use a server
module. Another, app2
stack could use a server
and a database
modules.
Next, we’ll deploy the infrastructure.