terraform-provider: require kubernetes and microservice version (#2791)

This commit is contained in:
Adrian Stobbe 2024-01-04 16:25:24 +01:00 committed by GitHub
parent 26a9639bcf
commit f41ce43919
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 157 additions and 133 deletions

View file

@ -8,10 +8,12 @@ package provider
import (
"context"
"fmt"
"regexp"
"testing"
"github.com/edgelesssys/constellation/v2/internal/semver"
"github.com/edgelesssys/constellation/v2/internal/versions"
"github.com/edgelesssys/constellation/v2/terraform-provider-constellation/internal/data"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
@ -21,10 +23,12 @@ import (
"github.com/stretchr/testify/require"
)
var providerVersion = semver.NewFromInt(2, 15, 0, "")
func TestMicroserviceConstraint(t *testing.T) {
sut := &ClusterResource{
providerData: data.ProviderData{
Version: semver.NewFromInt(2, 15, 0, ""),
Version: providerVersion,
},
}
testCases := []struct {
@ -50,7 +54,7 @@ func TestMicroserviceConstraint(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
_, diags := sut.getMicroserviceVersion(context.Background(), &ClusterResourceModel{
_, diags := sut.getMicroserviceVersion(&ClusterResourceModel{
MicroserviceVersion: basetypes.NewStringValue(tc.version),
})
require.Equal(t, tc.expectedErrorCount, diags.ErrorsCount())
@ -208,7 +212,7 @@ func TestAccClusterResource(t *testing.T) {
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
{
Config: fullClusterTestingConfig(t, "aws") + `
Config: fullClusterTestingConfig(t, "aws") + fmt.Sprintf(`
resource "constellation_cluster" "test" {
csp = "aws"
name = "constell"
@ -225,8 +229,10 @@ func TestAccClusterResource(t *testing.T) {
ip_cidr_node = "0.0.0.0/24"
ip_cidr_service = "0.0.0.0/24"
}
kubernetes_version = "%s"
constellation_microservice_version = "%s"
}
`,
`, versions.Default, providerVersion.String()),
ExpectError: regexp.MustCompile(".*Master secret must be a hex-encoded 32-byte.*"),
},
},
@ -236,7 +242,7 @@ func TestAccClusterResource(t *testing.T) {
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
{
Config: fullClusterTestingConfig(t, "aws") + `
Config: fullClusterTestingConfig(t, "aws") + fmt.Sprintf(`
resource "constellation_cluster" "test" {
csp = "aws"
name = "constell"
@ -253,8 +259,10 @@ func TestAccClusterResource(t *testing.T) {
ip_cidr_node = "0.0.0.0/24"
ip_cidr_service = "0.0.0.0/24"
}
kubernetes_version = "%s"
constellation_microservice_version = "%s"
}
`,
`, versions.Default, providerVersion.String()),
ExpectError: regexp.MustCompile(".*Master secret salt must be a hex-encoded 32-byte.*"),
},
},
@ -264,7 +272,7 @@ func TestAccClusterResource(t *testing.T) {
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
{
Config: fullClusterTestingConfig(t, "aws") + `
Config: fullClusterTestingConfig(t, "aws") + fmt.Sprintf(`
resource "constellation_cluster" "test" {
csp = "aws"
name = "constell"
@ -281,8 +289,10 @@ func TestAccClusterResource(t *testing.T) {
ip_cidr_node = "0.0.0.0/24"
ip_cidr_service = "0.0.0.0/24"
}
kubernetes_version = "%s"
constellation_microservice_version = "%s"
}
`,
`, versions.Default, providerVersion.String()),
ExpectError: regexp.MustCompile(".*Measurement salt must be a hex-encoded 32-byte.*"),
},
},
@ -292,7 +302,7 @@ func TestAccClusterResource(t *testing.T) {
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
{
Config: fullClusterTestingConfig(t, "aws") + `
Config: fullClusterTestingConfig(t, "aws") + fmt.Sprintf(`
resource "constellation_cluster" "test" {
csp = "aws"
name = "constell"
@ -309,8 +319,10 @@ func TestAccClusterResource(t *testing.T) {
ip_cidr_node = "0.0.0x.0/xxx"
ip_cidr_service = "0.0.0.0/24"
}
kubernetes_version = "%s"
constellation_microservice_version = "%s"
}
`,
`, versions.Default, providerVersion.String()),
ExpectError: regexp.MustCompile(".*Node IP CIDR must be a valid CIDR.*"),
},
},
@ -320,7 +332,7 @@ func TestAccClusterResource(t *testing.T) {
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
{
Config: fullClusterTestingConfig(t, "aws") + `
Config: fullClusterTestingConfig(t, "aws") + fmt.Sprintf(`
resource "constellation_cluster" "test" {
csp = "aws"
name = "constell"
@ -337,8 +349,10 @@ func TestAccClusterResource(t *testing.T) {
ip_cidr_node = "0.0.0.0/24"
ip_cidr_service = "0.0.0x.0/xxx"
}
kubernetes_version = "%s"
constellation_microservice_version = "%s"
}
`,
`, versions.Default, providerVersion.String()),
ExpectError: regexp.MustCompile(".*Service IP CIDR must be a valid CIDR.*"),
},
},
@ -348,7 +362,7 @@ func TestAccClusterResource(t *testing.T) {
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
{
Config: fullClusterTestingConfig(t, "azure") + `
Config: fullClusterTestingConfig(t, "azure") + fmt.Sprintf(`
resource "constellation_cluster" "test" {
csp = "azure"
name = "constell"
@ -365,8 +379,10 @@ func TestAccClusterResource(t *testing.T) {
ip_cidr_node = "0.0.0.0/24"
ip_cidr_service = "0.0.0.0/24"
}
kubernetes_version = "%s"
constellation_microservice_version = "%s"
}
`,
`, versions.Default, providerVersion.String()),
ExpectError: regexp.MustCompile(".*When csp is set to 'azure', the 'azure' configuration must be set.*"),
},
},
@ -376,7 +392,7 @@ func TestAccClusterResource(t *testing.T) {
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
{
Config: fullClusterTestingConfig(t, "gcp") + `
Config: fullClusterTestingConfig(t, "gcp") + fmt.Sprintf(`
resource "constellation_cluster" "test" {
csp = "gcp"
name = "constell"
@ -394,8 +410,10 @@ func TestAccClusterResource(t *testing.T) {
ip_cidr_service = "0.0.0.0/24"
ip_cidr_pod = "0.0.0.0/24"
}
kubernetes_version = "%s"
constellation_microservice_version = "%s"
}
`,
`, versions.Default, providerVersion.String()),
ExpectError: regexp.MustCompile(".*When csp is set to 'gcp', the 'gcp' configuration must be set.*"),
},
},
@ -405,29 +423,31 @@ func TestAccClusterResource(t *testing.T) {
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
{
Config: fullClusterTestingConfig(t, "gcp") + `
Config: fullClusterTestingConfig(t, "gcp") + fmt.Sprintf(`
resource "constellation_cluster" "test" {
csp = "gcp"
name = "constell"
uid = "test"
image = data.constellation_image.bar.image
attestation = data.constellation_attestation.foo.attestation
init_secret = "deadbeef"
master_secret = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
master_secret_salt = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
measurement_salt = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
out_of_cluster_endpoint = "192.0.2.1"
in_cluster_endpoint = "192.0.2.1"
network_config = {
ip_cidr_node = "0.0.0.0/24"
ip_cidr_service = "0.0.0.0/24"
}
gcp = {
project_id = "test"
service_account_key = "eyJ0ZXN0IjogInRlc3QifQ=="
}
csp = "gcp"
name = "constell"
uid = "test"
image = data.constellation_image.bar.image
attestation = data.constellation_attestation.foo.attestation
init_secret = "deadbeef"
master_secret = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
master_secret_salt = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
measurement_salt = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
out_of_cluster_endpoint = "192.0.2.1"
in_cluster_endpoint = "192.0.2.1"
network_config = {
ip_cidr_node = "0.0.0.0/24"
ip_cidr_service = "0.0.0.0/24"
}
gcp = {
project_id = "test"
service_account_key = "eyJ0ZXN0IjogInRlc3QifQ=="
}
kubernetes_version = "%s"
constellation_microservice_version = "%s"
}
`,
`, versions.Default, providerVersion.String()),
ExpectError: regexp.MustCompile(".*When csp is set to 'gcp', 'ip_cidr_pod' must be set.*"),
},
},