From 4846301ff482157300f32b2eb31011cbc96b3069 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Mon, 28 Nov 2022 16:20:14 -0500 Subject: [PATCH] hcp: reject template type changes between builds As a follow-up to tracking the template type for an iteration, we actively check that it remains consistent between two invocations of packer, and reject the update if it is not the case. --- internal/hcp/registry/types.bucket.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/hcp/registry/types.bucket.go b/internal/hcp/registry/types.bucket.go index 59114999c..e3f3895f2 100644 --- a/internal/hcp/registry/types.bucket.go +++ b/internal/hcp/registry/types.bucket.go @@ -338,6 +338,13 @@ func (b *Bucket) initializeIteration(ctx context.Context, templateType models.Ha return fmt.Errorf("failed to initialize iteration details for Bucket %s with error: %w", b.Slug, err) } + if iteration.TemplateType != nil && + *iteration.TemplateType != models.HashicorpCloudPackerIterationTemplateTypeTEMPLATETYPEUNSET && + *iteration.TemplateType != templateType { + return fmt.Errorf("This iteration was initially created with a %[2]s template. Changing from %[2]s to %[1]s is not supported.", + templateType, *iteration.TemplateType) + } + log.Println("[TRACE] a valid iteration was retrieved with the id", iteration.ID) b.Iteration.ID = iteration.ID