I would like to define a single Packer template that consists of 3 builds; each one building upon the previous:
source "amazon-ebs" "base" {
source_ami_filter {
filters {
...
}
}
build {
name = "build_1"
source "amazon-ebs.base" {
ami_name = "build-1-ami"
}
}
build {
name = "build_2"
source "amazon-ebs.base" {
ami_name = "build-2-ami
source_ami = build_1.output.ami_id
source_ami_filter { filters = {} }
}
}
build {
name = "build_3"
source "amazon-ebs.base" {
ami_name = "base-3-ami
source_ami = build_2.output.ami_id
source_ami_filter { filters = {} }
}
}
I know that it is possible to chain builders in some way (https://www.packer.io/guides/packer-on-cicd/pipelineing-builds#chaining-together-several-of-the-same-builders-to-make-save-points). However, that example is using Docker and doing it a little more indirectly.
Is it possible to refer directly to the AMI ID produced by a previous build stage? I know build_x.output.ami_id is incorrect but is there a syntax to allow it?
If so, I think I also need to override/unset the source_ami_filter from the source because the documentation says when source_ami and source_ami_filter are used together then source_ami has to meet the other criteria of the filter which won't necessarily be the case.