Review Project
Let’s explore the generated app folder.
App Modules
Let’s check out the app/modules/example folder.
main.tf
resource "google_storage_bucket" "this" {
name = var.name
uniform_bucket_level_access = var.uniform_bucket_level_access
location = var.location
}
variables.tf
variable "name" {
description = "bucket name (required)"
type = string
}
variable "uniform_bucket_level_access" {
description = "uniform_bucket_level_access"
type = bool
default = false
}
variable "location" {
description = "location"
type = string
default = "US"
}
You can see that the starter example module creates an gcs bucket.
Stack Modules
Next let’s look at the generated app/stacks/demo that was created:
app/stacks/demo/main.tf
resource "random_pet" "this" {
length = 2
}
module "bucket" {
source = "../../modules/example"
name = "bucket-${random_pet.this.id}"
uniform_bucket_level_access = var.uniform_bucket_level_access
location = var.location
}
You can see that it’s just another terraform module, that will use the app/modules/example module. It uses the random_pet resource to provide a random but friendly name for the gcs bucket.
Modules vs Stacks
Both modules and stacks are terraform modules. The difference is organizational and how they are can be used.
- Modules are reusable pieces of code. Generally, it contains non-business specific logic.
- Stacks can be used to group together modules. Generally, this is where more business-specific logic can go.
For example, the app1 stack could be designed to use an instance module. Another, app2 stack could use an instance and rds modules.
There are no hard rules. Stacks can be reusable and you provide the tfvars config. It’s up to you. Here are some more Tfvars Location Thoughts.
Next, we’ll deploy the infrastructure.