2023-05-02 11:33:06 -04:00
|
|
|
// Copyright IBM Corp. 2014, 2026
|
2023-08-10 18:43:27 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-05-02 11:33:06 -04:00
|
|
|
|
2017-10-19 19:08:35 -04:00
|
|
|
// The version package provides a location to set the release versions for all
|
|
|
|
|
// packages to consume, without creating import cycles.
|
|
|
|
|
//
|
2018-06-09 20:27:53 -04:00
|
|
|
// This package should not import any other terraform packages.
|
2017-10-19 19:08:35 -04:00
|
|
|
package version
|
|
|
|
|
|
|
|
|
|
import (
|
2023-04-03 23:38:30 -04:00
|
|
|
_ "embed"
|
2017-10-19 19:08:35 -04:00
|
|
|
"fmt"
|
2023-04-03 23:38:30 -04:00
|
|
|
"strings"
|
2017-10-19 19:08:35 -04:00
|
|
|
|
|
|
|
|
version "github.com/hashicorp/go-version"
|
|
|
|
|
)
|
|
|
|
|
|
2023-04-03 23:38:30 -04:00
|
|
|
// rawVersion is the current version as a string, as read from the VERSION
|
|
|
|
|
// file. This must be a valid semantic version.
|
|
|
|
|
//
|
|
|
|
|
//go:embed VERSION
|
|
|
|
|
var rawVersion string
|
|
|
|
|
|
|
|
|
|
// dev determines whether the -dev prerelease marker will
|
|
|
|
|
// be included in version info. It is expected to be set to "no" using
|
|
|
|
|
// linker flags when building binaries for release.
|
|
|
|
|
var dev string = "yes"
|
2017-10-19 19:08:35 -04:00
|
|
|
|
2023-04-03 23:38:30 -04:00
|
|
|
// The main version number that is being run at the moment, populated from the raw version.
|
|
|
|
|
var Version string
|
2017-10-19 19:08:35 -04:00
|
|
|
|
2023-04-03 23:38:30 -04:00
|
|
|
// A pre-release marker for the version, populated using a combination of the raw version
|
|
|
|
|
// and the dev flag.
|
|
|
|
|
var Prerelease string
|
|
|
|
|
|
|
|
|
|
// SemVer is an instance of version.Version representing the main version
|
|
|
|
|
// without any prerelease information.
|
2018-11-13 18:51:01 -05:00
|
|
|
var SemVer *version.Version
|
|
|
|
|
|
|
|
|
|
func init() {
|
2023-04-03 23:38:30 -04:00
|
|
|
semVerFull := version.Must(version.NewVersion(strings.TrimSpace(rawVersion)))
|
|
|
|
|
SemVer = semVerFull.Core()
|
|
|
|
|
Version = SemVer.String()
|
|
|
|
|
|
|
|
|
|
if dev == "no" {
|
|
|
|
|
Prerelease = semVerFull.Prerelease()
|
|
|
|
|
} else {
|
|
|
|
|
Prerelease = "dev"
|
|
|
|
|
}
|
2018-11-13 18:51:01 -05:00
|
|
|
}
|
2017-10-19 19:08:35 -04:00
|
|
|
|
|
|
|
|
// Header is the header name used to send the current terraform version
|
|
|
|
|
// in http requests.
|
|
|
|
|
const Header = "Terraform-Version"
|
|
|
|
|
|
|
|
|
|
// String returns the complete version string, including prerelease
|
|
|
|
|
func String() string {
|
2017-10-19 21:48:08 -04:00
|
|
|
if Prerelease != "" {
|
|
|
|
|
return fmt.Sprintf("%s-%s", Version, Prerelease)
|
2017-10-19 19:08:35 -04:00
|
|
|
}
|
2017-10-19 21:48:08 -04:00
|
|
|
return Version
|
2017-10-19 19:08:35 -04:00
|
|
|
}
|