terraform-provider-stackitp.../stackit/internal/services/postgresflexalpha/postgresflex_acc_test.go
Marcel S. Henselin e01ae1a920
All checks were successful
Publish / Check GoReleaser config (push) Successful in 5s
Publish / Publish provider (push) Successful in 12m24s
fix: fix lintings (#58)
## Description

<!-- **Please link some issue here describing what you are trying to achieve.**

In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->

relates to #1234

## Checklist

- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)

Reviewed-on: #58
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
2026-02-13 14:27:14 +00:00

1001 lines
33 KiB
Go

package postgresflexalpha_test
import (
"context"
_ "embed"
"fmt"
"log"
"os"
"strconv"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/stackitcloud/stackit-sdk-go/core/config"
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
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"
)
const pfx = "stackitprivatepreview_postgresflexalpha"
var testInstances []string
func init() {
sweeperName := fmt.Sprintf("%s_%s", pfx, "sweeper")
resource.AddTestSweepers(sweeperName, &resource.Sweeper{
Name: sweeperName,
F: func(region string) error {
ctx := context.Background()
apiClientConfigOptions := []config.ConfigurationOption{}
apiClient, err := postgresflexalpha2.NewAPIClient(apiClientConfigOptions...)
if err != nil {
log.Fatalln(err)
}
instances, err := apiClient.ListInstancesRequest(ctx, testutils.ProjectId, testutils.Region).
Size(100).
Execute()
if err != nil {
log.Fatalln(err)
}
for _, inst := range instances.GetInstances() {
if strings.HasPrefix(inst.GetName(), "tf-acc-") {
for _, item := range testInstances {
if inst.GetName() == item {
delErr := apiClient.DeleteInstanceRequestExecute(ctx, testutils.ProjectId, testutils.Region, inst.GetId())
if delErr != nil {
// TODO: maybe just warn?
log.Fatalln(delErr)
}
}
}
}
}
return nil
},
})
}
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)
}
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
Users []User
Databases []Database
}
type User struct {
Name string
ProjectId string
Roles []string
}
type Database struct {
Name string
ProjectId string
Owner 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 TestAccInstance(t *testing.T) {
exData := getExample()
updNameData := exData
updNameData.Name = "name-updated"
updSizeData := exData
updSizeData.Size = 25
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
t.Logf(" ... working on instance %s", exData.TfName)
testInstances = append(testInstances, exData.TfName)
},
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
exData,
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "instance", exData.TfName), "name", exData.Name),
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "instance", exData.TfName), "id"),
),
},
// Update name and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
updNameData,
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "instance", exData.TfName), "name", updNameData.Name),
),
},
// Update size and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
updSizeData,
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
testutils.ResStr(pfx, "instance", exData.TfName),
"storage.size",
strconv.Itoa(int(updSizeData.Size)),
),
),
},
//// Import test
//{
// ResourceName: "example_resource.test",
// ImportState: true,
// ImportStateVerify: true,
// },
},
})
}
func TestAccInstanceWithUsers(t *testing.T) {
data := getExample()
userName := "testUser"
data.Users = []User{
{
Name: userName,
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
Roles: []string{"login"},
},
}
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
t.Logf(" ... working on instance %s", data.TfName)
testInstances = append(testInstances, data.TfName)
},
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
data,
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "instance", data.TfName), "name", data.Name),
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "instance", data.TfName), "id"),
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "user", userName), "name", userName),
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "user", userName), "id"),
),
},
},
})
}
func TestAccInstanceWithDatabases(t *testing.T) {
data := getExample()
dbName := "testdb"
userName := "testUser"
data.Users = []User{
{
Name: userName,
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
Roles: []string{"login"},
},
}
data.Databases = []Database{
{
Name: dbName,
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
Owner: userName,
},
}
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
t.Logf(" ... working on instance %s", data.TfName)
testInstances = append(testInstances, data.TfName)
},
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
data,
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "instance", data.TfName), "name", data.Name),
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "instance", data.TfName), "id"),
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "user", userName), "name", userName),
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "user", userName), "id"),
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "database", dbName), "name", dbName),
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "database", dbName), "owner", userName),
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "database", dbName), "id"),
),
},
},
})
}
// 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.ParallelTest(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.ParallelTest(
// 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
//}