tfversion

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2024 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package tfversion contains the Terraform version check interface, request/response structs, and common version check implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version0_12_26 is the first Terraform CLI version supported
	// by the testing code.
	Version0_12_26 *version.Version = version.Must(version.NewVersion("0.12.26"))

	Version1_0_0 *version.Version = version.Must(version.NewVersion("1.0.0"))
	Version2_0_0 *version.Version = version.Must(version.NewVersion("2.0.0"))

	Version0_13_0 *version.Version = version.Must(version.NewVersion("0.13.0"))
	Version0_14_0 *version.Version = version.Must(version.NewVersion("0.14.0"))
	Version0_15_0 *version.Version = version.Must(version.NewVersion("0.15.0"))
	Version1_1_0  *version.Version = version.Must(version.NewVersion("1.1.0"))
	Version1_2_0  *version.Version = version.Must(version.NewVersion("1.2.0"))
	Version1_3_0  *version.Version = version.Must(version.NewVersion("1.3.0"))
	Version1_4_0  *version.Version = version.Must(version.NewVersion("1.4.0"))
	// Version1_4_6 fixed inclusion of sensitive values in `terraform show -json` output.
	// Reference: https://github.com/hashicorp/terraform/releases/tag/v1.4.6
	Version1_4_6 *version.Version = version.Must(version.NewVersion("1.4.6"))
	Version1_5_0 *version.Version = version.Must(version.NewVersion("1.5.0"))
	Version1_6_0 *version.Version = version.Must(version.NewVersion("1.6.0"))
	Version1_7_0 *version.Version = version.Must(version.NewVersion("1.7.0"))
	Version1_8_0 *version.Version = version.Must(version.NewVersion("1.8.0"))
	Version1_9_0 *version.Version = version.Must(version.NewVersion("1.9.0"))
)

Common use version variables to simplify provider testing implementations. This list is not intended to be exhaustive of all Terraform versions, however these should at least include cases where Terraform introduced new configuration language features.

Functions

This section is empty.

Types

type CheckTerraformVersionRequest

type CheckTerraformVersionRequest struct {
	// TerraformVersion is the version associated with the selected Terraform CLI binary.
	TerraformVersion *version.Version
}

CheckTerraformVersionRequest is the request received for the CheckTerraformVersion method of the TerraformVersionCheck interface. The response of that method is CheckTerraformVersionResponse.

type CheckTerraformVersionResponse

type CheckTerraformVersionResponse struct {
	// Error will result in failing the test with a given error message.
	Error error

	// Skip will result in passing the test with a given skip message.
	Skip string
}

CheckTerraformVersionResponse is the response returned for the CheckTerraformVersion method of the TerraformVersionCheck interface. The request of that method is CheckTerraformVersionRequest.

type TerraformVersionCheck

type TerraformVersionCheck interface {
	// CheckTerraformVersion should implement the logic to either pass, error (failing the test), or skip (passing the test).
	CheckTerraformVersion(context.Context, CheckTerraformVersionRequest, *CheckTerraformVersionResponse)
}

TerraformVersionCheck is the interface for writing check logic against the Terraform CLI version. The Terraform CLI version is determined by the binary selected by the TF_ACC_TERRAFORM_PATH environment variable value, installed by the TF_ACC_TERRAFORM_VERSION value, or already existing based on the PATH environment variable. This logic is executed at the beginning of the TestCase before any TestStep is executed.

This package contains some built-in functionality that implements the interface, otherwise consumers can use this interface for implementing their own custom logic.

func All

func All(terraformVersionChecks ...TerraformVersionCheck) TerraformVersionCheck

All will return the first non-nil error or non-empty skip message if any of the given checks return a non-nil error or non-empty skip message. Otherwise, it will return a nil error and empty skip message (run the test)

Use of All is only necessary when used in conjunction with Any as the TerraformVersionChecks field automatically applies a logical AND.

func Any

func Any(terraformVersionChecks ...TerraformVersionCheck) TerraformVersionCheck

Any will return a nil error and empty skip message (run the test) if any of the given checks return a nil error and empty skip message. Otherwise, it will return all errors and fail the test if any of the given checks return a non-nil error, or it will return all skip messages and skip (pass) the test.

func RequireAbove

func RequireAbove(minimumVersion *version.Version) TerraformVersionCheck

RequireAbove will fail the test if the Terraform CLI version is exclusively below the given version. For example, if given version.Must(version.NewVersion("1.8.0")), then 1.7.x or any other prior versions will fail the test.

Prereleases of Terraform CLI (whether alpha, beta, or rc) are considered equal to a given patch version. For example, if given version.Must(version.NewVersion("1.8.0")), then 1.8.0-rc1 will run, not fail, the test. Terraform prereleases are considered as potential candidates for the upcoming version and therefore are treated as semantically equal for testing. If failing prereleases of the same patch release is desired, give a higher prerelease version. For example, if given version.Must(version.NewVersion("1.8.0-rc2")), then 1.8.0-rc1 will fail the test.

func RequireBelow

func RequireBelow(maximumVersion *version.Version) TerraformVersionCheck

RequireBelow will fail the test if the Terraform CLI version is inclusively above the given version. For example, if given version.Must(version.NewVersion("1.8.0")), then versions 1.8.x and above will fail the test.

