4

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.

1 Answers1

1

After trying in vain to do this same "chaining" myself, I finally believe the claim made in Packer's documentation that you link to:

Packer templates don't come with a custom "glue" to bind them together. We recommend using your CI system or wrapping scripts to connect the templates into a chain.

The largest problem lies in the fact that Packer builds for AWS AMIs require the source AMI ID in order to do pre-build validations. So if a single template will build two AMIs, neither of them can reference the AMI ID of the other, because that's unknown during pre-build validations.

Indigenuity
  • 111
  • 2