terraform-provider-stackitp.../stackit/internal/services/postgresflexalpha/postgresflex_acc_test.go
Marcel S. Henselin 22c414769e
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 6s
CI Workflow / CI (pull_request) Failing after 6m37s
CI Workflow / Code coverage report (pull_request) Has been skipped
CI Workflow / Test readiness for publishing provider (pull_request) Successful in 23m59s
chore: refactor tests
2026-02-10 17:43:58 +01:00

862 lines
28 KiB
Go

package postgresflexalpha_test
import (
"context"
_ "embed"
"fmt"
"os"
"strconv"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
postgresflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils"
// The fwresource import alias is so there is no collision
// with the more typical acceptance testing import:
// "github.com/hashicorp/terraform-plugin-testing/helper/resource"
fwresource "github.com/hashicorp/terraform-plugin-framework/resource"
)
func TestInstanceResourceSchema(t *testing.T) {
t.Parallel()
ctx := context.Background()
schemaRequest := fwresource.SchemaRequest{}
schemaResponse := &fwresource.SchemaResponse{}
// Instantiate the resource.Resource and call its Schema method
postgresflexalpha.NewInstanceResource().Schema(ctx, schemaRequest, schemaResponse)
if schemaResponse.Diagnostics.HasError() {
t.Fatalf("Schema method diagnostics: %+v", schemaResponse.Diagnostics)
}
// Validate the schema
diagnostics := schemaResponse.Schema.ValidateImplementation(ctx)
if diagnostics.HasError() {
t.Fatalf("Schema validation diagnostics: %+v", diagnostics)
}
}
var (
//go:embed testdata/resource-no-enc.tf
resourceConfigNoEnc string //nolint:unused // needs implementation
//go:embed testdata/resource-enc.tf
resourceConfigEnc string //nolint:unused // needs implementation
)
func TestMain(m *testing.M) {
testutils.Setup()
code := m.Run()
// shutdown()
os.Exit(code)
}
//var (
// validFlavor = "2.4"
// kekKeyRingId = ""
// kekKeyVersion = ""
// kekKeySA = ""
//)
func testAccPreCheck(t *testing.T) {
if _, ok := os.LookupEnv("TF_ACC_PROJECT_ID"); !ok {
t.Fatalf("could not find env var TF_ACC_PROJECT_ID")
}
}
//func TestAccResourceExample_parallel(t *testing.T) {
// t.Parallel()
//
// exData := resData{
// Region: "eu01",
// ServiceAccountFilePath: sa_file,
// ProjectID: project_id,
// Name: acctest.RandomWithPrefix("tf-acc"),
// }
//
// resource.Test(t, resource.TestCase{
// ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
// Steps: []resource.TestStep{
// {
// Config: testAccResourceEncryptionExampleConfig(exData),
// Check: resource.TestCheckResourceAttrSet("example_resource.test", "id"),
// },
// },
// })
//}
type resData struct {
ServiceAccountFilePath string
ProjectId string
Region string
Name string
TfName string
FlavorId string
BackupSchedule string
UseEncryption bool
KekKeyId string
KekKeyRingId string
KekKeyVersion uint8
KekServiceAccount string
PerformanceClass string
Replicas uint32
Size uint32
AclString string
AccessScope string
RetentionDays uint32
Version string
}
func getExample() resData {
name := acctest.RandomWithPrefix("tf-acc")
return resData{
Region: os.Getenv("TF_ACC_REGION"),
ServiceAccountFilePath: os.Getenv("TF_ACC_SERVICE_ACCOUNT_FILE"),
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
Name: name,
TfName: name,
FlavorId: "2.4",
BackupSchedule: "0 0 * * *",
UseEncryption: false,
RetentionDays: 33,
Replicas: 1,
PerformanceClass: "premium-perf2-stackit",
Size: 10,
AclString: "0.0.0.0/0",
AccessScope: "PUBLIC",
Version: "17",
}
}
func TestAccResourceExample_basic(t *testing.T) {
exData := getExample()
resName := fmt.Sprintf(
"stackitprivatepreview_postgresflexalpha_instance.%s",
exData.TfName,
)
updNameData := exData
updNameData.Name = "name-updated"
updSizeData := exData
updSizeData.Size = 25
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
exData,
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resName, "name", exData.Name),
resource.TestCheckResourceAttrSet(resName, "id"),
),
},
// Update name and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
updNameData,
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resName, "name", updNameData.Name),
),
},
// Update size and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
updSizeData,
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
resName,
"storage.size",
strconv.Itoa(int(updSizeData.Size)),
),
),
},
//// Import test
//{
// ResourceName: "example_resource.test",
// ImportState: true,
// ImportStateVerify: true,
//},
},
})
}
//func setupMockServer() *httptest.Server {
// mux := http.NewServeMux()
//
// mux.HandleFunc("/api/resources", func(w http.ResponseWriter, r *http.Request) {
// switch r.Method {
// case http.MethodPost:
// w.WriteHeader(http.StatusCreated)
// err := json.NewEncoder(w).Encode(map[string]string{
// "id": "mock-id-123",
// "name": "test-resource",
// })
// if err != nil {
// log.Fatalln(err)
// }
// case http.MethodGet:
// w.WriteHeader(http.StatusOK)
// err := json.NewEncoder(w).Encode([]map[string]string{})
// if err != nil {
// log.Fatalln(err)
// }
// }
// })
//
// return httptest.NewServer(mux)
//}
//
//func TestUnitResourceCreate(t *testing.T) {
// server := setupMockServer()
// defer server.Close()
//
// // Configure provider to use mock server URL
// err := os.Setenv("API_ENDPOINT", server.URL)
// if err != nil {
// log.Fatalln(err)
// }
//
// // Run unit tests against mock
//}
// type postgresFlexClientMocked struct {
// returnError bool
// getFlavorsResp *postgresflex.GetFlavorsResponse
// }
//
// func (c *postgresFlexClientMocked) ListFlavorsExecute(_ context.Context, _, _ string) (*postgresflex.GetFlavorsResponse, error) {
// if c.returnError {
// return nil, fmt.Errorf("get flavors failed")
// }
//
// return c.getFlavorsResp, nil
// }
//func TestNewInstanceResource(t *testing.T) {
// exData := resData{
// Region: "eu01",
// ServiceAccountFilePath: sa_file,
// ProjectID: project_id,
// Name: "testRes",
// }
// resource.Test(t, resource.TestCase{
// ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
// Steps: []resource.TestStep{
// {
// Config: testAccResourceEncryptionExampleConfig(exData),
// Check: resource.ComposeAggregateTestCheckFunc(
// resource.TestCheckResourceAttr("example_resource.test", "name", exData.Name),
// resource.TestCheckResourceAttrSet("example_resource.test", "id"),
// ),
// },
// },
// })
//
// //tests := []struct {
// // name string
// // want resource.Resource
// //}{
// // {
// // name: "create empty instance resource",
// // want: &instanceResource{},
// // },
// //}
// //for _, tt := range tests {
// // t.Run(tt.name, func(t *testing.T) {
// // if got := NewInstanceResource(); !reflect.DeepEqual(got, tt.want) {
// // t.Errorf("NewInstanceResource() = %v, want %v", got, tt.want)
// // }
// // })
// //}
//}
//// Instance resource data
//var instanceResource = map[string]string{
// "project_id": testutils.ProjectId,
// "region": "eu01",
// "name": fmt.Sprintf("tf-acc-%s", acctest.RandStringFromCharSet(7, acctest.CharSetAlphaNum)),
// "acl": "192.168.0.0/16",
// "backup_schedule": "00 16 * * *",
// "backup_schedule_updated": "00 12 * * *",
// "retention_days": "33",
// "flavor_cpu": "2",
// "flavor_ram": "4",
// "flavor_description": "Small, Compute optimized",
// "replicas": "1",
// "storage_class": "premium-perf12-stackit",
// "storage_size": "5",
// "version": "14",
// "flavor_id": "2.4",
// "kek_key_id": "UUID1",
// "kek_key_ring_id": "UUID2",
// "kek_key_version": "1",
// "service_account": "service@account.com",
// "access_scope": "SNA",
//}
//
//// User resource data
//var userResource = map[string]string{
// "username": fmt.Sprintf("tfaccuser%s", acctest.RandStringFromCharSet(4, acctest.CharSetAlpha)),
// "role": "createdb",
// "project_id": testutils.ProjectId,
//}
//
//// Database resource data
//var databaseResource = map[string]string{
// "name": fmt.Sprintf("tfaccdb%s", acctest.RandStringFromCharSet(4, acctest.CharSetAlphaNum)),
// "project_id": testutils.ProjectId,
//}
//
//func configResources(backupSchedule string, _ *string) string {
// return fmt.Sprintf(
// `
// %s
//
//
// resource "stackitprivatepreview_postgresflexalpha_instance" "instance" {
// project_id = "%s"
// region = "%s"
// name = "%s"
// backup_schedule = "%s"
// retention_days = %s
// flavor_id = %s
// replicas = %s
// storage = {
// performance_class = "%s"
// size = %s
// }
// encryption = {
// kek_key_id = "%s"
// kek_key_ring_id = "%s"
// kek_key_version = "%s"
// service_account = "%s"
// }
// network = {
// acl = ["%s"]
// access_scope = "%s"
// }
// version = %s
// }
//
// resource "stackitprivatepreview_postgresflexalpha_user" "user" {
// project_id = "%s"
// instance_id = stackitprivatepreview_postgresflexalpha_instance.instance.instance_id
// username = "%s"
// roles = ["%s"]
// }
//
// resource "stackitprivatepreview_postgresflexalpha_database" "database" {
// project_id = "%s"
// instance_id = stackitprivatepreview_postgresflexalpha_instance.instance.instance_id
// name = "%s"
// owner = stackitprivatepreview_postgresflexalpha_user.user.username
// }
// `,
// testutils.PostgresFlexProviderConfig(
// utils.GetEnvOrDefault("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_FILE", "~/service-account.json"),
// ),
// instanceResource["project_id"],
// instanceResource["region"],
// instanceResource["name"],
// backupSchedule,
// instanceResource["retention_days"],
// instanceResource["flavor_id"],
// instanceResource["replicas"],
// instanceResource["storage_class"],
// instanceResource["storage_size"],
// instanceResource["kek_key_id"],
// instanceResource["kek_key_ring_id"],
// instanceResource["kek_key_version"],
// instanceResource["service_account"],
// instanceResource["acl"],
// instanceResource["access_scope"],
// instanceResource["version"],
//
// userResource["project_id"],
// userResource["username"],
// userResource["role"],
//
// databaseResource["project_id"],
// databaseResource["name"],
// )
//}
//
//func TestAccPostgresFlexFlexResource(t *testing.T) {
// resource.Test(
// t, resource.TestCase{
// ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
// CheckDestroy: testAccCheckPostgresFlexDestroy,
// Steps: []resource.TestStep{
// // Creation
// {
// // testdata/<Test_Name>
// // ConfigDirectory: config.TestNameDirectory(),
//
// // testdata/<Test_Name>/<step_number>
// // ConfigDirectory: config.TestStepDirectory(),
// Config: configResources(instanceResource["backup_schedule"], &testutils.Region),
// Check: resource.ComposeAggregateTestCheckFunc(
// // Instance
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "project_id",
// instanceResource["project_id"],
// ),
// resource.TestCheckResourceAttrSet(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "instance_id",
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "name",
// instanceResource["name"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "acl.#",
// "1",
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "acl.0",
// instanceResource["acl"],
// ),
// resource.TestCheckResourceAttrSet(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.id",
// ),
// resource.TestCheckResourceAttrSet(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.description",
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "backup_schedule",
// instanceResource["backup_schedule"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.cpu",
// instanceResource["flavor_cpu"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.ram",
// instanceResource["flavor_ram"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "replicas",
// instanceResource["replicas"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "storage.class",
// instanceResource["storage_class"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "storage.size",
// instanceResource["storage_size"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "version",
// instanceResource["version"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "region",
// testutils.Region,
// ),
//
// // User
// resource.TestCheckResourceAttrPair(
// "stackitprivatepreview_postgresflexalpha_user.user", "project_id",
// "stackitprivatepreview_postgresflexalpha_instance.instance", "project_id",
// ),
// resource.TestCheckResourceAttrPair(
// "stackitprivatepreview_postgresflexalpha_user.user", "instance_id",
// "stackitprivatepreview_postgresflexalpha_instance.instance", "instance_id",
// ),
// resource.TestCheckResourceAttrSet("stackitprivatepreview_postgresflexalpha_user.user", "user_id"),
// resource.TestCheckResourceAttrSet("stackitprivatepreview_postgresflexalpha_user.user", "password"),
//
// // Database
// resource.TestCheckResourceAttrPair(
// "stackitprivatepreview_postgresflexalpha_database.database", "project_id",
// "stackitprivatepreview_postgresflexalpha_instance.instance", "project_id",
// ),
// resource.TestCheckResourceAttrPair(
// "stackitprivatepreview_postgresflexalpha_database.database", "instance_id",
// "stackitprivatepreview_postgresflexalpha_instance.instance", "instance_id",
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_database.database",
// "name",
// databaseResource["name"],
// ),
// resource.TestCheckResourceAttrPair(
// "stackitprivatepreview_postgresflexalpha_database.database", "owner",
// "stackitprivatepreview_postgresflexalpha_user.user", "username",
// ),
// ),
// },
// // data source
// {
// Config: fmt.Sprintf(
// `
// %s
//
// data "stackitprivatepreview_postgresflexalpha_instance" "instance" {
// project_id = stackitprivatepreview_postgresflexalpha_instance.instance.project_id
// instance_id = stackitprivatepreview_postgresflexalpha_instance.instance.instance_id
// }
//
// data "stackitprivatepreview_postgresflexalpha_user" "user" {
// project_id = stackitprivatepreview_postgresflexalpha_instance.instance.project_id
// instance_id = stackitprivatepreview_postgresflexalpha_instance.instance.instance_id
// user_id = stackitprivatepreview_postgresflexalpha_user.user.user_id
// }
//
// data "stackitprivatepreview_postgresflexalpha_database" "database" {
// project_id = stackitprivatepreview_postgresflexalpha_instance.instance.project_id
// instance_id = stackitprivatepreview_postgresflexalpha_instance.instance.instance_id
// database_id = stackitprivatepreview_postgresflexalpha_database.database.database_id
// }
// `,
// configResources(instanceResource["backup_schedule"], nil),
// ),
// Check: resource.ComposeAggregateTestCheckFunc(
// // Instance data
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance",
// "project_id",
// instanceResource["project_id"],
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance",
// "name",
// instanceResource["name"],
// ),
// resource.TestCheckResourceAttrPair(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance", "project_id",
// "stackitprivatepreview_postgresflexalpha_instance.instance", "project_id",
// ),
// resource.TestCheckResourceAttrPair(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance", "instance_id",
// "stackitprivatepreview_postgresflexalpha_instance.instance", "instance_id",
// ),
// resource.TestCheckResourceAttrPair(
// "data.stackitprivatepreview_postgresflexalpha_user.user", "instance_id",
// "stackitprivatepreview_postgresflexalpha_user.user", "instance_id",
// ),
//
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance",
// "acl.#",
// "1",
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance",
// "acl.0",
// instanceResource["acl"],
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance",
// "backup_schedule",
// instanceResource["backup_schedule"],
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.id",
// instanceResource["flavor_id"],
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.description",
// instanceResource["flavor_description"],
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.cpu",
// instanceResource["flavor_cpu"],
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.ram",
// instanceResource["flavor_ram"],
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_instance.instance",
// "replicas",
// instanceResource["replicas"],
// ),
//
// // User data
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_user.user",
// "project_id",
// userResource["project_id"],
// ),
// resource.TestCheckResourceAttrSet(
// "data.stackitprivatepreview_postgresflexalpha_user.user",
// "user_id",
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_user.user",
// "username",
// userResource["username"],
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_user.user",
// "roles.#",
// "1",
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_user.user",
// "roles.0",
// userResource["role"],
// ),
// resource.TestCheckResourceAttrSet(
// "data.stackitprivatepreview_postgresflexalpha_user.user",
// "host",
// ),
// resource.TestCheckResourceAttrSet(
// "data.stackitprivatepreview_postgresflexalpha_user.user",
// "port",
// ),
//
// // Database data
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_database.database",
// "project_id",
// instanceResource["project_id"],
// ),
// resource.TestCheckResourceAttr(
// "data.stackitprivatepreview_postgresflexalpha_database.database",
// "name",
// databaseResource["name"],
// ),
// resource.TestCheckResourceAttrPair(
// "data.stackitprivatepreview_postgresflexalpha_database.database",
// "instance_id",
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "instance_id",
// ),
// resource.TestCheckResourceAttrPair(
// "data.stackitprivatepreview_postgresflexalpha_database.database",
// "owner",
// "data.stackitprivatepreview_postgresflexalpha_user.user",
// "username",
// ),
// ),
// },
// // Import
// {
// ResourceName: "stackitprivatepreview_postgresflexalpha_instance.instance",
// ImportStateIdFunc: func(s *terraform.State) (string, error) {
// r, ok := s.RootModule().Resources["stackitprivatepreview_postgresflexalpha_instance.instance"]
// if !ok {
// return "", fmt.Errorf("couldn't find resource stackitprivatepreview_postgresflexalpha_instance.instance")
// }
// instanceId, ok := r.Primary.Attributes["instance_id"]
// if !ok {
// return "", fmt.Errorf("couldn't find attribute instance_id")
// }
//
// return fmt.Sprintf("%s,%s,%s", testutils.ProjectId, testutils.Region, instanceId), nil
// },
// ImportState: true,
// ImportStateVerify: true,
// ImportStateVerifyIgnore: []string{"password"},
// },
// {
// ResourceName: "stackitprivatepreview_postgresflexalpha_user.user",
// ImportStateIdFunc: func(s *terraform.State) (string, error) {
// r, ok := s.RootModule().Resources["stackitprivatepreview_postgresflexalpha_user.user"]
// if !ok {
// return "", fmt.Errorf("couldn't find resource stackitprivatepreview_postgresflexalpha_user.user")
// }
// instanceId, ok := r.Primary.Attributes["instance_id"]
// if !ok {
// return "", fmt.Errorf("couldn't find attribute instance_id")
// }
// userId, ok := r.Primary.Attributes["user_id"]
// if !ok {
// return "", fmt.Errorf("couldn't find attribute user_id")
// }
//
// return fmt.Sprintf("%s,%s,%s,%s", testutils.ProjectId, testutils.Region, instanceId, userId), nil
// },
// ImportState: true,
// ImportStateVerify: true,
// ImportStateVerifyIgnore: []string{"password", "uri"},
// },
// {
// ResourceName: "stackitprivatepreview_postgresflexalpha_database.database",
// ImportStateIdFunc: func(s *terraform.State) (string, error) {
// r, ok := s.RootModule().Resources["stackitprivatepreview_postgresflexalpha_database.database"]
// if !ok {
// return "", fmt.Errorf("couldn't find resource stackitprivatepreview_postgresflexalpha_database.database")
// }
// instanceId, ok := r.Primary.Attributes["instance_id"]
// if !ok {
// return "", fmt.Errorf("couldn't find attribute instance_id")
// }
// databaseId, ok := r.Primary.Attributes["database_id"]
// if !ok {
// return "", fmt.Errorf("couldn't find attribute database_id")
// }
//
// return fmt.Sprintf(
// "%s,%s,%s,%s",
// testutils.ProjectId,
// testutils.Region,
// instanceId,
// databaseId,
// ), nil
// },
// ImportState: true,
// ImportStateVerify: true,
// },
// // Update
// {
// Config: configResources(instanceResource["backup_schedule_updated"], nil),
// Check: resource.ComposeAggregateTestCheckFunc(
// // Instance data
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "project_id",
// instanceResource["project_id"],
// ),
// resource.TestCheckResourceAttrSet(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "instance_id",
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "name",
// instanceResource["name"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "acl.#",
// "1",
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "acl.0",
// instanceResource["acl"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "backup_schedule",
// instanceResource["backup_schedule_updated"],
// ),
// resource.TestCheckResourceAttrSet(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.id",
// ),
// resource.TestCheckResourceAttrSet(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.description",
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.cpu",
// instanceResource["flavor_cpu"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "flavor.ram",
// instanceResource["flavor_ram"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "replicas",
// instanceResource["replicas"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "storage.class",
// instanceResource["storage_class"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "storage.size",
// instanceResource["storage_size"],
// ),
// resource.TestCheckResourceAttr(
// "stackitprivatepreview_postgresflexalpha_instance.instance",
// "version",
// instanceResource["version"],
// ),
// ),
// },
// // Deletion is done by the framework implicitly
// },
// },
// )
//}
//
//func testAccCheckPostgresFlexDestroy(s *terraform.State) error {
// ctx := context.Background()
// var client *postgresflex.APIClient
// var err error
// if testutils.PostgresFlexCustomEndpoint == "" {
// client, err = postgresflex.NewAPIClient()
// } else {
// client, err = postgresflex.NewAPIClient(
// config.WithEndpoint(testutils.PostgresFlexCustomEndpoint),
// )
// }
// if err != nil {
// return fmt.Errorf("creating client: %w", err)
// }
//
// instancesToDestroy := []string{}
// for _, rs := range s.RootModule().Resources {
// if rs.Type != "stackitprivatepreview_postgresflexalpha_instance" {
// continue
// }
// // instance terraform ID: = "[project_id],[region],[instance_id]"
// instanceId := strings.Split(rs.Primary.ID, core.Separator)[2]
// instancesToDestroy = append(instancesToDestroy, instanceId)
// }
//
// instancesResp, err := client.ListInstancesRequest(ctx, testutils.ProjectId, testutils.Region).Execute()
// if err != nil {
// return fmt.Errorf("getting instancesResp: %w", err)
// }
//
// items := *instancesResp.Instances
// for i := range items {
// if items[i].Id == nil {
// continue
// }
// if utils.Contains(instancesToDestroy, *items[i].Id) {
// // TODO @mhenselin - does force still exist?
// err := client.DeleteInstanceRequestExecute(ctx, testutils.ProjectId, testutils.Region, *items[i].Id)
// if err != nil {
// return fmt.Errorf("deleting instance %s during CheckDestroy: %w", *items[i].Id, err)
// }
// }
// }
// return nil
//}