Prereleases of Terraform CLI (whether alpha, beta, or rc) are considered equal to a given patch version. For example, if given version.Must(version.NewVersion("1.8.0")), then 1.8.0-rc1 will fail, not run, the test. Terraform prereleases are considered as potential candidates for the upcoming version and therefore are treated as semantically equal for testing purposes. If failing prereleases of the same patch release is desired, give a lower prerelease version. For example, if given version.Must(version.NewVersion("1.8.0-rc1")), then 1.8.0-rc2 will fail the test.

func RequireBetween

func RequireBetween(minimumVersion, maximumVersion *version.Version) TerraformVersionCheck

RequireBetween will fail the test if the Terraform CLI version is outside the given minimum (exclusive) and maximum (inclusive). For example, if given a minimum version of version.Must(version.NewVersion("1.7.0")) and a maximum version of version.Must(version.NewVersion("1.8.0")), then 1.6.x or any other prior versions and versions greater than or equal to 1.8.0 will fail the test.

Prereleases of Terraform CLI (whether alpha, beta, or rc) are considered equal to a given patch version. For example, if given a minimum version of version.Must(version.NewVersion("1.8.0")), then 1.8.0-rc1 will run, not fail, the test. Terraform prereleases are considered as potential candidates for the upcoming version and therefore are treated as semantically equal for testing purposes. If failing prereleases of the same patch release is desired, give a higher prerelease version. For example, if given a minimum version of version.Must(version.NewVersion("1.8.0-rc2")), then 1.8.0-rc1 will fail the test.

func RequireNot

func RequireNot(version *version.Version) TerraformVersionCheck

RequireNot will fail the test if the Terraform CLI version matches the given version.

Prereleases of Terraform CLI (whether alpha, beta, or rc) are considered equal to a given patch version. For example, if given version.Must(version.NewVersion("1.8.0")), then 1.8.0-rc1 will fail, not run, the test. Terraform prereleases are considered as potential candidates for the upcoming version and therefore are treated as semantically equal for testing purposes. If running prereleases of the same patch release is desired, give a different prerelease version. For example, if given version.Must(version.NewVersion("1.8.0-rc2")), then 1.8.0-rc1 will run the test.

func SkipAbove

func SkipAbove(maximumVersion *version.Version) TerraformVersionCheck

SkipAbove will skip (pass) the test if the Terraform CLI version is exclusively above the given version. For example, if given version.Must(version.NewVersion("1.8.0")), then 1.8.x or any other later versions will skip the test.

Prereleases of Terraform CLI (whether alpha, beta, or rc) are considered equal to a given patch version. For example, if given version.Must(version.NewVersion("1.8.0")), then 1.8.0-rc1 will run, not skip, the test. Terraform prereleases are considered as potential candidates for the upcoming version and therefore are treated as semantically equal for testing. If skipping prereleases of the same patch release is desired, give a lower prerelease version. For example, if given version.Must(version.NewVersion("1.8.0-rc1")), then 1.8.0-rc2 will skip the test.

func SkipBelow

func SkipBelow(minimumVersion *version.Version) TerraformVersionCheck

SkipBelow will skip (pass) the test if the Terraform CLI version is exclusively below the given version. For example, if given version.Must(version.NewVersion("1.8.0")), then 1.7.x or any other prior versions will skip the test.

Prereleases of Terraform CLI (whether alpha, beta, or rc) are considered equal to a given patch version. For example, if given version.Must(version.NewVersion("1.8.0")), then 1.8.0-rc1 will run, not skip, the test. Terraform prereleases are considered as potential candidates for the upcoming version and therefore are treated as important for testing to run. If skipping prereleases of the same patch release is desired, give a higher prerelease version. For example, if given version.Must(version.NewVersion("1.8.0-rc2")), then 1.8.0-rc1 will skip the test.

func SkipBetween

func SkipBetween(minimumVersion, maximumVersion *version.Version) TerraformVersionCheck

SkipBetween will skip the test if the Terraform CLI version is between the given minimum (inclusive) and maximum (exclusive). For example, if given a minimum version of version.Must(version.NewVersion("1.7.0")) and a maximum version of version.Must(version.NewVersion("1.8.0")), then versions 1.7.x will skip the test.

Prereleases of Terraform CLI (whether alpha, beta, or rc) are considered equal to a given patch version. For example, if given a minimum version of version.Must(version.NewVersion("1.8.0")), then 1.8.0-rc1 will skip, not run, the test. Terraform prereleases are considered as potential candidates for the upcoming version and therefore are treated as semantically equal for testing purposes. If running prereleases of the same patch release is desired, give a higher prerelease version. For example, if given a minimum version of version.Must(version.NewVersion("1.8.0-rc2")), then 1.8.0-rc1 will run the test.

func SkipIf

func SkipIf(version *version.Version) TerraformVersionCheck

SkipIf will skip (pass) the test if the Terraform CLI version matches the given version.

Prereleases of Terraform CLI (whether alpha, beta, or rc) are considered equal to a given patch version. For example, if given version.Must(version.NewVersion("1.8.0")), then 1.8.0-rc1 will skip, not run, the test. Terraform prereleases are considered as potential candidates for the upcoming version and therefore are treated as semantically equal for testing purposes. If running prereleases of the same patch release is desired, give a different prerelease version. For example, if given version.Must(version.NewVersion("1.8.0-rc2")), then 1.8.0-rc1 will run the test.

func SkipIfNotPrerelease added in v1.8.0

func SkipIfNotPrerelease() TerraformVersionCheck

SkipIfNotPrerelease will skip (pass) the test if the Terraform CLI version does not include prerelease information. This will include builds of Terraform that are from source. (e.g. 1.8.0-dev)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL