I meant a module in the Terraform sense of the word. This applies only to a particular subset of modules that contain things that can temporarily coexist during a staged rollout, but it’d look something like this:
module "example_v1" {
source = "example.com/example/example"
version = "1.0.0"
name_suffix = "v1"
}
module "example_v2" {
source = "example.com/example/example"
version = "2.0.0"
name_suffix = "v2"
}
The sequence of steps I was describing would have this configuration start off with only module "example_v1"
, and then during rollout both of them are temporarily present for the first step and then finally module "example_v1"
is removed once module "example_v2"
is up and running, returning to only having one module.
As you can see, there is no specific mention of “blue” or “green” in this case. This is exploiting the ephemeral nature of cloud infrastructure to bring up totally new infrastructure for each new release, rather than to pivot back and forth between two long-lived instances. In a sense I suppose strictly this is a “blue/green-like” approach, rather than strictly blue/green: the sense of a particular cluster being blue or green is replaced by the idea of “older/newer”, or “previous/next”, with each “generation” of the infrastructure having a version number associated with it.
In the other example of pivoting between two long-lived instances (called “blue” and “green”, probably), in the specific system I was thinking of where I did something like that the module was set up to take a count and an image id as input variables:
variable "blue" {
type = object({
image = string
count = number
})
default = {
image = null
count = 0
}
}
variable "green" {
type = object({
image = string
count = number
})
default = {
image = null
count = 0
}
}
module "blue" {
source = "./modules/bluegreen"
image_id = var.blue.image
instance_count = var.blue.count
}
module "green" {
source = "./modules/bluegreen"
image_id = var.green.image
instance_count = var.green.count
}
In this case, the “steady state” (while a rollout isn’t in progress) is for one of them to have count = 0
set so that nothing exists for it. So in my case I had the image id as part of the objects being created, since I expected them to be recreated each time we rolled stuff out anyway.
If that isn’t true for you and you intend to leave both the blue and green objects running indefinitely then I would think you would use object names containing “blue” and “green” so that the ones that don’t need to be recreated when the image id changes will be undisturbed.