From b6f02d3f77496d873d8fbbab6580a0e7eb894a67 Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Fri, 17 Dec 2021 13:34:44 -0500 Subject: [PATCH] Update handling of image metadata before pushing to registry (#11458) When obtaining image metadata for a HCP Packer build, Packer core will use mapstructure to decode the image metadata and validate that is has all of the required data set. Before this change Packer core would fail if there is extra metadata fields in the image metadata that Packer is not aware. This change removes the restriction of erroring on unused metadata fields. Packer should only care about the fields it knows and ignore the rest. In the future, we will add new fields to the SDK but plugins may begin sending that data sooner. --- packer/registry_builder.go | 2 +- packer/registry_post_processor.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packer/registry_builder.go b/packer/registry_builder.go index 28674f7af..23ac56e2c 100644 --- a/packer/registry_builder.go +++ b/packer/registry_builder.go @@ -73,7 +73,7 @@ func (b *RegistryBuilder) Run(ctx context.Context, ui packersdk.Ui, hook packers decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ Result: &images, WeaklyTypedInput: true, - ErrorUnused: true, + ErrorUnused: false, }) if err != nil { return artifact, fmt.Errorf("failed to create decoder for HCP Packer registry image: %w", err) diff --git a/packer/registry_post_processor.go b/packer/registry_post_processor.go index 6a18e4771..2e9adacc2 100644 --- a/packer/registry_post_processor.go +++ b/packer/registry_post_processor.go @@ -65,7 +65,7 @@ func (p *RegistryPostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ Result: &images, WeaklyTypedInput: true, - ErrorUnused: true, + ErrorUnused: false, }) if err != nil { return source, false, false, fmt.Errorf("failed to create decoder for HCP Packer registry image: %w", err)