mirror of
https://github.com/hashicorp/packer.git
synced 2026-05-27 20:27:18 -04:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package hcl2template
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/go-version"
|
|
"github.com/hashicorp/hcl/v2"
|
|
)
|
|
|
|
// CheckCoreVersionRequirements visits each of the block in the given
|
|
// configuration and verifies that any given Core version constraints match
|
|
// with the version of Packer Core that is being used.
|
|
//
|
|
// The returned diagnostics will contain errors if any constraints do not match.
|
|
// The returned diagnostics might also return warnings, which should be
|
|
// displayed to the user.
|
|
func (cfg *PackerConfig) CheckCoreVersionRequirements(coreVersion *version.Version) hcl.Diagnostics {
|
|
if cfg == nil {
|
|
return nil
|
|
}
|
|
|
|
var diags hcl.Diagnostics
|
|
|
|
for _, constraint := range cfg.Packer.VersionConstraints {
|
|
if !constraint.Required.Check(coreVersion) {
|
|
diags = diags.Append(&hcl.Diagnostic{
|
|
Severity: hcl.DiagError,
|
|
Summary: "Unsupported Packer Core version",
|
|
Detail: fmt.Sprintf(
|
|
"This configuration does not support Packer version %s. To proceed, either choose another supported Packer version or update this version constraint. Version constraints are normally set for good reason, so updating the constraint may lead to other errors or unexpected behavior.",
|
|
coreVersion.String(),
|
|
),
|
|
Subject: constraint.DeclRange.Ptr(),
|
|
})
|
|
}
|
|
}
|
|
|
|
return diags
|
|
}
|