Packer "references unknown source" in a build block in CI
A build block links to sources by name. If the sources = [...] list names a source that no source block defines, Packer cannot wire the build and fails at load.
What this error means
packer validate or build fails with "build references unknown source X" because the name in the build block does not match a declared source.
Error: Unknown source amazon-ebs.ubunto
on build.pkr.hcl line 20, in build:
20: sources = ["source.amazon-ebs.ubunto"]
Known: [source.amazon-ebs.ubuntu]Common causes
A typo in the source reference
The sources list names amazon-ebs.ubunto while the source block is amazon-ebs.ubuntu, so no match is found.
The source block is in a file not loaded
The source is defined in a file outside the directory Packer builds, so it is not part of the loaded config.
How to fix it
Match the source name exactly
- Read the "Known:" list Packer prints.
- Correct the
sourcesentry to match the declared source. - Run
packer validateto confirm the build links.
build {
sources = ["source.amazon-ebs.ubuntu"]
}Build the directory that holds all files
Point Packer at the directory containing every source and build file so all blocks load together.
packer build .How to prevent it
- Keep source and build blocks in the same loaded directory.
- Copy source names to avoid typos in the build block.
- Run
packer validatebefore build to catch broken links.