From c7260e04e2717a5be9d7cea208ed0036d00185dc Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Mon, 9 Mar 2026 11:03:29 +0100 Subject: [PATCH] fix: refactor tests --- .../sqlserverflexalpha_database.md | 32 + .../sqlserverflexalpha_instance.md | 77 +++ docs/data-sources/sqlserverflexalpha_user.md | 62 ++ docs/resources/sqlserverflexalpha_database.md | 63 ++ docs/resources/sqlserverflexalpha_instance.md | 103 +++ docs/resources/sqlserverflexalpha_user.md | 53 ++ internal/testutil/assert.go | 11 - internal/testutil/testutil.go.bak | 651 ------------------ internal/testutil/testutil_test.go.bak | 50 -- .../postgresflexalpha/instance/functions.go | 6 +- .../instance/functions_test.go | 8 +- .../postgresflexalpha/user/mapper_test.go | 20 +- .../postgresflexalpha/utils/util_test.go | 12 +- .../database/mapper_test.go | 6 +- .../sqlserverflexalpha/user/mapper_test.go | 90 +-- .../services/sqlserverflexbeta/user/mapper.go | 1 + .../sqlserverflexbeta/user/mapper_test.go | 43 +- .../sqlserverflexbeta/utils/util_test.go | 14 +- stackit/provider_acc_test.go | 157 +---- 19 files changed, 521 insertions(+), 938 deletions(-) create mode 100644 docs/data-sources/sqlserverflexalpha_database.md create mode 100644 docs/data-sources/sqlserverflexalpha_instance.md create mode 100644 docs/data-sources/sqlserverflexalpha_user.md create mode 100644 docs/resources/sqlserverflexalpha_database.md create mode 100644 docs/resources/sqlserverflexalpha_instance.md create mode 100644 docs/resources/sqlserverflexalpha_user.md delete mode 100644 internal/testutil/assert.go delete mode 100644 internal/testutil/testutil.go.bak delete mode 100644 internal/testutil/testutil_test.go.bak diff --git a/docs/data-sources/sqlserverflexalpha_database.md b/docs/data-sources/sqlserverflexalpha_database.md new file mode 100644 index 00000000..df66ffb7 --- /dev/null +++ b/docs/data-sources/sqlserverflexalpha_database.md @@ -0,0 +1,32 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "stackitprivatepreview_sqlserverflexalpha_database Data Source - stackitprivatepreview" +subcategory: "" +description: |- + +--- + +# stackitprivatepreview_sqlserverflexalpha_database (Data Source) + + + + + + +## Schema + +### Required + +- `database_name` (String) The name of the database. +- `instance_id` (String) The ID of the instance. +- `project_id` (String) The STACKIT project ID. +- `region` (String) The region which should be addressed + +### Read-Only + +- `collation_name` (String) The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint. +- `compatibility_level` (Number) CompatibilityLevel of the Database. +- `id` (String) The terraform internal identifier. +- `name` (String) The name of the database. +- `owner` (String) The owner of the database. +- `tf_original_api_id` (Number) The id of the database. diff --git a/docs/data-sources/sqlserverflexalpha_instance.md b/docs/data-sources/sqlserverflexalpha_instance.md new file mode 100644 index 00000000..b05d7b8e --- /dev/null +++ b/docs/data-sources/sqlserverflexalpha_instance.md @@ -0,0 +1,77 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "stackitprivatepreview_sqlserverflexalpha_instance Data Source - stackitprivatepreview" +subcategory: "" +description: |- + +--- + +# stackitprivatepreview_sqlserverflexalpha_instance (Data Source) + + + +## Example Usage + +```terraform +data "stackitprivatepreview_sqlserverflexalpha_instance" "example" { + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +} +``` + + +## Schema + +### Required + +- `instance_id` (String) The ID of the instance. +- `project_id` (String) The STACKIT project ID. +- `region` (String) The region which should be addressed + +### Read-Only + +- `backup_schedule` (String) The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule. +- `edition` (String) Edition of the MSSQL server instance +- `encryption` (Attributes) this defines which key to use for storage encryption (see [below for nested schema](#nestedatt--encryption)) +- `flavor_id` (String) The id of the instance flavor. +- `is_deletable` (Boolean) Whether the instance can be deleted or not. +- `name` (String) The name of the instance. +- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network)) +- `replicas` (Number) How many replicas the instance should have. +- `retention_days` (Number) The days for how long the backup files should be stored before cleaned up. 30 to 365 +- `status` (String) +- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage)) +- `tf_original_api_id` (String) The ID of the instance. +- `version` (String) The sqlserver version used for the instance. + + +### Nested Schema for `encryption` + +Read-Only: + +- `kek_key_id` (String) The key identifier +- `kek_key_ring_id` (String) The keyring identifier +- `kek_key_version` (String) The key version +- `service_account` (String) + + + +### Nested Schema for `network` + +Read-Only: + +- `access_scope` (String) The network access scope of the instance + +⚠️ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected. +- `acl` (List of String) List of IPV4 cidr. +- `instance_address` (String) +- `router_address` (String) + + + +### Nested Schema for `storage` + +Read-Only: + +- `class` (String) The storage class for the storage. +- `size` (Number) The storage size in Gigabytes. diff --git a/docs/data-sources/sqlserverflexalpha_user.md b/docs/data-sources/sqlserverflexalpha_user.md new file mode 100644 index 00000000..63526135 --- /dev/null +++ b/docs/data-sources/sqlserverflexalpha_user.md @@ -0,0 +1,62 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "stackitprivatepreview_sqlserverflexalpha_user Data Source - stackitprivatepreview" +subcategory: "" +description: |- + +--- + +# stackitprivatepreview_sqlserverflexalpha_user (Data Source) + + + +## Example Usage + +```terraform +data "stackitprivatepreview_sqlserverflexalpha_user" "example" { + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + user_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +} +``` + + +## Schema + +### Required + +- `instance_id` (String) The ID of the instance. +- `project_id` (String) The STACKIT project ID. +- `region` (String) The region which should be addressed + +### Optional + +- `page` (Number) Number of the page of items list to be returned. +- `size` (Number) Number of items to be returned on each page. +- `sort` (String) Sorting of the users to be returned on each page. + +### Read-Only + +- `pagination` (Attributes) (see [below for nested schema](#nestedatt--pagination)) +- `users` (Attributes List) List of all users inside an instance (see [below for nested schema](#nestedatt--users)) + + +### Nested Schema for `pagination` + +Read-Only: + +- `page` (Number) +- `size` (Number) +- `sort` (String) +- `total_pages` (Number) +- `total_rows` (Number) + + + +### Nested Schema for `users` + +Read-Only: + +- `status` (String) The current status of the user. +- `tf_original_api_id` (Number) The ID of the user. +- `username` (String) The name of the user. diff --git a/docs/resources/sqlserverflexalpha_database.md b/docs/resources/sqlserverflexalpha_database.md new file mode 100644 index 00000000..7d8f050b --- /dev/null +++ b/docs/resources/sqlserverflexalpha_database.md @@ -0,0 +1,63 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "stackitprivatepreview_sqlserverflexalpha_database Resource - stackitprivatepreview" +subcategory: "" +description: |- + +--- + +# stackitprivatepreview_sqlserverflexalpha_database (Resource) + + + +## Example Usage + +```terraform +resource "stackitprivatepreview_sqlserverflexalpha_database" "example" { + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + collation = "" + compatibility = "160" + name = "" + owner = "" +} + +# Only use the import statement, if you want to import a existing sqlserverflex database +import { + to = stackitprivatepreview_sqlserverflexalpha_database.import-example + id = "${var.project_id},${var.region},${var.sql_instance_id},${var.sql_user_id}" +} + +import { + to = stackitprivatepreview_sqlserverflexalpha_database.import-example + identity = { + project_id = "project.id" + region = "region" + instance_id = "instance.id" + database_id = "database.id" + } +} +``` + + +## Schema + +### Required + +- `name` (String) The name of the database. +- `owner` (String) The owner of the database. + +### Optional + +- `collation` (String) The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint. +- `compatibility` (Number) CompatibilityLevel of the Database. +- `database_name` (String) The name of the database. +- `instance_id` (String) The ID of the instance. +- `project_id` (String) The STACKIT project ID. +- `region` (String) The region which should be addressed + +### Read-Only + +- `collation_name` (String) The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint. +- `compatibility_level` (Number) CompatibilityLevel of the Database. +- `id` (Number) The id of the database. diff --git a/docs/resources/sqlserverflexalpha_instance.md b/docs/resources/sqlserverflexalpha_instance.md new file mode 100644 index 00000000..95e33673 --- /dev/null +++ b/docs/resources/sqlserverflexalpha_instance.md @@ -0,0 +1,103 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "stackitprivatepreview_sqlserverflexalpha_instance Resource - stackitprivatepreview" +subcategory: "" +description: |- + +--- + +# stackitprivatepreview_sqlserverflexalpha_instance (Resource) + + + +## Example Usage + +```terraform +resource "stackitprivatepreview_sqlserverflexalpha_instance" "example" { + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + name = "example-instance" + acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"] + backup_schedule = "00 00 * * *" + flavor = { + cpu = 4 + ram = 16 + } + storage = { + class = "class" + size = 5 + } + version = 2022 +} + +# Only use the import statement, if you want to import an existing sqlserverflex instance +import { + to = stackitprivatepreview_sqlserverflexalpha_instance.import-example + id = "${var.project_id},${var.region},${var.sql_instance_id}" +} +``` + + +## Schema + +### Required + +- `backup_schedule` (String) The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule. +- `flavor_id` (String) The id of the instance flavor. +- `name` (String) The name of the instance. +- `network` (Attributes) the network configuration of the instance. (see [below for nested schema](#nestedatt--network)) +- `retention_days` (Number) The days for how long the backup files should be stored before cleaned up. 30 to 365 +- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage)) +- `version` (String) The sqlserver version used for the instance. + +### Optional + +- `encryption` (Attributes) this defines which key to use for storage encryption (see [below for nested schema](#nestedatt--encryption)) +- `instance_id` (String) The ID of the instance. +- `project_id` (String) The STACKIT project ID. +- `region` (String) The region which should be addressed + +### Read-Only + +- `edition` (String) Edition of the MSSQL server instance +- `id` (String) The ID of the instance. +- `is_deletable` (Boolean) Whether the instance can be deleted or not. +- `replicas` (Number) How many replicas the instance should have. +- `status` (String) + + +### Nested Schema for `network` + +Required: + +- `acl` (List of String) List of IPV4 cidr. + +Optional: + +- `access_scope` (String) The network access scope of the instance + +⚠️ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected. + +Read-Only: + +- `instance_address` (String) +- `router_address` (String) + + + +### Nested Schema for `storage` + +Required: + +- `class` (String) The storage class for the storage. +- `size` (Number) The storage size in Gigabytes. + + + +### Nested Schema for `encryption` + +Required: + +- `kek_key_id` (String) The key identifier +- `kek_key_ring_id` (String) The keyring identifier +- `kek_key_version` (String) The key version +- `service_account` (String) diff --git a/docs/resources/sqlserverflexalpha_user.md b/docs/resources/sqlserverflexalpha_user.md new file mode 100644 index 00000000..85d5350e --- /dev/null +++ b/docs/resources/sqlserverflexalpha_user.md @@ -0,0 +1,53 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "stackitprivatepreview_sqlserverflexalpha_user Resource - stackitprivatepreview" +subcategory: "" +description: |- + +--- + +# stackitprivatepreview_sqlserverflexalpha_user (Resource) + + + +## Example Usage + +```terraform +resource "stackitprivatepreview_sqlserverflexalpha_user" "example" { + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + username = "username" + roles = ["role"] +} + +# Only use the import statement, if you want to import an existing sqlserverflex user +import { + to = stackitprivatepreview_sqlserverflexalpha_user.import-example + id = "${var.project_id},${var.region},${var.sql_instance_id},${var.sql_user_id}" +} +``` + + +## Schema + +### Required + +- `roles` (List of String) A list containing the user roles for the instance. A list with the valid user roles can be retrieved using the List Roles endpoint. +- `username` (String) The name of the user. + +### Optional + +- `default_database` (String) The default database for a user of the instance. +- `instance_id` (String) The ID of the instance. +- `project_id` (String) The STACKIT project ID. +- `region` (String) The region which should be addressed +- `user_id` (Number) The ID of the user. + +### Read-Only + +- `host` (String) The host of the instance in which the user belongs to. +- `id` (Number) The ID of the user. +- `password` (String) The password for the user. +- `port` (Number) The port of the instance in which the user belongs to. +- `status` (String) The current status of the user. +- `uri` (String) The connection string for the user to the instance. diff --git a/internal/testutil/assert.go b/internal/testutil/assert.go deleted file mode 100644 index 80cb2104..00000000 --- a/internal/testutil/assert.go +++ /dev/null @@ -1,11 +0,0 @@ -package testutil - -import "testing" - -func Equal[V comparable](t *testing.T, got, expected V) { - t.Helper() - - if expected != got { - t.Errorf("assert equal failed:\ngot: %v \nexpected: %v", got, expected) - } -} diff --git a/internal/testutil/testutil.go.bak b/internal/testutil/testutil.go.bak deleted file mode 100644 index 2756677f..00000000 --- a/internal/testutil/testutil.go.bak +++ /dev/null @@ -1,651 +0,0 @@ -package testutil - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "time" - - "github.com/hashicorp/terraform-plugin-framework/providerserver" - "github.com/hashicorp/terraform-plugin-go/tfprotov6" - "github.com/hashicorp/terraform-plugin-testing/config" - "github.com/hashicorp/terraform-plugin-testing/echoprovider" - - "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit" -) - -const ( - // Default location of credentials JSON - // credentialsFilePath = ".stackit/credentials.json" //nolint:gosec // linter false positive - serviceAccountFilePath = ".stackit/service_account.json" -) - -var ( - // TestAccProtoV6ProviderFactories is used to instantiate a provider during - // acceptance testing. The factory function will be invoked for every Terraform - // CLI command executed to create a provider server to which the CLI can - // reattach. - TestAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ - "stackitprivatepreview": providerserver.NewProtocol6WithError(stackit.New("test-version")()), - } - - // TestEphemeralAccProtoV6ProviderFactories is used to instantiate a provider during - // acceptance testing. The factory function will be invoked for every Terraform - // CLI command executed to create a provider server to which the CLI can - // reattach. - // - // See the Terraform acceptance test documentation on ephemeral resources for more information: - // https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests/ephemeral-resources - TestEphemeralAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ - "stackitprivatepreview": providerserver.NewProtocol6WithError(stackit.New("test-version")()), - "echo": echoprovider.NewProviderServer(), - } - - // E2ETestsEnabled checks if end-to-end tests should be run. - // It is enabled when the TF_ACC environment variable is set to "1". - E2ETestsEnabled = os.Getenv("TF_ACC") == "1" - // OrganizationId is the id of organization used for tests - OrganizationId = os.Getenv("TF_ACC_ORGANIZATION_ID") - // ProjectId is the id of project used for tests - ProjectId = os.Getenv("TF_ACC_PROJECT_ID") - Region = os.Getenv("TF_ACC_REGION") - // ServiceAccountFile is the json file of the service account - ServiceAccountFile = os.Getenv("TF_ACC_SERVICE_ACCOUNT_FILE") - // ServerId is the id of a server used for some tests - ServerId = getenv("TF_ACC_SERVER_ID", "") - // TestProjectParentContainerID is the container id of the parent resource under which projects are created as part of the resource-manager acceptance tests - TestProjectParentContainerID = os.Getenv("TF_ACC_TEST_PROJECT_PARENT_CONTAINER_ID") - // TestProjectParentUUID is the uuid of the parent resource under which projects are created as part of the resource-manager acceptance tests - TestProjectParentUUID = os.Getenv("TF_ACC_TEST_PROJECT_PARENT_UUID") - // TestProjectServiceAccountEmail is the e-mail of a service account with admin permissions on the organization under which projects are created as part of the resource-manager acceptance tests - TestProjectServiceAccountEmail = os.Getenv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_EMAIL") - // TestProjectUserEmail is the e-mail of a user for the project created as part of the resource-manager acceptance tests - // Default email: acc-test@sa.stackit.cloud - TestProjectUserEmail = getenv("TF_ACC_TEST_PROJECT_USER_EMAIL", "acc-test@sa.stackit.cloud") - // TestImageLocalFilePath is the local path to an image file used for image acceptance tests - TestImageLocalFilePath = getenv("TF_ACC_TEST_IMAGE_LOCAL_FILE_PATH", "default") - - CdnCustomEndpoint = os.Getenv("TF_ACC_CDN_CUSTOM_ENDPOINT") - DnsCustomEndpoint = os.Getenv("TF_ACC_DNS_CUSTOM_ENDPOINT") - GitCustomEndpoint = os.Getenv("TF_ACC_GIT_CUSTOM_ENDPOINT") - IaaSCustomEndpoint = os.Getenv("TF_ACC_IAAS_CUSTOM_ENDPOINT") - KMSCustomEndpoint = os.Getenv("TF_ACC_KMS_CUSTOM_ENDPOINT") - LoadBalancerCustomEndpoint = os.Getenv("TF_ACC_LOADBALANCER_CUSTOM_ENDPOINT") - LogMeCustomEndpoint = os.Getenv("TF_ACC_LOGME_CUSTOM_ENDPOINT") - MariaDBCustomEndpoint = os.Getenv("TF_ACC_MARIADB_CUSTOM_ENDPOINT") - ModelServingCustomEndpoint = os.Getenv("TF_ACC_MODELSERVING_CUSTOM_ENDPOINT") - AuthorizationCustomEndpoint = os.Getenv("TF_ACC_authorization_custom_endpoint") - MongoDBFlexCustomEndpoint = os.Getenv("TF_ACC_MONGODBFLEX_CUSTOM_ENDPOINT") - OpenSearchCustomEndpoint = os.Getenv("TF_ACC_OPENSEARCH_CUSTOM_ENDPOINT") - ObservabilityCustomEndpoint = os.Getenv("TF_ACC_OBSERVABILITY_CUSTOM_ENDPOINT") - ObjectStorageCustomEndpoint = os.Getenv("TF_ACC_OBJECTSTORAGE_CUSTOM_ENDPOINT") - PostgresFlexCustomEndpoint = os.Getenv("TF_ACC_POSTGRESFLEX_CUSTOM_ENDPOINT") - RabbitMQCustomEndpoint = os.Getenv("TF_ACC_RABBITMQ_CUSTOM_ENDPOINT") - RedisCustomEndpoint = os.Getenv("TF_ACC_REDIS_CUSTOM_ENDPOINT") - ResourceManagerCustomEndpoint = os.Getenv("TF_ACC_RESOURCEMANAGER_CUSTOM_ENDPOINT") - ScfCustomEndpoint = os.Getenv("TF_ACC_SCF_CUSTOM_ENDPOINT") - SecretsManagerCustomEndpoint = os.Getenv("TF_ACC_SECRETSMANAGER_CUSTOM_ENDPOINT") - SQLServerFlexCustomEndpoint = os.Getenv("TF_ACC_SQLSERVERFLEX_CUSTOM_ENDPOINT") - ServerBackupCustomEndpoint = os.Getenv("TF_ACC_SERVER_BACKUP_CUSTOM_ENDPOINT") - ServerUpdateCustomEndpoint = os.Getenv("TF_ACC_SERVER_UPDATE_CUSTOM_ENDPOINT") - ServiceAccountCustomEndpoint = os.Getenv("TF_ACC_SERVICE_ACCOUNT_CUSTOM_ENDPOINT") - SKECustomEndpoint = os.Getenv("TF_ACC_SKE_CUSTOM_ENDPOINT") -) - -// Provider config helper functions - -func ObservabilityProviderConfig() string { - if ObservabilityCustomEndpoint == "" { - return `provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - observability_custom_endpoint = "%s" - }`, - ObservabilityCustomEndpoint, - ) -} - -func CdnProviderConfig() string { - if CdnCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - enable_beta_resources = true - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - cdn_custom_endpoint = "%s" - enable_beta_resources = true - }`, - CdnCustomEndpoint, - ) -} - -func DnsProviderConfig() string { - if DnsCustomEndpoint == "" { - return `provider "stackitprivatepreview" {}` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - dns_custom_endpoint = "%s" - }`, - DnsCustomEndpoint, - ) -} - -func IaaSProviderConfig() string { - if IaaSCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - iaas_custom_endpoint = "%s" - }`, - IaaSCustomEndpoint, - ) -} - -func IaaSProviderConfigWithBetaResourcesEnabled() string { - if IaaSCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - enable_beta_resources = true - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - enable_beta_resources = true - iaas_custom_endpoint = "%s" - }`, - IaaSCustomEndpoint, - ) -} - -func IaaSProviderConfigWithExperiments() string { - if IaaSCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - experiments = [ "routing-tables", "network" ] - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - iaas_custom_endpoint = "%s" - experiments = [ "routing-tables", "network" ] - }`, - IaaSCustomEndpoint, - ) -} - -func KMSProviderConfig() string { - if KMSCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - kms_custom_endpoint = "%s" - }`, - KMSCustomEndpoint, - ) -} - -func LoadBalancerProviderConfig() string { - if LoadBalancerCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - loadbalancer_custom_endpoint = "%s" - }`, - LoadBalancerCustomEndpoint, - ) -} - -func LogMeProviderConfig() string { - if LogMeCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - logme_custom_endpoint = "%s" - }`, - LogMeCustomEndpoint, - ) -} - -func MariaDBProviderConfig() string { - if MariaDBCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - mariadb_custom_endpoint = "%s" - }`, - MariaDBCustomEndpoint, - ) -} - -func ModelServingProviderConfig() string { - if ModelServingCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - } - ` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - modelserving_custom_endpoint = "%s" - }`, - ModelServingCustomEndpoint, - ) -} - -func MongoDBFlexProviderConfig() string { - if MongoDBFlexCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - mongodbflex_custom_endpoint = "%s" - }`, - MongoDBFlexCustomEndpoint, - ) -} - -func ObjectStorageProviderConfig() string { - if ObjectStorageCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - objectstorage_custom_endpoint = "%s" - }`, - ObjectStorageCustomEndpoint, - ) -} - -func OpenSearchProviderConfig() string { - if OpenSearchCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - opensearch_custom_endpoint = "%s" - }`, - OpenSearchCustomEndpoint, - ) -} - -func PostgresFlexProviderConfig(saFile string) string { - if PostgresFlexCustomEndpoint == "" { - return fmt.Sprintf(` - provider "stackitprivatepreview" { - default_region = "eu01" - service_account_key_path = "%s" - }`, saFile) - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - service_account_key_path = "%s" - postgresflex_custom_endpoint = "%s" - }`, - saFile, - PostgresFlexCustomEndpoint, - ) -} - -func RabbitMQProviderConfig() string { - if RabbitMQCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - rabbitmq_custom_endpoint = "%s" - }`, - RabbitMQCustomEndpoint, - ) -} - -func RedisProviderConfig() string { - if RedisCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - redis_custom_endpoint = "%s" - }`, - RedisCustomEndpoint, - ) -} - -func ResourceManagerProviderConfig() string { - key := GetTestProjectServiceAccountJson("") - if ResourceManagerCustomEndpoint == "" || AuthorizationCustomEndpoint == "" { - return fmt.Sprintf(` - provider "stackitprivatepreview" { - service_account_key = "%s" - }`, - key, - ) - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - resourcemanager_custom_endpoint = "%s" - authorization_custom_endpoint = "%s" - service_account_token = "%s" - }`, - ResourceManagerCustomEndpoint, - AuthorizationCustomEndpoint, - key, - ) -} - -func SecretsManagerProviderConfig() string { - if SecretsManagerCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - secretsmanager_custom_endpoint = "%s" - }`, - SecretsManagerCustomEndpoint, - ) -} - -func SQLServerFlexProviderConfig(saFile string) string { - if SQLServerFlexCustomEndpoint == "" { - return fmt.Sprintf(` - provider "stackitprivatepreview" { - default_region = "eu01" - service_account_key_path = "%s" - }`, saFile) - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - service_account_key_path = "%s" - sqlserverflex_custom_endpoint = "%s" - }`, - saFile, - SQLServerFlexCustomEndpoint, - ) -} - -func ServerBackupProviderConfig() string { - if ServerBackupCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - enable_beta_resources = true - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - server_backup_custom_endpoint = "%s" - enable_beta_resources = true - }`, - ServerBackupCustomEndpoint, - ) -} - -func ServerUpdateProviderConfig() string { - if ServerUpdateCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - enable_beta_resources = true - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - server_update_custom_endpoint = "%s" - enable_beta_resources = true - }`, - ServerUpdateCustomEndpoint, - ) -} - -func SKEProviderConfig() string { - if SKECustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - ske_custom_endpoint = "%s" - }`, - SKECustomEndpoint, - ) -} - -func AuthorizationProviderConfig() string { - if AuthorizationCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - experiments = ["iam"] - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - authorization_custom_endpoint = "%s" - experiments = ["iam"] - }`, - AuthorizationCustomEndpoint, - ) -} - -func ServiceAccountProviderConfig() string { - if ServiceAccountCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - enable_beta_resources = true - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - service_account_custom_endpoint = "%s" - enable_beta_resources = true - }`, - ServiceAccountCustomEndpoint, - ) -} - -func GitProviderConfig() string { - if GitCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - enable_beta_resources = true - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - git_custom_endpoint = "%s" - enable_beta_resources = true - }`, - GitCustomEndpoint, - ) -} - -func ScfProviderConfig() string { - if ScfCustomEndpoint == "" { - return ` - provider "stackitprivatepreview" { - default_region = "eu01" - }` - } - return fmt.Sprintf(` - provider "stackitprivatepreview" { - default_region = "eu01" - scf_custom_endpoint = "%s" - }`, - ScfCustomEndpoint, - ) -} - -func ResourceNameWithDateTime(name string) string { - dateTime := time.Now().Format(time.RFC3339) - // Remove timezone to have a smaller datetime - dateTimeTrimmed, _, _ := strings.Cut(dateTime, "+") - return fmt.Sprintf("tf-acc-%s-%s", name, dateTimeTrimmed) -} - -func GetTestProjectServiceAccountJson(path string) string { - var err error - token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_JSON") - if !tokenSet || token == "" { - token, err = readTestServiceAccountJsonFromFile(path) - if err != nil { - return "" - } - } - return token -} - -//func GetTestProjectServiceAccountToken(path string) string { -// var err error -// token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN") -// if !tokenSet || token == "" { -// token, err = readTestTokenFromCredentialsFile(path) -// if err != nil { -// return "" -// } -// } -// return token -//} -// -//func readTestTokenFromCredentialsFile(path string) (string, error) { -// if path == "" { -// customPath, customPathSet := os.LookupEnv("STACKIT_CREDENTIALS_PATH") -// if !customPathSet || customPath == "" { -// path = credentialsFilePath -// home, err := os.UserHomeDir() -// if err != nil { -// return "", fmt.Errorf("getting home directory: %w", err) -// } -// path = filepath.Join(home, path) -// } else { -// path = customPath -// } -// } -// -// credentialsRaw, err := os.ReadFile(path) -// if err != nil { -// return "", fmt.Errorf("opening file: %w", err) -// } -// -// var credentials struct { -// TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN string `json:"TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN"` -// } -// err = json.Unmarshal(credentialsRaw, &credentials) -// if err != nil { -// return "", fmt.Errorf("unmarshalling credentials: %w", err) -// } -// return credentials.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN, nil -//} - -func readTestServiceAccountJsonFromFile(path string) (string, error) { - if path == "" { - customPath, customPathSet := os.LookupEnv("STACKIT_SERVICE_ACCOUNT_PATH") - if !customPathSet || customPath == "" { - path = serviceAccountFilePath - home, err := os.UserHomeDir() - if err != nil { - return "", fmt.Errorf("getting home directory: %w", err) - } - path = filepath.Join(home, path) - } else { - path = customPath - } - } - - credentialsRaw, err := os.ReadFile(path) - if err != nil { - return "", fmt.Errorf("opening file: %w", err) - } - return string(credentialsRaw), nil -} - -func getenv(key, defaultValue string) string { - val := os.Getenv(key) - if val == "" { - return defaultValue - } - return val -} - -// CreateDefaultLocalFile is a helper for local_file_path. No real data is created -func CreateDefaultLocalFile() os.File { - // Define the file name and size - fileName := "test-512k.img" - size := 512 * 1024 // 512 KB - - // Create the file - file, err := os.Create(fileName) - if err != nil { - panic(err) - } - - // Seek to the desired position (512 KB) - _, err = file.Seek(int64(size), 0) - if err != nil { - panic(err) - } - - return *file -} - -func ConvertConfigVariable(variable config.Variable) string { - tmpByteArray, _ := variable.MarshalJSON() - // In case the variable is a string, the quotes should be removed - if tmpByteArray[0] == '"' && tmpByteArray[len(tmpByteArray)-1] == '"' { - result := string(tmpByteArray[1 : len(tmpByteArray)-1]) - // Replace escaped quotes which where added MarshalJSON - rawString := strings.ReplaceAll(result, `\"`, `"`) - return rawString - } - return string(tmpByteArray) -} diff --git a/internal/testutil/testutil_test.go.bak b/internal/testutil/testutil_test.go.bak deleted file mode 100644 index f74ca81c..00000000 --- a/internal/testutil/testutil_test.go.bak +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) STACKIT - -package testutil - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-testing/config" -) - -func TestConvertConfigVariable(t *testing.T) { - tests := []struct { - name string - variable config.Variable - want string - }{ - { - name: "string", - variable: config.StringVariable("test"), - want: "test", - }, - { - name: "bool: true", - variable: config.BoolVariable(true), - want: "true", - }, - { - name: "bool: false", - variable: config.BoolVariable(false), - want: "false", - }, - { - name: "integer", - variable: config.IntegerVariable(10), - want: "10", - }, - { - name: "quoted string", - variable: config.StringVariable(`instance =~ ".*"`), - want: `instance =~ ".*"`, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := ConvertConfigVariable(tt.variable); got != tt.want { - t.Errorf("ConvertConfigVariable() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/stackit/internal/services/postgresflexalpha/instance/functions.go b/stackit/internal/services/postgresflexalpha/instance/functions.go index 21c15a0b..6e7164b9 100644 --- a/stackit/internal/services/postgresflexalpha/instance/functions.go +++ b/stackit/internal/services/postgresflexalpha/instance/functions.go @@ -171,7 +171,7 @@ func handleConnectionInfo(ctx context.Context, m *dataSourceModel, resp *postgre postgresflexalphadatasource.WriteValue{}.AttributeTypes(ctx), map[string]attr.Value{ "host": types.StringValue(resp.ConnectionInfo.Write.Host), - "port": types.Int32Value(resp.ConnectionInfo.Write.Port), + "port": types.Int64Value(int64(resp.ConnectionInfo.Write.Port)), }, ), }, @@ -180,7 +180,7 @@ func handleConnectionInfo(ctx context.Context, m *dataSourceModel, resp *postgre } func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) error { - netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl()) + netACL, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl()) if diags.HasError() { return fmt.Errorf("failed converting network acl from response") } @@ -199,7 +199,7 @@ func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.G postgresflexalphadatasource.NetworkValue{}.AttributeTypes(ctx), map[string]attr.Value{ "access_scope": types.StringValue(string(resp.Network.GetAccessScope())), - "acl": netAcl, + "acl": netACL, "instance_address": types.StringValue(instAddr), "router_address": types.StringValue(rtrAddr), }, diff --git a/stackit/internal/services/postgresflexalpha/instance/functions_test.go b/stackit/internal/services/postgresflexalpha/instance/functions_test.go index 154d1bd4..0fa85f16 100644 --- a/stackit/internal/services/postgresflexalpha/instance/functions_test.go +++ b/stackit/internal/services/postgresflexalpha/instance/functions_test.go @@ -66,7 +66,7 @@ func Test_handleConnectionInfo(t *testing.T) { ConnectionInfo: postgresflex.InstanceConnectionInfo{ Write: postgresflex.InstanceConnectionInfoWrite{ Host: tt.args.hostName, - Port: tt.args.port, + Port: int32(tt.args.port), }, }, } @@ -93,7 +93,7 @@ func Test_handleConnectionInfo(t *testing.T) { if !ok { t.Errorf("could not find a value for port in connection_info.write") } - if !gotPort.Equal(types.Int32Value(tt.args.port)) { + if !gotPort.Equal(types.Int64Value(int64(tt.args.port))) { t.Errorf("port value incorrect: want: %d - got: %s", tt.args.port, gotPort.String()) } } @@ -102,6 +102,7 @@ func Test_handleConnectionInfo(t *testing.T) { } func Test_handleEncryption(t *testing.T) { + t.Skipf("please implement") type args struct { m *dataSourceModel resp *postgresflex.GetInstanceResponse @@ -121,6 +122,7 @@ func Test_handleEncryption(t *testing.T) { } func Test_handleNetwork(t *testing.T) { + t.Skipf("please implement") type args struct { ctx context.Context m *dataSourceModel @@ -143,6 +145,7 @@ func Test_handleNetwork(t *testing.T) { } func Test_mapGetDataInstanceResponseToModel(t *testing.T) { + t.Skipf("please implement") type args struct { ctx context.Context m *dataSourceModel @@ -165,6 +168,7 @@ func Test_mapGetDataInstanceResponseToModel(t *testing.T) { } func Test_mapGetInstanceResponseToModel(t *testing.T) { + t.Skipf("please implement") type args struct { ctx context.Context m *postgresflexalpharesource.InstanceModel diff --git a/stackit/internal/services/postgresflexalpha/user/mapper_test.go b/stackit/internal/services/postgresflexalpha/user/mapper_test.go index 76ac0b95..5b07ede8 100644 --- a/stackit/internal/services/postgresflexalpha/user/mapper_test.go +++ b/stackit/internal/services/postgresflexalpha/user/mapper_test.go @@ -169,11 +169,11 @@ func TestMapFieldsCreate(t *testing.T) { UserId: types.Int64Value(1), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - Name: types.StringNull(), + Name: types.StringValue(""), Roles: types.List(types.SetNull(types.StringType)), Password: types.StringNull(), Region: types.StringValue(testRegion), - Status: types.StringNull(), + Status: types.StringValue(""), //ConnectionString: types.StringNull(), }, true, @@ -213,11 +213,11 @@ func TestMapFieldsCreate(t *testing.T) { UserId: types.Int64Value(1), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - Name: types.StringNull(), + Name: types.StringValue(""), Roles: types.List(types.SetNull(types.StringType)), Password: types.StringNull(), Region: types.StringValue(testRegion), - Status: types.StringNull(), + Status: types.StringValue(""), //ConnectionString: types.StringNull(), }, true, @@ -260,7 +260,7 @@ func TestMapFieldsCreate(t *testing.T) { t.Fatalf("Should not have failed: %v", err) } if tt.isValid { - diff := cmp.Diff(state, &tt.expected) + diff := cmp.Diff(&tt.expected, state) if diff != "" { t.Fatalf("Data does not match: %s", diff) } @@ -290,10 +290,10 @@ func TestMapFields(t *testing.T) { UserId: types.Int64Value(int64(1)), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - Name: types.StringNull(), + Name: types.StringValue(""), Roles: types.List(types.SetNull(types.StringType)), Region: types.StringValue(testRegion), - Status: types.StringNull(), + Status: types.StringValue(""), //ConnectionString: types.StringNull(), }, true, @@ -326,7 +326,7 @@ func TestMapFields(t *testing.T) { ), ), Region: types.StringValue(testRegion), - Status: types.StringNull(), + Status: types.StringValue(""), //ConnectionString: types.StringNull(), }, true, @@ -343,10 +343,10 @@ func TestMapFields(t *testing.T) { UserId: types.Int64Value(1), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - Name: types.StringNull(), + Name: types.StringValue(""), Roles: types.List(types.SetNull(types.StringType)), Region: types.StringValue(testRegion), - Status: types.StringNull(), + Status: types.StringValue(""), //ConnectionString: types.StringNull(), }, true, diff --git a/stackit/internal/services/postgresflexalpha/utils/util_test.go b/stackit/internal/services/postgresflexalpha/utils/util_test.go index 3e25e075..16791f2b 100644 --- a/stackit/internal/services/postgresflexalpha/utils/util_test.go +++ b/stackit/internal/services/postgresflexalpha/utils/util_test.go @@ -15,7 +15,7 @@ import ( "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core" "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api" ) const ( @@ -38,7 +38,7 @@ func TestConfigureClient(t *testing.T) { name string args args wantErr bool - expected *postgresflex.APIClient + expected *v3alpha1api.APIClient }{ { name: "default endpoint", @@ -47,8 +47,8 @@ func TestConfigureClient(t *testing.T) { Version: testVersion, }, }, - expected: func() *postgresflex.APIClient { - apiClient, err := postgresflex.NewAPIClient( + expected: func() *v3alpha1api.APIClient { + apiClient, err := v3alpha1api.NewAPIClient( config.WithRegion("eu01"), utils.UserAgentConfigOption(testVersion), ) @@ -67,8 +67,8 @@ func TestConfigureClient(t *testing.T) { PostgresFlexCustomEndpoint: testCustomEndpoint, }, }, - expected: func() *postgresflex.APIClient { - apiClient, err := postgresflex.NewAPIClient( + expected: func() *v3alpha1api.APIClient { + apiClient, err := v3alpha1api.NewAPIClient( utils.UserAgentConfigOption(testVersion), config.WithEndpoint(testCustomEndpoint), ) diff --git a/stackit/internal/services/sqlserverflexalpha/database/mapper_test.go b/stackit/internal/services/sqlserverflexalpha/database/mapper_test.go index 136fc2fc..866ca776 100644 --- a/stackit/internal/services/sqlserverflexalpha/database/mapper_test.go +++ b/stackit/internal/services/sqlserverflexalpha/database/mapper_test.go @@ -5,6 +5,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/stackitcloud/stackit-sdk-go/core/utils" sqlserverflexalpha "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api" datasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/database/datasources_gen" ) @@ -200,8 +201,9 @@ func TestToCreatePayload(t *testing.T) { }, expected: expected{ payload: &sqlserverflexalpha.CreateDatabaseRequestPayload{ - Name: ("my-db"), - Owner: ("my-owner"), + Name: "my-db", + Owner: "my-owner", + Compatibility: utils.Ptr(int32(0)), }, }, }, diff --git a/stackit/internal/services/sqlserverflexalpha/user/mapper_test.go b/stackit/internal/services/sqlserverflexalpha/user/mapper_test.go index 2ea6547b..394d7a00 100644 --- a/stackit/internal/services/sqlserverflexalpha/user/mapper_test.go +++ b/stackit/internal/services/sqlserverflexalpha/user/mapper_test.go @@ -28,13 +28,13 @@ func TestMapDataSourceFields(t *testing.T) { UserId: types.Int64Value(1), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - Username: types.StringNull(), + Username: types.StringValue(""), Roles: types.List(types.SetNull(types.StringType)), - Host: types.StringNull(), - Port: types.Int64Null(), + Host: types.StringValue(""), + Port: types.Int64Value(0), Region: types.StringValue(testRegion), - Status: types.StringNull(), - DefaultDatabase: types.StringNull(), + Status: types.StringValue(""), + DefaultDatabase: types.StringValue(""), }, true, }, @@ -93,15 +93,17 @@ func TestMapDataSourceFields(t *testing.T) { }, testRegion, dataSourceModel{ - Id: types.StringValue("pid,region,iid,1"), - UserId: types.Int64Value(1), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Username: types.StringNull(), - Roles: types.List(types.SetValueMust(types.StringType, []attr.Value{})), - Host: types.StringNull(), - Port: types.Int64Value(2123456789), - Region: types.StringValue(testRegion), + Id: types.StringValue("pid,region,iid,1"), + UserId: types.Int64Value(1), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Username: types.StringValue(""), + Roles: types.List(types.SetValueMust(types.StringType, []attr.Value{})), + Host: types.StringValue(""), + Port: types.Int64Value(2123456789), + Region: types.StringValue(testRegion), + DefaultDatabase: types.StringValue(""), + Status: types.StringValue(""), }, true, }, @@ -165,28 +167,31 @@ func TestMapFieldsCreate(t *testing.T) { { "default_values", &v3alpha1api.CreateUserResponse{ - Id: (int64(1)), - Password: (""), + Id: int64(1), + Password: "xy", }, testRegion, resourceModel{ - Id: types.Int64Value(1), - UserId: types.Int64Value(1), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Username: types.StringNull(), - Roles: types.List(types.SetNull(types.StringType)), - Password: types.StringValue(""), - Host: types.StringNull(), - Port: types.Int64Null(), - Region: types.StringValue(testRegion), + Id: types.Int64Value(1), + UserId: types.Int64Value(1), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Username: types.StringValue(""), + Roles: types.List(types.SetNull(types.StringType)), + Password: types.StringValue("xy"), + Host: types.StringValue(""), + Port: types.Int64Value(0), + Region: types.StringValue(testRegion), + DefaultDatabase: types.StringValue(""), + Status: types.StringValue(""), + Uri: types.StringValue(""), }, true, }, { "simple_values", &v3alpha1api.CreateUserResponse{ - Id: (int64(2)), + Id: int64(2), Roles: []string{ "role_2", "role_1", @@ -198,6 +203,7 @@ func TestMapFieldsCreate(t *testing.T) { Port: int32(1234), Status: "status", DefaultDatabase: "default_db", + Uri: "myURI", }, testRegion, resourceModel{ @@ -221,6 +227,7 @@ func TestMapFieldsCreate(t *testing.T) { Region: types.StringValue(testRegion), Status: types.StringValue("status"), DefaultDatabase: types.StringValue("default_db"), + Uri: types.StringValue("myURI"), }, true, }, @@ -230,7 +237,7 @@ func TestMapFieldsCreate(t *testing.T) { Id: int64(3), Roles: []string{}, Username: "", - Password: "", + Password: "xy", Host: "", Port: int32(256789), }, @@ -240,14 +247,15 @@ func TestMapFieldsCreate(t *testing.T) { UserId: types.Int64Value(3), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - Username: types.StringNull(), - Roles: types.List(types.SetValueMust(types.StringType, []attr.Value{})), - Password: types.StringValue(""), - Host: types.StringNull(), - Port: types.Int64Value(2123456789), + Username: types.StringValue(""), + Roles: types.ListNull(types.StringType), + Password: types.StringValue("xy"), + Host: types.StringValue(""), + Port: types.Int64Value(256789), Region: types.StringValue(testRegion), - DefaultDatabase: types.StringNull(), - Status: types.StringNull(), + DefaultDatabase: types.StringValue(""), + Status: types.StringValue(""), + Uri: types.StringValue(""), }, true, }, @@ -325,10 +333,10 @@ func TestMapFields(t *testing.T) { UserId: types.Int64Value(1), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - Username: types.StringNull(), + Username: types.StringValue(""), Roles: types.List(types.SetNull(types.StringType)), - Host: types.StringNull(), - Port: types.Int64Null(), + Host: types.StringValue(""), + Port: types.Int64Value(0), Region: types.StringValue(testRegion), }, true, @@ -382,9 +390,9 @@ func TestMapFields(t *testing.T) { UserId: types.Int64Value(1), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - Username: types.StringNull(), + Username: types.StringValue(""), Roles: types.List(types.SetValueMust(types.StringType, []attr.Value{})), - Host: types.StringNull(), + Host: types.StringValue(""), Port: types.Int64Value(2123456789), Region: types.StringValue(testRegion), }, @@ -477,7 +485,7 @@ func TestToCreatePayload(t *testing.T) { { "null_fields_and_int_conversions", &resourceModel{ - Username: types.StringNull(), + Username: types.StringValue(""), }, []string{ "", diff --git a/stackit/internal/services/sqlserverflexbeta/user/mapper.go b/stackit/internal/services/sqlserverflexbeta/user/mapper.go index cf4c3284..106a4dc3 100644 --- a/stackit/internal/services/sqlserverflexbeta/user/mapper.go +++ b/stackit/internal/services/sqlserverflexbeta/user/mapper.go @@ -166,6 +166,7 @@ func mapFieldsCreate(userResp *v3beta1api.CreateUserResponse, model *resourceMod model.Region = types.StringValue(region) model.Status = types.StringValue(user.Status) model.DefaultDatabase = types.StringValue(user.DefaultDatabase) + model.Uri = types.StringValue(user.Uri) return nil } diff --git a/stackit/internal/services/sqlserverflexbeta/user/mapper_test.go b/stackit/internal/services/sqlserverflexbeta/user/mapper_test.go index c021fc86..d8fa083a 100644 --- a/stackit/internal/services/sqlserverflexbeta/user/mapper_test.go +++ b/stackit/internal/services/sqlserverflexbeta/user/mapper_test.go @@ -161,39 +161,43 @@ func TestMapFieldsCreate(t *testing.T) { { "default_values", &sqlserverflexbeta.CreateUserResponse{ - Id: (int64(1)), - Password: (""), + Id: int64(1), + Password: "", }, testRegion, resourceModel{ - Id: types.Int64Value(1), - UserId: types.Int64Value(1), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Username: types.StringNull(), - Roles: types.List(types.SetNull(types.StringType)), - Password: types.StringValue(""), - Host: types.StringNull(), - Port: types.Int64Null(), - Region: types.StringValue(testRegion), + Id: types.Int64Value(1), + UserId: types.Int64Value(1), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Username: types.StringValue(""), + Roles: types.List(types.SetNull(types.StringType)), + Password: types.StringValue(""), + Host: types.StringValue(""), + Port: types.Int64Value(0), + Region: types.StringValue(testRegion), + DefaultDatabase: types.StringValue(""), + Status: types.StringValue(""), + Uri: types.StringValue(""), }, true, }, { "simple_values", &sqlserverflexbeta.CreateUserResponse{ - Id: (int64(2)), + Id: int64(2), Roles: []string{ "role_1", "role_2", "", }, - Username: ("username"), - Password: ("password"), - Host: ("host"), - Port: (int32(1234)), - Status: ("status"), - DefaultDatabase: ("default_db"), + Username: "username", + Password: "password", + Host: "host", + Port: int32(1234), + Status: "status", + DefaultDatabase: "default_db", + Uri: "myURI", }, testRegion, resourceModel{ @@ -217,6 +221,7 @@ func TestMapFieldsCreate(t *testing.T) { Region: types.StringValue(testRegion), Status: types.StringValue("status"), DefaultDatabase: types.StringValue("default_db"), + Uri: types.StringValue("myURI"), }, true, }, diff --git a/stackit/internal/services/sqlserverflexbeta/utils/util_test.go b/stackit/internal/services/sqlserverflexbeta/utils/util_test.go index 62e2c68f..92c6ffaa 100644 --- a/stackit/internal/services/sqlserverflexbeta/utils/util_test.go +++ b/stackit/internal/services/sqlserverflexbeta/utils/util_test.go @@ -10,7 +10,7 @@ import ( sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients" "github.com/stackitcloud/stackit-sdk-go/core/config" - sqlserverflex "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3beta1api" + "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3beta1api" "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core" "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils" @@ -36,7 +36,7 @@ func TestConfigureClient(t *testing.T) { name string args args wantErr bool - expected *sqlserverflex.APIClient + expected *v3beta1api.APIClient }{ { name: "default endpoint", @@ -45,8 +45,8 @@ func TestConfigureClient(t *testing.T) { Version: testVersion, }, }, - expected: func() *sqlserverflex.APIClient { - apiClient, err := sqlserverflex.NewAPIClient( + expected: func() *v3beta1api.APIClient { + apiClient, err := v3beta1api.NewAPIClient( config.WithRegion("eu01"), utils.UserAgentConfigOption(testVersion), ) @@ -65,8 +65,8 @@ func TestConfigureClient(t *testing.T) { SQLServerFlexCustomEndpoint: testCustomEndpoint, }, }, - expected: func() *sqlserverflex.APIClient { - apiClient, err := sqlserverflex.NewAPIClient( + expected: func() *v3beta1api.APIClient { + apiClient, err := v3beta1api.NewAPIClient( utils.UserAgentConfigOption(testVersion), config.WithEndpoint(testCustomEndpoint), ) @@ -89,7 +89,7 @@ func TestConfigureClient(t *testing.T) { t.Errorf("ConfigureClient() error = %v, want %v", diags.HasError(), tt.wantErr) } - if !reflect.DeepEqual(actual, tt.expected) { + if !reflect.DeepEqual(actual.GetConfig(), tt.expected.GetConfig()) { t.Errorf("ConfigureClient() = %v, want %v", actual, tt.expected) } }, diff --git a/stackit/provider_acc_test.go b/stackit/provider_acc_test.go index 3acba151..3ba365a6 100644 --- a/stackit/provider_acc_test.go +++ b/stackit/provider_acc_test.go @@ -3,22 +3,14 @@ package stackit_test import ( "context" _ "embed" - "fmt" - "net/http" "os" "reflect" "regexp" "testing" - "time" - "github.com/golang-jwt/jwt/v5" "github.com/google/go-cmp/cmp" - test "github.com/hashicorp/terraform-plugin-testing/helper/resource" //nolint:staticcheck // used for acceptance testing - "github.com/jarcoal/httpmock" - "github.com/stackitcloud/stackit-sdk-go/core/clients" - - postgresflexalpha "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api" - + sqlserverflexalphaDatabase "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/database" + //nolint:staticcheck // used for acceptance testing postgresFlexAlphaFlavor "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/flavor" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -29,14 +21,11 @@ import ( postgresflexalphaFlavors "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/flavors" postgresFlexAlphaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance" postgresFlexAlphaUser "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/user" - //sqlserverflexalphaDatabase "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/database" - //sqlserverFlexAlphaFlavor "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/flavor" - //sqlserverFlexAlphaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance" - //sqlserverFlexAlphaUser "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/user" - //sqlserverflexBetaDatabase "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/database" - //sqlserverFlexBetaFlavor "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/flavor" - //sqlserverFlexBetaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/instance" - //sqlserverFlexBetaUser "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/user" + sqlserverFlexAlphaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance" + sqlserverFlexAlphaUser "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/user" + sqlserverflexBetaDatabase "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/database" + sqlserverFlexBetaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/instance" + sqlserverFlexBetaUser "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/user" "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils" @@ -62,110 +51,6 @@ func TestMain(m *testing.M) { os.Exit(code) } -func TestMshTest(t *testing.T) { - httpmock.Activate() - defer httpmock.DeactivateAndReset() - - testutils.ActivateEnvironmentHttpMocks() - - httpmock.RegisterResponder( - "POST", `https://service-account.api.stackit.cloud/token`, - func(_ *http.Request) (*http.Response, error) { - token := jwt.NewWithClaims( - jwt.SigningMethodHS256, jwt.MapClaims{ - "foo": "bar", - "nbf": time.Date(2015, 10, 10, 12, 0, 0, 0, time.UTC).Unix(), - }, - ) - // Sign and get the complete encoded token as a string using the secret - tokenString, err := token.SignedString([]byte("mySecret")) - if err != nil { - panic(err) - } - - tR := clients.TokenResponseBody{ - AccessToken: tokenString, - ExpiresIn: 3600, - RefreshToken: "", - Scope: "", - TokenType: "", - } - - return httpmock.NewJsonResponse(http.StatusOK, tR) - }, - ) - - httpmock.RegisterResponder( - "GET", - `https://postgres-flex-service.api.eu01.stackit.cloud/v3alpha1/projects/xyz-project-id/regions/eu01/flavors?page=1&size=25&sort=id.asc`, - func(_ *http.Request) (*http.Response, error) { - res := postgresflexalpha.GetFlavorsResponse{ - Flavors: []postgresflexalpha.ListFlavors{ - { - Cpu: 0, - Description: "", - Id: "", - MaxGB: 0, - Memory: 0, - MinGB: 0, - NodeType: "", - StorageClasses: nil, - }, - }, - Pagination: postgresflexalpha.Pagination{ - Page: (int32(1)), - Size: (int32(25)), - Sort: "", - TotalPages: (int32(1)), - TotalRows: (int32(0)), - }, - } - return httpmock.NewJsonResponse( - http.StatusOK, - res, - ) - }, - ) - - if _, ok := os.LookupEnv("TF_ACC_SERVICE_ACCOUNT_FILE"); !ok { - t.Skipf("TF_ACC_SERVICE_ACCOUNT_FILE is missing") - } - - test.Test( - t, test.TestCase{ - IsUnitTest: true, - ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories, - Steps: []test.TestStep{ - { - ConfigVariables: map[string]config.Variable{ - "project_id": config.StringVariable("xyz-project-id"), - }, - Config: fmt.Sprintf( - ` - provider "stackitprivatepreview" { - default_region = "%[1]s" - service_account_key_path = "%[2]s" - } - variable "project_id" { - type = string - } - data "stackitprivatepreview_postgresflexalpha_flavor" "all" { - project_id = var.project_id - region = "eu01" - cpu = 2 - ram = 4 - node_type = "Single" - storage_class = "premium-perf2-stackit" - }`, - os.Getenv("TF_ACC_REGION"), - os.Getenv("TF_ACC_SERVICE_ACCOUNT_FILE"), - ), - }, - }, - }, - ) -} - func TestUnitProviderHasChildDataSources_Basic(t *testing.T) { expectedDataSources := []datasource.DataSource{ postgresFlexAlphaFlavor.NewFlavorDataSource(), @@ -175,15 +60,15 @@ func TestUnitProviderHasChildDataSources_Basic(t *testing.T) { postgresFlexAlphaUser.NewUserDataSource(), postgresflexalphaFlavors.NewFlavorsDataSource(), - //sqlserverFlexAlphaFlavor.NewFlavorDataSource(), - //sqlserverFlexAlphaInstance.NewInstanceDataSource(), - //sqlserverFlexAlphaUser.NewUserDataSource(), - //sqlserverflexalphaDatabase.NewDatabaseDataSource(), + // sqlserverFlexAlphaFlavor.NewFlavorDataSource(), + sqlserverFlexAlphaInstance.NewInstanceDataSource(), + sqlserverFlexAlphaUser.NewUserDataSource(), + sqlserverflexalphaDatabase.NewDatabaseDataSource(), - //sqlserverflexBetaDatabase.NewDatabaseDataSource(), - //sqlserverFlexBetaInstance.NewInstanceDataSource(), - //sqlserverFlexBetaUser.NewUserDataSource(), - //sqlserverFlexBetaFlavor.NewFlavorDataSource(), + sqlserverflexBetaDatabase.NewDatabaseDataSource(), + sqlserverFlexBetaInstance.NewInstanceDataSource(), + sqlserverFlexBetaUser.NewUserDataSource(), + // sqlserverFlexBetaFlavor.NewFlavorDataSource(), } provider, ok := stackit.New("testing")().(*stackit.Provider) if !ok { @@ -212,13 +97,13 @@ func TestUnitProviderHasChildResources_Basic(t *testing.T) { postgresFlexAlphaUser.NewUserResource(), postgresFlexAlphaDatabase.NewDatabaseResource(), - //sqlserverFlexAlphaInstance.NewInstanceResource(), - //sqlserverFlexAlphaUser.NewUserResource(), - //sqlserverflexalphaDatabase.NewDatabaseResource(), + sqlserverFlexAlphaInstance.NewInstanceResource(), + sqlserverFlexAlphaUser.NewUserResource(), + sqlserverflexalphaDatabase.NewDatabaseResource(), - //sqlserverFlexBetaInstance.NewInstanceResource(), - //sqlserverFlexBetaUser.NewUserResource(), - //sqlserverflexBetaDatabase.NewDatabaseResource(), + sqlserverFlexBetaInstance.NewInstanceResource(), + sqlserverFlexBetaUser.NewUserResource(), + sqlserverflexBetaDatabase.NewDatabaseResource(), } provider, ok := stackit.New("testing")().(*stackit.Provider) if !ok {