From c28ae5e920669379c5ddf7cedeff15f95a8c589e Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 12 Jan 2024 09:24:16 +0100 Subject: [PATCH 01/21] apply update-atlas-sdk --- go.mod | 3 +-- go.sum | 6 ++---- internal/config/client.go | 4 ++-- internal/provider/provider_authentication_test.go | 2 +- .../alertconfiguration/data_source_alert_configuration.go | 2 +- .../data_source_alert_configuration_test.go | 2 +- .../alertconfiguration/data_source_alert_configurations.go | 2 +- .../service/alertconfiguration/model_alert_configuration.go | 2 +- .../alertconfiguration/model_alert_configuration_test.go | 2 +- .../alertconfiguration/resource_alert_configuration.go | 2 +- .../resource_alert_configuration_migration_test.go | 2 +- .../alertconfiguration/resource_alert_configuration_test.go | 2 +- internal/service/atlasuser/data_source_atlas_user.go | 2 +- internal/service/atlasuser/data_source_atlas_user_test.go | 2 +- internal/service/atlasuser/data_source_atlas_users.go | 2 +- internal/service/atlasuser/data_source_atlas_users_test.go | 2 +- .../service/databaseuser/data_source_database_user_test.go | 2 +- internal/service/databaseuser/model_database_user.go | 2 +- internal/service/databaseuser/model_database_user_test.go | 2 +- .../databaseuser/resource_database_user_migration_test.go | 2 +- .../service/databaseuser/resource_database_user_test.go | 2 +- .../service/encryptionatrest/model_encryption_at_rest.go | 2 +- .../encryptionatrest/model_encryption_at_rest_test.go | 2 +- .../service/encryptionatrest/resource_encryption_at_rest.go | 2 +- .../resource_encryption_at_rest_migration_test.go | 2 +- .../encryptionatrest/resource_encryption_at_rest_test.go | 2 +- .../service/encryptionatrest/service_encryption_at_rest.go | 2 +- .../data_source_federated_database_instance_test.go | 2 +- .../data_source_federated_database_instances.go | 2 +- .../resource_federated_database_instance.go | 2 +- .../data_source_federated_settings_identity_provider.go | 2 +- .../model_federated_settings_identity_provider.go | 2 +- .../resource_federated_settings_identity_provider.go | 4 ++-- .../resource_federated_settings_identity_provider_test.go | 2 +- internal/service/onlinearchive/resource_online_archive.go | 2 +- internal/service/project/data_source_project.go | 2 +- internal/service/project/data_source_project_test.go | 2 +- internal/service/project/data_source_projects.go | 2 +- internal/service/project/data_source_projects_test.go | 2 +- internal/service/project/model_project.go | 2 +- internal/service/project/model_project_test.go | 2 +- internal/service/project/resource_project.go | 2 +- internal/service/project/resource_project_migration_test.go | 2 +- internal/service/project/resource_project_test.go | 2 +- internal/service/project/service_project.go | 2 +- internal/service/projectapikey/resource_project_api_key.go | 2 +- .../projectipaccesslist/model_project_ip_access_list.go | 2 +- .../model_project_ip_access_list_test.go | 2 +- .../projectipaccesslist/resource_project_ip_access_list.go | 2 +- .../service/searchdeployment/model_search_deployment.go | 2 +- .../searchdeployment/model_search_deployment_test.go | 2 +- .../service/searchdeployment/service_search_deployment.go | 2 +- .../searchdeployment/state_transition_search_deployment.go | 2 +- .../state_transition_search_deployment_test.go | 2 +- internal/service/searchindex/data_source_search_indexes.go | 2 +- internal/service/searchindex/resource_search_index.go | 2 +- .../data_source_cloud_shared_tier_restore_jobs.go | 2 +- .../service/sharedtier/data_source_shared_tier_snapshots.go | 2 +- .../streamconnection/data_source_stream_connections.go | 2 +- .../streamconnection/data_source_stream_connections_test.go | 2 +- .../service/streamconnection/model_stream_connection.go | 2 +- .../streamconnection/model_stream_connection_test.go | 2 +- .../service/streaminstance/data_source_stream_instances.go | 2 +- .../streaminstance/data_source_stream_instances_test.go | 2 +- internal/service/streaminstance/model_stream_instance.go | 2 +- .../service/streaminstance/model_stream_instance_test.go | 2 +- internal/testutil/acc/database_user.go | 2 +- internal/testutil/acc/project.go | 2 +- internal/testutil/mocksvc/deployment_service.go | 2 +- internal/testutil/mocksvc/ear_service.go | 2 +- internal/testutil/mocksvc/group_project_service.go | 2 +- 71 files changed, 74 insertions(+), 77 deletions(-) diff --git a/go.mod b/go.mod index 216ba909d9..3d606c5df6 100644 --- a/go.mod +++ b/go.mod @@ -26,8 +26,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/zclconf/go-cty v1.14.1 go.mongodb.org/atlas v0.36.0 - go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0 - go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0 + go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0 go.mongodb.org/realm v0.1.0 golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 ) diff --git a/go.sum b/go.sum index 0c40f01eaf..3e510a19ab 100644 --- a/go.sum +++ b/go.sum @@ -759,10 +759,8 @@ github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgK go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M= go.mongodb.org/atlas v0.36.0 h1:m05S3AO7zkl+bcG1qaNsEKBnAqnKx2FDwLooHpIG3j4= go.mongodb.org/atlas v0.36.0/go.mod h1:nfPldE9dSama6G2IbIzmEza02Ly7yFZjMMVscaM0uEc= -go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0 h1:h1X2CGKyN1UFvNs69vp7xpufbbreq6p7bbrg5uJ1sxw= -go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0/go.mod h1:4TAUPaWPFNSbi8c1hbQLr1wAdkmqi48O7zvyXjBM+a8= -go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0 h1:x6nnq2pUIP9mN4WLD4/EseBzV88OmSgexxYchPilgno= -go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0/go.mod h1:el7cm23kEiiw72HAYimhNweKqp/ubHsNJk+Mk30yJhM= +go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0 h1:31Li8Xb1THAzYfAVDR9hhAn4z9IhmFs/+AbGqADsyt8= +go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0/go.mod h1:tXE5JorXFSauhnw9Xu+/tNrRh90rTX8rYs9y0i2Jy+c= go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M= go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= diff --git a/internal/config/client.go b/internal/config/client.go index 7731f50cc2..0a12b4a463 100644 --- a/internal/config/client.go +++ b/internal/config/client.go @@ -12,8 +12,8 @@ import ( "github.com/mongodb-forks/digest" "github.com/mongodb/terraform-provider-mongodbatlas/version" "github.com/spf13/cast" - oldAtlasSDK "go.mongodb.org/atlas-sdk/v20231001002/admin" - atlasSDK "go.mongodb.org/atlas-sdk/v20231115002/admin" + oldAtlasSDK "go.mongodb.org/atlas-sdk/v20231115003/admin" + atlasSDK "go.mongodb.org/atlas-sdk/v20231115003/admin" matlasClient "go.mongodb.org/atlas/mongodbatlas" realmAuth "go.mongodb.org/realm/auth" "go.mongodb.org/realm/realm" diff --git a/internal/provider/provider_authentication_test.go b/internal/provider/provider_authentication_test.go index 3938db2b39..3935fecf0a 100644 --- a/internal/provider/provider_authentication_test.go +++ b/internal/provider/provider_authentication_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccSTSAssumeRole_basic(t *testing.T) { diff --git a/internal/service/alertconfiguration/data_source_alert_configuration.go b/internal/service/alertconfiguration/data_source_alert_configuration.go index 95956d2041..082419f1a9 100644 --- a/internal/service/alertconfiguration/data_source_alert_configuration.go +++ b/internal/service/alertconfiguration/data_source_alert_configuration.go @@ -14,7 +14,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/zclconf/go-cty/cty" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var _ datasource.DataSource = &alertConfigurationDS{} diff --git a/internal/service/alertconfiguration/data_source_alert_configuration_test.go b/internal/service/alertconfiguration/data_source_alert_configuration_test.go index 667554eebb..96b1f407b3 100644 --- a/internal/service/alertconfiguration/data_source_alert_configuration_test.go +++ b/internal/service/alertconfiguration/data_source_alert_configuration_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigDSAlertConfiguration_basic(t *testing.T) { diff --git a/internal/service/alertconfiguration/data_source_alert_configurations.go b/internal/service/alertconfiguration/data_source_alert_configurations.go index 1560be961c..7ecb7b5761 100644 --- a/internal/service/alertconfiguration/data_source_alert_configurations.go +++ b/internal/service/alertconfiguration/data_source_alert_configurations.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const alertConfigurationsDataSourceName = "alert_configurations" diff --git a/internal/service/alertconfiguration/model_alert_configuration.go b/internal/service/alertconfiguration/model_alert_configuration.go index 1574c22983..eb48f0bd2e 100644 --- a/internal/service/alertconfiguration/model_alert_configuration.go +++ b/internal/service/alertconfiguration/model_alert_configuration.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mwielbut/pointy" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewNotificationList(tfNotificationSlice []TfNotificationModel) ([]admin.AlertsNotificationRootForGroup, error) { diff --git a/internal/service/alertconfiguration/model_alert_configuration_test.go b/internal/service/alertconfiguration/model_alert_configuration_test.go index cc00599378..bcdc1423f1 100644 --- a/internal/service/alertconfiguration/model_alert_configuration_test.go +++ b/internal/service/alertconfiguration/model_alert_configuration_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/alertconfiguration/resource_alert_configuration.go b/internal/service/alertconfiguration/resource_alert_configuration.go index 14670d111b..037e0e0b6b 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration.go +++ b/internal/service/alertconfiguration/resource_alert_configuration.go @@ -21,7 +21,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mwielbut/pointy" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/alertconfiguration/resource_alert_configuration_migration_test.go b/internal/service/alertconfiguration/resource_alert_configuration_migration_test.go index eb74dfca5b..99a7c89c2d 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration_migration_test.go +++ b/internal/service/alertconfiguration/resource_alert_configuration_migration_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" diff --git a/internal/service/alertconfiguration/resource_alert_configuration_test.go b/internal/service/alertconfiguration/resource_alert_configuration_test.go index bc0d1294b5..1d0d8c39f5 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration_test.go +++ b/internal/service/alertconfiguration/resource_alert_configuration_test.go @@ -14,7 +14,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigRSAlertConfiguration_basic(t *testing.T) { diff --git a/internal/service/atlasuser/data_source_atlas_user.go b/internal/service/atlasuser/data_source_atlas_user.go index 6246dba48c..d508fd118a 100644 --- a/internal/service/atlasuser/data_source_atlas_user.go +++ b/internal/service/atlasuser/data_source_atlas_user.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/atlasuser/data_source_atlas_user_test.go b/internal/service/atlasuser/data_source_atlas_user_test.go index 5a19a64a41..701ede7b46 100644 --- a/internal/service/atlasuser/data_source_atlas_user_test.go +++ b/internal/service/atlasuser/data_source_atlas_user_test.go @@ -11,7 +11,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigDSAtlasUser_ByUserID(t *testing.T) { diff --git a/internal/service/atlasuser/data_source_atlas_users.go b/internal/service/atlasuser/data_source_atlas_users.go index 62dd95db88..cc16da601d 100644 --- a/internal/service/atlasuser/data_source_atlas_users.go +++ b/internal/service/atlasuser/data_source_atlas_users.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/atlasuser/data_source_atlas_users_test.go b/internal/service/atlasuser/data_source_atlas_users_test.go index 0dd2b01dcb..ec9abf3aeb 100644 --- a/internal/service/atlasuser/data_source_atlas_users_test.go +++ b/internal/service/atlasuser/data_source_atlas_users_test.go @@ -13,7 +13,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/atlasuser" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigDSAtlasUsers_ByOrgID(t *testing.T) { diff --git a/internal/service/databaseuser/data_source_database_user_test.go b/internal/service/databaseuser/data_source_database_user_test.go index 00191ab397..1374bb1532 100644 --- a/internal/service/databaseuser/data_source_database_user_test.go +++ b/internal/service/databaseuser/data_source_database_user_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigDSDatabaseUser_basic(t *testing.T) { diff --git a/internal/service/databaseuser/model_database_user.go b/internal/service/databaseuser/model_database_user.go index b32f8911a5..9ea7e08cb5 100644 --- a/internal/service/databaseuser/model_database_user.go +++ b/internal/service/databaseuser/model_database_user.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewMongoDBDatabaseUser(ctx context.Context, dbUserModel *TfDatabaseUserModel) (*admin.CloudDatabaseUser, diag.Diagnostics) { diff --git a/internal/service/databaseuser/model_database_user_test.go b/internal/service/databaseuser/model_database_user_test.go index 3a6fc2590f..48fd6a3823 100644 --- a/internal/service/databaseuser/model_database_user_test.go +++ b/internal/service/databaseuser/model_database_user_test.go @@ -9,7 +9,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/databaseuser" "github.com/stretchr/testify/assert" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var ( diff --git a/internal/service/databaseuser/resource_database_user_migration_test.go b/internal/service/databaseuser/resource_database_user_migration_test.go index e32ccb2e37..86e2bf597b 100644 --- a/internal/service/databaseuser/resource_database_user_migration_test.go +++ b/internal/service/databaseuser/resource_database_user_migration_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" diff --git a/internal/service/databaseuser/resource_database_user_test.go b/internal/service/databaseuser/resource_database_user_test.go index 2050cf539f..4b48a299d7 100644 --- a/internal/service/databaseuser/resource_database_user_test.go +++ b/internal/service/databaseuser/resource_database_user_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigRSDatabaseUser_basic(t *testing.T) { diff --git a/internal/service/encryptionatrest/model_encryption_at_rest.go b/internal/service/encryptionatrest/model_encryption_at_rest.go index 484518b885..d222a9c8fc 100644 --- a/internal/service/encryptionatrest/model_encryption_at_rest.go +++ b/internal/service/encryptionatrest/model_encryption_at_rest.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewTfEncryptionAtRestRSModel(ctx context.Context, projectID string, encryptionResp *admin.EncryptionAtRest) *TfEncryptionAtRestRSModel { diff --git a/internal/service/encryptionatrest/model_encryption_at_rest_test.go b/internal/service/encryptionatrest/model_encryption_at_rest_test.go index 997c5bd763..0adc2616ca 100644 --- a/internal/service/encryptionatrest/model_encryption_at_rest_test.go +++ b/internal/service/encryptionatrest/model_encryption_at_rest_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/encryptionatrest" "github.com/stretchr/testify/assert" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var ( diff --git a/internal/service/encryptionatrest/resource_encryption_at_rest.go b/internal/service/encryptionatrest/resource_encryption_at_rest.go index 190d55d648..79da5c665f 100644 --- a/internal/service/encryptionatrest/resource_encryption_at_rest.go +++ b/internal/service/encryptionatrest/resource_encryption_at_rest.go @@ -24,7 +24,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/project" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/encryptionatrest/resource_encryption_at_rest_migration_test.go b/internal/service/encryptionatrest/resource_encryption_at_rest_migration_test.go index 4c41b7319c..c8d191b54e 100644 --- a/internal/service/encryptionatrest/resource_encryption_at_rest_migration_test.go +++ b/internal/service/encryptionatrest/resource_encryption_at_rest_migration_test.go @@ -11,7 +11,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig" "github.com/mwielbut/pointy" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccMigrationAdvRS_EncryptionAtRest_basicAWS(t *testing.T) { diff --git a/internal/service/encryptionatrest/resource_encryption_at_rest_test.go b/internal/service/encryptionatrest/resource_encryption_at_rest_test.go index b623d250e4..0e13849f96 100644 --- a/internal/service/encryptionatrest/resource_encryption_at_rest_test.go +++ b/internal/service/encryptionatrest/resource_encryption_at_rest_test.go @@ -20,7 +20,7 @@ import ( "github.com/mwielbut/pointy" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/encryptionatrest/service_encryption_at_rest.go b/internal/service/encryptionatrest/service_encryption_at_rest.go index 9528f0a0f9..d6334627a6 100644 --- a/internal/service/encryptionatrest/service_encryption_at_rest.go +++ b/internal/service/encryptionatrest/service_encryption_at_rest.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) type EarService interface { diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go index b50557501d..b0d76c8c11 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go @@ -13,7 +13,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccDataSourceFederatedDatabaseInstance_basic(t *testing.T) { diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go index 9cb193728f..d0e93fc9cb 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index e7053d9b26..93266a88fa 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -7,7 +7,7 @@ import ( "net/http" "strings" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go index 37b89142ed..87f20c75ad 100644 --- a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go @@ -7,7 +7,7 @@ import ( "sort" "strings" - oldAdmin "go.mongodb.org/atlas-sdk/v20231001002/admin" + oldAdmin "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go index be0e892da8..3228ff8871 100644 --- a/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" matlas "go.mongodb.org/atlas/mongodbatlas" ) diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index 15a2affd0b..fdffba8c65 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -7,8 +7,8 @@ import ( "net/http" "regexp" - oldAdmin "go.mongodb.org/atlas-sdk/v20231001002/admin" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + oldAdmin "go.mongodb.org/atlas-sdk/v20231115003/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go index 9a57d35244..05195c3cbc 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go @@ -11,7 +11,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccFedRSFederatedSettingsIdentityProvider_basic(t *testing.T) { diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index 83b0582d3c..01eb0a1a5d 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -16,7 +16,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mwielbut/pointy" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/project/data_source_project.go b/internal/service/project/data_source_project.go index e27ce51fd7..b64436dd25 100644 --- a/internal/service/project/data_source_project.go +++ b/internal/service/project/data_source_project.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" diff --git a/internal/service/project/data_source_project_test.go b/internal/service/project/data_source_project_test.go index f3dc9fb73a..bb99a711fe 100644 --- a/internal/service/project/data_source_project_test.go +++ b/internal/service/project/data_source_project_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" diff --git a/internal/service/project/data_source_projects.go b/internal/service/project/data_source_projects.go index f3e060f9a8..022af1dbdc 100644 --- a/internal/service/project/data_source_projects.go +++ b/internal/service/project/data_source_projects.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const projectsDataSourceName = "projects" diff --git a/internal/service/project/data_source_projects_test.go b/internal/service/project/data_source_projects_test.go index ba9fdf4043..ccdbf4c66c 100644 --- a/internal/service/project/data_source_projects_test.go +++ b/internal/service/project/data_source_projects_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" diff --git a/internal/service/project/model_project.go b/internal/service/project/model_project.go index 5a58ea3763..1ee707d429 100644 --- a/internal/service/project/model_project.go +++ b/internal/service/project/model_project.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewTFProjectDataSourceModel(ctx context.Context, project *admin.Group, diff --git a/internal/service/project/model_project_test.go b/internal/service/project/model_project_test.go index 1bd655ee6e..17887436c9 100644 --- a/internal/service/project/model_project_test.go +++ b/internal/service/project/model_project_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/project" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index 3c0bdad36a..4efab44a4f 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -9,7 +9,7 @@ import ( "sort" "time" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" diff --git a/internal/service/project/resource_project_migration_test.go b/internal/service/project/resource_project_migration_test.go index cea6a6961d..0760959aad 100644 --- a/internal/service/project/resource_project_migration_test.go +++ b/internal/service/project/resource_project_migration_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" diff --git a/internal/service/project/resource_project_test.go b/internal/service/project/resource_project_test.go index 85e3fa1f92..b70c8439a6 100644 --- a/internal/service/project/resource_project_test.go +++ b/internal/service/project/resource_project_test.go @@ -18,7 +18,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mocksvc" "github.com/stretchr/testify/mock" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var ( diff --git a/internal/service/project/service_project.go b/internal/service/project/service_project.go index 2384eac840..2feb333e55 100644 --- a/internal/service/project/service_project.go +++ b/internal/service/project/service_project.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) type GroupProjectService interface { diff --git a/internal/service/projectapikey/resource_project_api_key.go b/internal/service/projectapikey/resource_project_api_key.go index 7f71cf17cb..d36fdcda76 100644 --- a/internal/service/projectapikey/resource_project_api_key.go +++ b/internal/service/projectapikey/resource_project_api_key.go @@ -12,7 +12,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" matlas "go.mongodb.org/atlas/mongodbatlas" ) diff --git a/internal/service/projectipaccesslist/model_project_ip_access_list.go b/internal/service/projectipaccesslist/model_project_ip_access_list.go index 88611806c4..c3b00d4bc3 100644 --- a/internal/service/projectipaccesslist/model_project_ip_access_list.go +++ b/internal/service/projectipaccesslist/model_project_ip_access_list.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewMongoDBProjectIPAccessList(projectIPAccessListModel *TfProjectIPAccessListModel) *[]admin.NetworkPermissionEntry { diff --git a/internal/service/projectipaccesslist/model_project_ip_access_list_test.go b/internal/service/projectipaccesslist/model_project_ip_access_list_test.go index c6608bf394..1eca74d382 100644 --- a/internal/service/projectipaccesslist/model_project_ip_access_list_test.go +++ b/internal/service/projectipaccesslist/model_project_ip_access_list_test.go @@ -9,7 +9,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/projectipaccesslist" "github.com/stretchr/testify/assert" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var ( diff --git a/internal/service/projectipaccesslist/resource_project_ip_access_list.go b/internal/service/projectipaccesslist/resource_project_ip_access_list.go index c3395a05cf..3bb1f2b7fa 100644 --- a/internal/service/projectipaccesslist/resource_project_ip_access_list.go +++ b/internal/service/projectipaccesslist/resource_project_ip_access_list.go @@ -20,7 +20,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/searchdeployment/model_search_deployment.go b/internal/service/searchdeployment/model_search_deployment.go index d8f77e3b2b..39a3696c90 100644 --- a/internal/service/searchdeployment/model_search_deployment.go +++ b/internal/service/searchdeployment/model_search_deployment.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewSearchDeploymentReq(ctx context.Context, searchDeploymentPlan *TFSearchDeploymentRSModel) admin.ApiSearchDeploymentRequest { diff --git a/internal/service/searchdeployment/model_search_deployment_test.go b/internal/service/searchdeployment/model_search_deployment_test.go index 7fe31ba34c..3914d23768 100644 --- a/internal/service/searchdeployment/model_search_deployment_test.go +++ b/internal/service/searchdeployment/model_search_deployment_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/searchdeployment" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) type sdkToTFModelTestCase struct { diff --git a/internal/service/searchdeployment/service_search_deployment.go b/internal/service/searchdeployment/service_search_deployment.go index 4d90230b49..722d48a6bd 100644 --- a/internal/service/searchdeployment/service_search_deployment.go +++ b/internal/service/searchdeployment/service_search_deployment.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) type DeploymentService interface { diff --git a/internal/service/searchdeployment/state_transition_search_deployment.go b/internal/service/searchdeployment/state_transition_search_deployment.go index 64cf06a948..9ec570b2ea 100644 --- a/internal/service/searchdeployment/state_transition_search_deployment.go +++ b/internal/service/searchdeployment/state_transition_search_deployment.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const SearchDeploymentDoesNotExistsError = "ATLAS_FTS_DEPLOYMENT_DOES_NOT_EXIST" diff --git a/internal/service/searchdeployment/state_transition_search_deployment_test.go b/internal/service/searchdeployment/state_transition_search_deployment_test.go index 9541b046b6..96de1a075a 100644 --- a/internal/service/searchdeployment/state_transition_search_deployment_test.go +++ b/internal/service/searchdeployment/state_transition_search_deployment_test.go @@ -12,7 +12,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/searchdeployment" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mocksvc" "github.com/stretchr/testify/assert" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var ( diff --git a/internal/service/searchindex/data_source_search_indexes.go b/internal/service/searchindex/data_source_search_indexes.go index eac7675ea0..31675fbdc3 100644 --- a/internal/service/searchindex/data_source_search_indexes.go +++ b/internal/service/searchindex/data_source_search_indexes.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func PluralDataSource() *schema.Resource { diff --git a/internal/service/searchindex/resource_search_index.go b/internal/service/searchindex/resource_search_index.go index 01f99662b3..fe01df9dc9 100644 --- a/internal/service/searchindex/resource_search_index.go +++ b/internal/service/searchindex/resource_search_index.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go b/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go index 98cd0ad90c..c87de70367 100644 --- a/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go +++ b/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - atlasSDK "go.mongodb.org/atlas-sdk/v20231115002/admin" + atlasSDK "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" diff --git a/internal/service/sharedtier/data_source_shared_tier_snapshots.go b/internal/service/sharedtier/data_source_shared_tier_snapshots.go index 5375e41f4b..b7ab78cb26 100644 --- a/internal/service/sharedtier/data_source_shared_tier_snapshots.go +++ b/internal/service/sharedtier/data_source_shared_tier_snapshots.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - atlasSDK "go.mongodb.org/atlas-sdk/v20231115002/admin" + atlasSDK "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" diff --git a/internal/service/streamconnection/data_source_stream_connections.go b/internal/service/streamconnection/data_source_stream_connections.go index 5eae9bb5a6..66bda56caa 100644 --- a/internal/service/streamconnection/data_source_stream_connections.go +++ b/internal/service/streamconnection/data_source_stream_connections.go @@ -10,7 +10,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/dsschema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var _ datasource.DataSource = &streamConnectionsDS{} diff --git a/internal/service/streamconnection/data_source_stream_connections_test.go b/internal/service/streamconnection/data_source_stream_connections_test.go index c4fdd57af6..25569960b3 100644 --- a/internal/service/streamconnection/data_source_stream_connections_test.go +++ b/internal/service/streamconnection/data_source_stream_connections_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccStreamDSStreamConnections_basic(t *testing.T) { diff --git a/internal/service/streamconnection/model_stream_connection.go b/internal/service/streamconnection/model_stream_connection.go index ce7c9d5255..b7aafee88b 100644 --- a/internal/service/streamconnection/model_stream_connection.go +++ b/internal/service/streamconnection/model_stream_connection.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewStreamConnectionReq(ctx context.Context, plan *TFStreamConnectionModel) (*admin.StreamsConnection, diag.Diagnostics) { diff --git a/internal/service/streamconnection/model_stream_connection_test.go b/internal/service/streamconnection/model_stream_connection_test.go index 838dd62b68..0ba584cda0 100644 --- a/internal/service/streamconnection/model_stream_connection_test.go +++ b/internal/service/streamconnection/model_stream_connection_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/streamconnection" "github.com/stretchr/testify/assert" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/streaminstance/data_source_stream_instances.go b/internal/service/streaminstance/data_source_stream_instances.go index 1ca3cfb1a7..3a0b32ff15 100644 --- a/internal/service/streaminstance/data_source_stream_instances.go +++ b/internal/service/streaminstance/data_source_stream_instances.go @@ -10,7 +10,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/dsschema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var _ datasource.DataSource = &streamInstancesDS{} diff --git a/internal/service/streaminstance/data_source_stream_instances_test.go b/internal/service/streaminstance/data_source_stream_instances_test.go index 3b5cb5a645..f2ba3848f8 100644 --- a/internal/service/streaminstance/data_source_stream_instances_test.go +++ b/internal/service/streaminstance/data_source_stream_instances_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccStreamDSStreamInstances_basic(t *testing.T) { diff --git a/internal/service/streaminstance/model_stream_instance.go b/internal/service/streaminstance/model_stream_instance.go index 4871b93a37..d54f7e1de4 100644 --- a/internal/service/streaminstance/model_stream_instance.go +++ b/internal/service/streaminstance/model_stream_instance.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewStreamInstanceCreateReq(ctx context.Context, plan *TFStreamInstanceModel) (*admin.StreamsTenant, diag.Diagnostics) { diff --git a/internal/service/streaminstance/model_stream_instance_test.go b/internal/service/streaminstance/model_stream_instance_test.go index c5e1e4408a..98aa289d40 100644 --- a/internal/service/streaminstance/model_stream_instance_test.go +++ b/internal/service/streaminstance/model_stream_instance_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/streaminstance" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/testutil/acc/database_user.go b/internal/testutil/acc/database_user.go index d1ec9e0611..3b92867f2d 100644 --- a/internal/testutil/acc/database_user.go +++ b/internal/testutil/acc/database_user.go @@ -10,7 +10,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/databaseuser" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func CheckDatabaseUserExists(resourceName string, dbUser *admin.CloudDatabaseUser) resource.TestCheckFunc { diff --git a/internal/testutil/acc/project.go b/internal/testutil/acc/project.go index 9c84d71bf3..c17ef8a112 100644 --- a/internal/testutil/acc/project.go +++ b/internal/testutil/acc/project.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func CheckProjectExists(resourceName string, project *admin.Group) resource.TestCheckFunc { diff --git a/internal/testutil/mocksvc/deployment_service.go b/internal/testutil/mocksvc/deployment_service.go index 62c96ad9bd..4465516fbf 100644 --- a/internal/testutil/mocksvc/deployment_service.go +++ b/internal/testutil/mocksvc/deployment_service.go @@ -5,7 +5,7 @@ package mocksvc import ( context "context" - admin "go.mongodb.org/atlas-sdk/v20231115002/admin" + admin "go.mongodb.org/atlas-sdk/v20231115003/admin" http "net/http" diff --git a/internal/testutil/mocksvc/ear_service.go b/internal/testutil/mocksvc/ear_service.go index ea9825f425..08b32f1c7e 100644 --- a/internal/testutil/mocksvc/ear_service.go +++ b/internal/testutil/mocksvc/ear_service.go @@ -5,7 +5,7 @@ package mocksvc import ( context "context" - admin "go.mongodb.org/atlas-sdk/v20231115002/admin" + admin "go.mongodb.org/atlas-sdk/v20231115003/admin" http "net/http" diff --git a/internal/testutil/mocksvc/group_project_service.go b/internal/testutil/mocksvc/group_project_service.go index 3b7a4b31d8..e9adc3f78d 100644 --- a/internal/testutil/mocksvc/group_project_service.go +++ b/internal/testutil/mocksvc/group_project_service.go @@ -5,7 +5,7 @@ package mocksvc import ( context "context" - admin "go.mongodb.org/atlas-sdk/v20231115002/admin" + admin "go.mongodb.org/atlas-sdk/v20231115003/admin" http "net/http" From 32d630a269b84b64f61013dd66f6aae0b2dae83e Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 12 Jan 2024 10:58:43 +0100 Subject: [PATCH 02/21] revert changes to oldAdmin --- go.mod | 1 + go.sum | 2 ++ internal/config/client.go | 2 +- .../data_source_federated_settings_identity_provider.go | 2 +- .../resource_federated_settings_identity_provider.go | 2 +- 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3d606c5df6..84a44ac9fd 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/zclconf/go-cty v1.14.1 go.mongodb.org/atlas v0.36.0 + go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0 go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0 go.mongodb.org/realm v0.1.0 golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 diff --git a/go.sum b/go.sum index 3e510a19ab..0bbcb169fc 100644 --- a/go.sum +++ b/go.sum @@ -759,6 +759,8 @@ github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgK go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M= go.mongodb.org/atlas v0.36.0 h1:m05S3AO7zkl+bcG1qaNsEKBnAqnKx2FDwLooHpIG3j4= go.mongodb.org/atlas v0.36.0/go.mod h1:nfPldE9dSama6G2IbIzmEza02Ly7yFZjMMVscaM0uEc= +go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0 h1:h1X2CGKyN1UFvNs69vp7xpufbbreq6p7bbrg5uJ1sxw= +go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0/go.mod h1:4TAUPaWPFNSbi8c1hbQLr1wAdkmqi48O7zvyXjBM+a8= go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0 h1:31Li8Xb1THAzYfAVDR9hhAn4z9IhmFs/+AbGqADsyt8= go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0/go.mod h1:tXE5JorXFSauhnw9Xu+/tNrRh90rTX8rYs9y0i2Jy+c= go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M= diff --git a/internal/config/client.go b/internal/config/client.go index 0a12b4a463..4cffb723a4 100644 --- a/internal/config/client.go +++ b/internal/config/client.go @@ -12,7 +12,7 @@ import ( "github.com/mongodb-forks/digest" "github.com/mongodb/terraform-provider-mongodbatlas/version" "github.com/spf13/cast" - oldAtlasSDK "go.mongodb.org/atlas-sdk/v20231115003/admin" + oldAtlasSDK "go.mongodb.org/atlas-sdk/v20231001002/admin" atlasSDK "go.mongodb.org/atlas-sdk/v20231115003/admin" matlasClient "go.mongodb.org/atlas/mongodbatlas" realmAuth "go.mongodb.org/realm/auth" diff --git a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go index 87f20c75ad..37b89142ed 100644 --- a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go @@ -7,7 +7,7 @@ import ( "sort" "strings" - oldAdmin "go.mongodb.org/atlas-sdk/v20231115003/admin" + oldAdmin "go.mongodb.org/atlas-sdk/v20231001002/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index fdffba8c65..cf0510dc22 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -7,7 +7,7 @@ import ( "net/http" "regexp" - oldAdmin "go.mongodb.org/atlas-sdk/v20231115003/admin" + oldAdmin "go.mongodb.org/atlas-sdk/v20231001002/admin" "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" From 2527ba6bf8b220e45f8bddf9d354ab5a0e10bdc4 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 12 Jan 2024 11:04:52 +0100 Subject: [PATCH 03/21] remove atlasSDK alias --- .../sharedtier/data_source_cloud_shared_tier_restore_jobs.go | 4 ++-- .../service/sharedtier/data_source_shared_tier_snapshots.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go b/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go index c87de70367..a1d9b4c214 100644 --- a/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go +++ b/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - atlasSDK "go.mongodb.org/atlas-sdk/v20231115003/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -109,7 +109,7 @@ func dataSourceMongoDBAtlasCloudSharedTierRestoreJobRead(ctx context.Context, d return nil } -func flattenShardTierRestoreJobs(sharedTierJobs []atlasSDK.TenantRestore) []map[string]any { +func flattenShardTierRestoreJobs(sharedTierJobs []admin.TenantRestore) []map[string]any { if len(sharedTierJobs) == 0 { return nil } diff --git a/internal/service/sharedtier/data_source_shared_tier_snapshots.go b/internal/service/sharedtier/data_source_shared_tier_snapshots.go index b7ab78cb26..a75cbf16d0 100644 --- a/internal/service/sharedtier/data_source_shared_tier_snapshots.go +++ b/internal/service/sharedtier/data_source_shared_tier_snapshots.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - atlasSDK "go.mongodb.org/atlas-sdk/v20231115003/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -92,7 +92,7 @@ func dataSourceMongoDBAtlasSharedTierSnapshotsRead(ctx context.Context, d *schem return nil } -func flattenSharedTierSnapshots(sharedTierSnapshots []atlasSDK.BackupTenantSnapshot) []map[string]any { +func flattenSharedTierSnapshots(sharedTierSnapshots []admin.BackupTenantSnapshot) []map[string]any { if len(sharedTierSnapshots) == 0 { return nil } From 2587fb3ab34c92c437ce933139bdd0a69aea2423 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 12 Jan 2024 16:03:55 +0100 Subject: [PATCH 04/21] use SlicePtrToSlice and NonEmptySliceToPtrSlice --- internal/common/conversion/type_conversion.go | 14 ++++++++++ .../data_source_alert_configuration.go | 19 +++++++------- .../data_source_alert_configurations.go | 2 +- .../model_alert_configuration.go | 14 +++++----- .../model_alert_configuration_test.go | 4 +-- .../resource_alert_configuration.go | 8 +++--- .../atlasuser/data_source_atlas_user.go | 6 ++--- .../atlasuser/data_source_atlas_user_test.go | 4 +-- .../atlasuser/data_source_atlas_users.go | 6 ++--- .../atlasuser/data_source_atlas_users_test.go | 4 +-- .../databaseuser/model_database_user.go | 18 ++++++------- .../databaseuser/model_database_user_test.go | 6 ++--- ...data_source_federated_database_instance.go | 4 +-- ...ata_source_federated_database_instances.go | 5 ++-- .../resource_federated_database_instance.go | 26 +++++++++---------- ...ce_federated_settings_identity_provider.go | 2 +- ...el_federated_settings_identity_provider.go | 14 +++++----- ...ce_federated_settings_identity_provider.go | 2 +- .../data_source_online_archive.go | 8 +++--- .../onlinearchive/resource_online_archive.go | 11 ++++---- .../project/data_source_project_test.go | 12 ++++----- .../service/project/data_source_projects.go | 7 ++--- .../project/data_source_projects_test.go | 8 +++--- internal/service/project/model_project.go | 16 +++++------- .../service/project/model_project_test.go | 6 ++--- internal/service/project/resource_project.go | 7 ++--- .../resource_project_migration_test.go | 4 +-- .../service/project/resource_project_test.go | 16 ++++++------ .../model_search_deployment.go | 5 ++-- .../model_search_deployment_test.go | 4 +-- ...state_transition_search_deployment_test.go | 2 +- .../searchindex/data_source_search_index.go | 12 ++++----- .../searchindex/data_source_search_indexes.go | 13 +++++----- .../searchindex/resource_search_index.go | 22 ++++++++-------- ...a_source_cloud_shared_tier_restore_jobs.go | 2 +- .../data_source_shared_tier_snapshots.go | 2 +- .../model_stream_connection.go | 7 ++--- .../model_stream_connection_test.go | 4 +-- .../streaminstance/model_stream_instance.go | 7 ++--- .../model_stream_instance_test.go | 8 +++--- 40 files changed, 179 insertions(+), 162 deletions(-) diff --git a/internal/common/conversion/type_conversion.go b/internal/common/conversion/type_conversion.go index 539dbea6b5..cbc1f17f75 100644 --- a/internal/common/conversion/type_conversion.go +++ b/internal/common/conversion/type_conversion.go @@ -56,3 +56,17 @@ func IsStringPresent(strPtr *string) bool { func MongoDBRegionToAWSRegion(region string) string { return strings.ReplaceAll(strings.ToLower(region), "_", "-") } + +func SlicePtrToSlice[T any](v *[]T) []T { + if v == nil { + return nil + } + return *v +} + +func NonEmptySliceToPtrSlice[T any](v []T) *[]T { + if len(v) == 0 { + return nil + } + return &v +} diff --git a/internal/service/alertconfiguration/data_source_alert_configuration.go b/internal/service/alertconfiguration/data_source_alert_configuration.go index 082419f1a9..33e6fa77ba 100644 --- a/internal/service/alertconfiguration/data_source_alert_configuration.go +++ b/internal/service/alertconfiguration/data_source_alert_configuration.go @@ -319,7 +319,7 @@ func outputAlertConfigurationResourceHcl(label string, alert *admin.GroupAlertsC resource.SetAttributeValue("enabled", cty.BoolVal(*alert.Enabled)) } - for _, matcher := range alert.Matchers { + for _, matcher := range conversion.SlicePtrToSlice(alert.Matchers) { appendBlockWithCtyValues(resource, "matcher", []string{}, convertMatcherToCtyValues(matcher)) } @@ -331,8 +331,9 @@ func outputAlertConfigurationResourceHcl(label string, alert *admin.GroupAlertsC appendBlockWithCtyValues(resource, "threshold_config", []string{}, convertThresholdToCtyValues(alert.Threshold)) } - for i := 0; i < len(alert.Notifications); i++ { - appendBlockWithCtyValues(resource, "notification", []string{}, convertNotificationToCtyValues(&alert.Notifications[i])) + notifications := conversion.SlicePtrToSlice(alert.Notifications) + for i := 0; i < len(notifications); i++ { + appendBlockWithCtyValues(resource, "notification", []string{}, convertNotificationToCtyValues(¬ifications[i])) } return string(f.Bytes()) @@ -438,16 +439,14 @@ func convertNotificationToCtyValues(notification *admin.AlertsNotificationRootFo values["sms_enabled"] = cty.BoolVal(*notification.SmsEnabled) } - if len(notification.Roles) > 0 { - roles := make([]cty.Value, 0) - - for _, r := range notification.Roles { + if roles := conversion.SlicePtrToSlice(notification.Roles); len(roles) > 0 { + roleList := make([]cty.Value, 0) + for _, r := range roles { if r != "" { - roles = append(roles, cty.StringVal(r)) + roleList = append(roleList, cty.StringVal(r)) } } - - values["roles"] = cty.TupleVal(roles) + values["roles"] = cty.TupleVal(roleList) } return values diff --git a/internal/service/alertconfiguration/data_source_alert_configurations.go b/internal/service/alertconfiguration/data_source_alert_configurations.go index 7ecb7b5761..018b8afa17 100644 --- a/internal/service/alertconfiguration/data_source_alert_configurations.go +++ b/internal/service/alertconfiguration/data_source_alert_configurations.go @@ -143,7 +143,7 @@ func (d *AlertConfigurationsDS) Read(ctx context.Context, req datasource.ReadReq alertConfigurationsConfig.ID = types.StringValue(conversion.EncodeStateID(map[string]string{ "project_id": projectID, })) - alertConfigurationsConfig.Results = NewTFAlertConfigurationDSModelList(alerts.Results, projectID, alertConfigurationsConfig.OutputType) + alertConfigurationsConfig.Results = NewTFAlertConfigurationDSModelList(conversion.SlicePtrToSlice(alerts.Results), projectID, alertConfigurationsConfig.OutputType) if *params.IncludeCount { alertConfigurationsConfig.TotalCount = types.Int64Value(int64(*alerts.TotalCount)) } diff --git a/internal/service/alertconfiguration/model_alert_configuration.go b/internal/service/alertconfiguration/model_alert_configuration.go index eb48f0bd2e..9e03779127 100644 --- a/internal/service/alertconfiguration/model_alert_configuration.go +++ b/internal/service/alertconfiguration/model_alert_configuration.go @@ -43,7 +43,7 @@ func NewNotificationList(tfNotificationSlice []TfNotificationModel) ([]admin.Ale Username: n.Username.ValueStringPointer(), VictorOpsApiKey: n.VictorOpsAPIKey.ValueStringPointer(), VictorOpsRoutingKey: n.VictorOpsRoutingKey.ValueStringPointer(), - Roles: n.Roles, + Roles: conversion.NonEmptySliceToPtrSlice(n.Roles), MicrosoftTeamsWebhookUrl: n.MicrosoftTeamsWebhookURL.ValueStringPointer(), WebhookSecret: n.WebhookSecret.ValueStringPointer(), WebhookUrl: n.WebhookURL.ValueStringPointer(), @@ -108,8 +108,8 @@ func NewTFAlertConfigurationModel(apiRespConfig *admin.GroupAlertsConfig, currSt Enabled: types.BoolPointerValue(apiRespConfig.Enabled), MetricThresholdConfig: NewTFMetricThresholdConfigModel(apiRespConfig.MetricThreshold, currState.MetricThresholdConfig), ThresholdConfig: NewTFThresholdConfigModel(apiRespConfig.Threshold, currState.ThresholdConfig), - Notification: NewTFNotificationModelList(apiRespConfig.Notifications, currState.Notification), - Matcher: NewTFMatcherModelList(apiRespConfig.Matchers, currState.Matcher), + Notification: NewTFNotificationModelList(conversion.SlicePtrToSlice(apiRespConfig.Notifications), currState.Notification), + Matcher: NewTFMatcherModelList(conversion.SlicePtrToSlice(apiRespConfig.Matchers), currState.Matcher), } } @@ -121,7 +121,7 @@ func NewTFNotificationModelList(n []admin.AlertsNotificationRootForGroup, currSt value := n[i] notifications[i] = TfNotificationModel{ TeamName: conversion.StringPtrNullIfEmpty(value.TeamName), - Roles: value.Roles, + Roles: conversion.SlicePtrToSlice(value.Roles), ChannelName: conversion.StringPtrNullIfEmpty(value.ChannelName), DatadogRegion: conversion.StringPtrNullIfEmpty(value.DatadogRegion), DelayMin: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(value.DelayMin)), @@ -145,7 +145,7 @@ func NewTFNotificationModelList(n []admin.AlertsNotificationRootForGroup, currSt currState := currStateNotifications[i] newState := TfNotificationModel{ TeamName: conversion.StringPtrNullIfEmpty(value.TeamName), - Roles: value.Roles, + Roles: conversion.SlicePtrToSlice(value.Roles), // sentive attributes do not use value returned from API APIToken: conversion.StringNullIfEmpty(currState.APIToken.ValueString()), DatadogAPIKey: conversion.StringNullIfEmpty(currState.DatadogAPIKey.ValueString()), @@ -303,8 +303,8 @@ func NewTfAlertConfigurationDSModel(apiRespConfig *admin.GroupAlertsConfig, proj Enabled: types.BoolPointerValue(apiRespConfig.Enabled), MetricThresholdConfig: NewTFMetricThresholdConfigModel(apiRespConfig.MetricThreshold, []TfMetricThresholdConfigModel{}), ThresholdConfig: NewTFThresholdConfigModel(apiRespConfig.Threshold, []TfThresholdConfigModel{}), - Notification: NewTFNotificationModelList(apiRespConfig.Notifications, []TfNotificationModel{}), - Matcher: NewTFMatcherModelList(apiRespConfig.Matchers, []TfMatcherModel{}), + Notification: NewTFNotificationModelList(conversion.SlicePtrToSlice(apiRespConfig.Notifications), []TfNotificationModel{}), + Matcher: NewTFMatcherModelList(conversion.SlicePtrToSlice(apiRespConfig.Matchers), []TfMatcherModel{}), } } diff --git a/internal/service/alertconfiguration/model_alert_configuration_test.go b/internal/service/alertconfiguration/model_alert_configuration_test.go index bcdc1423f1..bfcb295d12 100644 --- a/internal/service/alertconfiguration/model_alert_configuration_test.go +++ b/internal/service/alertconfiguration/model_alert_configuration_test.go @@ -45,7 +45,7 @@ func TestNotificationSDKToTFModel(t *testing.T) { SmsEnabled: admin.PtrBool(disabled), EmailEnabled: admin.PtrBool(enabled), ChannelName: admin.PtrString("#channel"), - Roles: roles, + Roles: conversion.NonEmptySliceToPtrSlice(roles), ApiToken: admin.PtrString("newApiToken"), }, }, @@ -290,7 +290,7 @@ func TestNotificationTFModelToSDK(t *testing.T) { DelayMin: admin.PtrInt(delayMin), SmsEnabled: admin.PtrBool(disabled), EmailEnabled: admin.PtrBool(enabled), - Roles: roles, + Roles: conversion.NonEmptySliceToPtrSlice(roles), }, }, }, diff --git a/internal/service/alertconfiguration/resource_alert_configuration.go b/internal/service/alertconfiguration/resource_alert_configuration.go index 037e0e0b6b..b48828b4ef 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration.go +++ b/internal/service/alertconfiguration/resource_alert_configuration.go @@ -380,7 +380,7 @@ func (r *alertConfigurationRS) Create(ctx context.Context, req resource.CreateRe apiReq := &admin.GroupAlertsConfig{ EventTypeName: alertConfigPlan.EventType.ValueStringPointer(), Enabled: alertConfigPlan.Enabled.ValueBoolPointer(), - Matchers: NewMatcherList(alertConfigPlan.Matcher), + Matchers: conversion.NonEmptySliceToPtrSlice(NewMatcherList(alertConfigPlan.Matcher)), MetricThreshold: NewMetricThreshold(alertConfigPlan.MetricThresholdConfig), Threshold: NewThreshold(alertConfigPlan.ThresholdConfig), } @@ -390,7 +390,7 @@ func (r *alertConfigurationRS) Create(ctx context.Context, req resource.CreateRe resp.Diagnostics.AddError(errorCreateAlertConf, err.Error()) return } - apiReq.Notifications = notifications + apiReq.Notifications = conversion.NonEmptySliceToPtrSlice(notifications) apiResp, _, err := connV2.AlertConfigurationsApi.CreateAlertConfiguration(ctx, projectID, apiReq).Execute() if err != nil { @@ -482,7 +482,7 @@ func (r *alertConfigurationRS) Update(ctx context.Context, req resource.UpdateRe } if !reflect.DeepEqual(alertConfigPlan.Matcher, alertConfigState.Matcher) { - apiReq.Matchers = NewMatcherList(alertConfigPlan.Matcher) + apiReq.Matchers = conversion.NonEmptySliceToPtrSlice(NewMatcherList(alertConfigPlan.Matcher)) } // Always refresh structure to handle service keys being obfuscated coming back from read API call @@ -491,7 +491,7 @@ func (r *alertConfigurationRS) Update(ctx context.Context, req resource.UpdateRe resp.Diagnostics.AddError(errorUpdateAlertConf, err.Error()) return } - apiReq.Notifications = notifications + apiReq.Notifications = conversion.NonEmptySliceToPtrSlice(notifications) var updatedAlertConfigResp *admin.GroupAlertsConfig diff --git a/internal/service/atlasuser/data_source_atlas_user.go b/internal/service/atlasuser/data_source_atlas_user.go index d508fd118a..72b9c77a0f 100644 --- a/internal/service/atlasuser/data_source_atlas_user.go +++ b/internal/service/atlasuser/data_source_atlas_user.go @@ -189,9 +189,9 @@ func newTFAtlasUserDSModel(user *admin.CloudAppUser) tfAtlasUserDSModel { LastAuth: types.StringPointerValue(conversion.TimePtrToStringPtr(user.LastAuth)), LastName: types.StringValue(user.LastName), MobileNumber: types.StringValue(user.MobileNumber), - TeamIDs: user.TeamIds, - Links: newTFLinksList(user.Links), - Roles: newTFRolesList(user.Roles), + TeamIDs: conversion.SlicePtrToSlice(user.TeamIds), + Links: newTFLinksList(conversion.SlicePtrToSlice(user.Links)), + Roles: newTFRolesList(conversion.SlicePtrToSlice(user.Roles)), } } diff --git a/internal/service/atlasuser/data_source_atlas_user_test.go b/internal/service/atlasuser/data_source_atlas_user_test.go index 701ede7b46..ad37cc608e 100644 --- a/internal/service/atlasuser/data_source_atlas_user_test.go +++ b/internal/service/atlasuser/data_source_atlas_user_test.go @@ -66,8 +66,8 @@ func dataSourceChecksForUser(dataSourceName, attrPrefix string, user *admin.Clou resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%smobile_number", attrPrefix), user.MobileNumber), resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%scountry", attrPrefix), user.Country), resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%screated_at", attrPrefix), *conversion.TimePtrToStringPtr(user.CreatedAt)), - resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%steam_ids.#", attrPrefix), fmt.Sprintf("%d", len(user.TeamIds))), - resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%slinks.#", attrPrefix), fmt.Sprintf("%d", len(user.Links))), + resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%steam_ids.#", attrPrefix), fmt.Sprintf("%d", len(*user.TeamIds))), + resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%slinks.#", attrPrefix), fmt.Sprintf("%d", len(*user.Links))), // for assertion of roles the values of `user.Roles` must not be used as it has the risk of flaky executions. CLOUDP-220377 resource.TestCheckResourceAttrWith(dataSourceName, fmt.Sprintf("%sroles.#", attrPrefix), acc.IntGreatThan(0)), resource.TestCheckResourceAttrSet(dataSourceName, fmt.Sprintf("%sroles.0.role_name", attrPrefix)), diff --git a/internal/service/atlasuser/data_source_atlas_users.go b/internal/service/atlasuser/data_source_atlas_users.go index cc16da601d..81e8b543cd 100644 --- a/internal/service/atlasuser/data_source_atlas_users.go +++ b/internal/service/atlasuser/data_source_atlas_users.go @@ -191,7 +191,7 @@ func (d *atlasUsersDS) Read(ctx context.Context, req datasource.ReadRequest, res resp.Diagnostics.AddError("error when getting users from Atlas", fmt.Sprintf(errorUsersRead, "project", projectID, err.Error())) return } - users = apiResp.Results + users = conversion.SlicePtrToSlice(apiResp.Results) totalCount = *apiResp.TotalCount case !atlasUsersConfig.TeamID.IsNull() && !atlasUsersConfig.OrgID.IsNull(): teamID := atlasUsersConfig.TeamID.ValueString() @@ -205,7 +205,7 @@ func (d *atlasUsersDS) Read(ctx context.Context, req datasource.ReadRequest, res resp.Diagnostics.AddError("error when getting users from Atlas", fmt.Sprintf(errorUsersRead, "team", teamID, err.Error())) return } - users = apiResp.Results + users = conversion.SlicePtrToSlice(apiResp.Results) totalCount = *apiResp.TotalCount default: // only org_id is defined orgID := atlasUsersConfig.OrgID.ValueString() @@ -218,7 +218,7 @@ func (d *atlasUsersDS) Read(ctx context.Context, req datasource.ReadRequest, res resp.Diagnostics.AddError("error when getting users from Atlas", fmt.Sprintf(errorUsersRead, "org", orgID, err.Error())) return } - users = apiResp.Results + users = conversion.SlicePtrToSlice(apiResp.Results) totalCount = *apiResp.TotalCount } diff --git a/internal/service/atlasuser/data_source_atlas_users_test.go b/internal/service/atlasuser/data_source_atlas_users_test.go index ec9abf3aeb..0d3376d4f7 100644 --- a/internal/service/atlasuser/data_source_atlas_users_test.go +++ b/internal/service/atlasuser/data_source_atlas_users_test.go @@ -223,8 +223,8 @@ func dataSourceChecksForUsers(dataSourceName, orgID string, users *admin.Paginat resource.TestCheckResourceAttr(dataSourceName, "org_id", orgID), resource.TestCheckResourceAttr(dataSourceName, "total_count", fmt.Sprintf("%d", totalCountValue)), } - for i := range users.Results { - checks = append(checks, dataSourceChecksForUser(dataSourceName, fmt.Sprintf("results.%d.", i), &users.Results[i])...) + for i := range *users.Results { + checks = append(checks, dataSourceChecksForUser(dataSourceName, fmt.Sprintf("results.%d.", i), &(*users.Results)[i])...) } return checks diff --git a/internal/service/databaseuser/model_database_user.go b/internal/service/databaseuser/model_database_user.go index 9ea7e08cb5..b86f7e9169 100644 --- a/internal/service/databaseuser/model_database_user.go +++ b/internal/service/databaseuser/model_database_user.go @@ -40,24 +40,24 @@ func NewMongoDBDatabaseUser(ctx context.Context, dbUserModel *TfDatabaseUserMode OidcAuthType: dbUserModel.OIDCAuthType.ValueStringPointer(), LdapAuthType: dbUserModel.LDAPAuthType.ValueStringPointer(), DatabaseName: dbUserModel.AuthDatabaseName.ValueString(), - Roles: NewMongoDBAtlasRoles(rolesModel), - Labels: NewMongoDBAtlasLabels(labelsModel), - Scopes: NewMongoDBAtlasScopes(scopesModel), + Roles: conversion.NonEmptySliceToPtrSlice(NewMongoDBAtlasRoles(rolesModel)), + Labels: conversion.NonEmptySliceToPtrSlice(NewMongoDBAtlasLabels(labelsModel)), + Scopes: conversion.NonEmptySliceToPtrSlice(NewMongoDBAtlasScopes(scopesModel)), }, nil } func NewTfDatabaseUserModel(ctx context.Context, model *TfDatabaseUserModel, dbUser *admin.CloudDatabaseUser) (*TfDatabaseUserModel, diag.Diagnostics) { - rolesSet, diagnostic := types.SetValueFrom(ctx, RoleObjectType, NewTFRolesModel(dbUser.Roles)) + rolesSet, diagnostic := types.SetValueFrom(ctx, RoleObjectType, NewTFRolesModel(conversion.SlicePtrToSlice(dbUser.Roles))) if diagnostic.HasError() { return nil, diagnostic } - labelsSet, diagnostic := types.SetValueFrom(ctx, LabelObjectType, NewTFLabelsModel(dbUser.Labels)) + labelsSet, diagnostic := types.SetValueFrom(ctx, LabelObjectType, NewTFLabelsModel(conversion.SlicePtrToSlice(dbUser.Labels))) if diagnostic.HasError() { return nil, diagnostic } - scopesSet, diagnostic := types.SetValueFrom(ctx, ScopeObjectType, NewTFScopesModel(dbUser.Scopes)) + scopesSet, diagnostic := types.SetValueFrom(ctx, ScopeObjectType, NewTFScopesModel(conversion.SlicePtrToSlice(dbUser.Scopes))) if diagnostic.HasError() { return nil, diagnostic } @@ -102,9 +102,9 @@ func NewTFDatabaseDSUserModel(ctx context.Context, dbUser *admin.CloudDatabaseUs OIDCAuthType: types.StringValue(dbUser.GetOidcAuthType()), LDAPAuthType: types.StringValue(dbUser.GetLdapAuthType()), AWSIAMType: types.StringValue(dbUser.GetAwsIAMType()), - Roles: NewTFRolesModel(dbUser.Roles), - Labels: NewTFLabelsModel(dbUser.Labels), - Scopes: NewTFScopesModel(dbUser.Scopes), + Roles: NewTFRolesModel(conversion.SlicePtrToSlice(dbUser.Roles)), + Labels: NewTFLabelsModel(conversion.SlicePtrToSlice(dbUser.Labels)), + Scopes: NewTFScopesModel(conversion.SlicePtrToSlice(dbUser.Scopes)), } return databaseUserModel, nil diff --git a/internal/service/databaseuser/model_database_user_test.go b/internal/service/databaseuser/model_database_user_test.go index 48fd6a3823..ebae7a0f3f 100644 --- a/internal/service/databaseuser/model_database_user_test.go +++ b/internal/service/databaseuser/model_database_user_test.go @@ -69,9 +69,9 @@ var ( OidcAuthType: &oidCAuthType, LdapAuthType: &ldapAuthType, AwsIAMType: &awsIAMType, - Roles: []admin.DatabaseUserRole{sdkRole}, - Labels: []admin.ComponentLabel{sdkLabel}, - Scopes: []admin.UserScope{sdkScope}, + Roles: &[]admin.DatabaseUserRole{sdkRole}, + Labels: &[]admin.ComponentLabel{sdkLabel}, + Scopes: &[]admin.UserScope{sdkScope}, } ) diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go index 6aa8c171f2..c9ea9c38c1 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go @@ -347,13 +347,13 @@ func dataSourceMongoDBAtlasFederatedDatabaseInstanceRead(ctx context.Context, d return diag.FromErr(fmt.Errorf(errorFederatedDatabaseInstanceSetting, "data_process_region", name, err)) } - if storageDatabaseField := flattenDataFederationDatabase(dataFederationInstance.Storage.Databases); storageDatabaseField != nil { + if storageDatabaseField := flattenDataFederationDatabase(conversion.SlicePtrToSlice(dataFederationInstance.Storage.Databases)); storageDatabaseField != nil { if err := d.Set("storage_databases", storageDatabaseField); err != nil { return diag.FromErr(fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_databases", name, err)) } } - if err := d.Set("storage_stores", flattenDataFederationStores(dataFederationInstance.Storage.Stores)); err != nil { + if err := d.Set("storage_stores", flattenDataFederationStores(conversion.SlicePtrToSlice(dataFederationInstance.Storage.Stores))); err != nil { return diag.FromErr(fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_stores", name, err)) } diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go index d0e93fc9cb..44c7b49347 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -146,8 +147,8 @@ func flattenFederatedDatabaseInstances(d *schema.ResourceData, projectID string, "hostnames": federatedDatabaseInstances[i].GetHostnames(), "cloud_provider_config": flattenCloudProviderConfig(d, federatedDatabaseInstances[i].CloudProviderConfig), "data_process_region": flattenDataProcessRegion(federatedDatabaseInstances[i].DataProcessRegion), - "storage_databases": flattenDataFederationDatabase(federatedDatabaseInstances[i].Storage.Databases), - "storage_stores": flattenDataFederationStores(federatedDatabaseInstances[i].Storage.Stores), + "storage_databases": flattenDataFederationDatabase(conversion.SlicePtrToSlice(federatedDatabaseInstances[i].Storage.Databases)), + "storage_stores": flattenDataFederationStores(conversion.SlicePtrToSlice(federatedDatabaseInstances[i].Storage.Stores)), } } } diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index 93266a88fa..a53cf8b5d6 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -496,7 +496,7 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex if storage, ok := dataFederationInstance.GetStorageOk(); ok { if databases, ok := storage.GetDatabasesOk(); ok { - if storageDatabaseField := flattenDataFederationDatabase(databases); storageDatabaseField != nil { + if storageDatabaseField := flattenDataFederationDatabase(conversion.SlicePtrToSlice(databases)); storageDatabaseField != nil { if err := d.Set("storage_databases", storageDatabaseField); err != nil { return nil, fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_databases", name, err) } @@ -504,7 +504,7 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex } if stores, ok := storage.GetStoresOk(); ok { - if err := d.Set("storage_stores", flattenDataFederationStores(stores)); err != nil { + if err := d.Set("storage_stores", flattenDataFederationStores(conversion.SlicePtrToSlice(stores))); err != nil { return nil, fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_stores", name, err) } } @@ -528,8 +528,8 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex func newDataFederationStorage(d *schema.ResourceData) *admin.DataLakeStorage { return &admin.DataLakeStorage{ - Databases: newDataFederationDatabase(d), - Stores: newStores(d), + Databases: conversion.NonEmptySliceToPtrSlice(newDataFederationDatabase(d)), + Stores: conversion.NonEmptySliceToPtrSlice(newStores(d)), } } @@ -552,7 +552,7 @@ func newStores(d *schema.ResourceData) []admin.DataLakeStoreSettings { Prefix: conversion.StringPtr(storeFromConfMap["prefix"].(string)), Delimiter: conversion.StringPtr(storeFromConfMap["delimiter"].(string)), IncludeTags: conversion.Pointer(storeFromConfMap["include_tags"].(bool)), - AdditionalStorageClasses: newAdditionalStorageClasses(storeFromConfMap["additional_storage_classes"].([]any)), + AdditionalStorageClasses: conversion.NonEmptySliceToPtrSlice(newAdditionalStorageClasses(storeFromConfMap["additional_storage_classes"].([]any))), ReadPreference: newReadPreference(storeFromConfMap), } } @@ -582,7 +582,7 @@ func newReadPreference(storeFromConfMap map[string]any) *admin.DataLakeAtlasStor return &admin.DataLakeAtlasStoreReadPreference{ Mode: conversion.StringPtr(readPreferenceFromConfMap["mode"].(string)), MaxStalenessSeconds: conversion.IntPtr(readPreferenceFromConfMap["max_staleness_seconds"].(int)), - TagSets: newTagSets(readPreferenceFromConfMap), + TagSets: conversion.NonEmptySliceToPtrSlice(newTagSets(readPreferenceFromConfMap)), } } @@ -626,7 +626,7 @@ func newDataFederationDatabase(d *schema.ResourceData) []admin.DataLakeDatabaseI dbs[i] = admin.DataLakeDatabaseInstance{ Name: conversion.StringPtr(storageDBFromConfMap["name"].(string)), MaxWildcardCollections: conversion.IntPtr(storageDBFromConfMap["max_wildcard_collections"].(int)), - Collections: newDataFederationCollections(storageDBFromConfMap), + Collections: conversion.NonEmptySliceToPtrSlice(newDataFederationCollections(storageDBFromConfMap)), } } @@ -643,7 +643,7 @@ func newDataFederationCollections(storageDBFromConfMap map[string]any) []admin.D for i, collectionFromConf := range collectionsFromConf { collections[i] = admin.DataLakeDatabaseCollection{ Name: conversion.StringPtr(collectionFromConf.(map[string]any)["name"].(string)), - DataSources: newDataFederationDataSource(collectionFromConf.(map[string]any)), + DataSources: conversion.NonEmptySliceToPtrSlice(newDataFederationDataSource(collectionFromConf.(map[string]any))), } } @@ -670,7 +670,7 @@ func newDataFederationDataSource(collectionFromConf map[string]any) []admin.Data ProvenanceFieldName: conversion.StringPtr(dataSourceFromConfMap["provenance_field_name"].(string)), StoreName: conversion.StringPtr(dataSourceFromConfMap["store_name"].(string)), DatasetName: conversion.StringPtr(dataSourceFromConfMap["dataset_name"].(string)), - Urls: newUrls(dataSourceFromConfMap["urls"].([]any)), + Urls: conversion.NonEmptySliceToPtrSlice(newUrls(dataSourceFromConfMap["urls"].([]any))), } } @@ -777,8 +777,8 @@ func flattenDataFederationDatabase(atlasDatabases []admin.DataLakeDatabaseInstan dbs[i] = map[string]any{ "name": atlasDatabase.GetName(), "max_wildcard_collections": atlasDatabase.GetMaxWildcardCollections(), - "collections": flattenDataFederationCollections(atlasDatabase.Collections), - "views": flattenDataFederationDatabaseViews(atlasDatabase.Views), + "collections": flattenDataFederationCollections(conversion.SlicePtrToSlice(atlasDatabase.Collections)), + "views": flattenDataFederationDatabaseViews(conversion.SlicePtrToSlice(atlasDatabase.Views)), } } @@ -805,7 +805,7 @@ func flattenDataFederationCollections(atlasCollections []admin.DataLakeDatabaseC for i, atlasCollection := range atlasCollections { colls[i] = map[string]any{ "name": atlasCollection.GetName(), - "data_sources": flattenDataFederationDataSources(atlasCollection.DataSources), + "data_sources": flattenDataFederationDataSources(conversion.SlicePtrToSlice(atlasCollection.DataSources)), } } @@ -869,7 +869,7 @@ func newReadPreferenceField(atlasReadPreference *admin.DataLakeAtlasStoreReadPre { "mode": atlasReadPreference.GetMode(), "max_staleness_seconds": atlasReadPreference.GetMaxStalenessSeconds(), - "tag_sets": flattenReadPreferenceTagSets(atlasReadPreference.TagSets), + "tag_sets": flattenReadPreferenceTagSets(conversion.SlicePtrToSlice(atlasReadPreference.TagSets)), }, } } diff --git a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go index 37b89142ed..ecb26f4c92 100644 --- a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go @@ -242,7 +242,7 @@ func dataSourceMongoDBAtlasFederatedSettingsIdentityProviderRead(ctx context.Con return diag.FromErr(fmt.Errorf("error setting `associated_domains` for federatedSettings IdentityProviders: %s", err)) } - if err := d.Set("associated_orgs", FlattenAssociatedOrgs(federatedSettingsIdentityProvider.AssociatedOrgs)); err != nil { + if err := d.Set("associated_orgs", FlattenAssociatedOrgs(conversion.SlicePtrToSlice(federatedSettingsIdentityProvider.AssociatedOrgs))); err != nil { return diag.FromErr(fmt.Errorf("error setting `associated_orgs` for federatedSettings IdentityProviders: %s", err)) } diff --git a/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go index 3228ff8871..75770af640 100644 --- a/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go @@ -19,7 +19,7 @@ func FlattenFederatedSettingsIdentityProvider(federatedSettingsIdentityProvider federatedSettingsIdentityProviderMap[i] = map[string]any{ "acs_url": federatedSettingsIdentityProvider[i].AcsUrl, "associated_domains": federatedSettingsIdentityProvider[i].AssociatedDomains, - "associated_orgs": FlattenAssociatedOrgs(federatedSettingsIdentityProvider[i].AssociatedOrgs), + "associated_orgs": FlattenAssociatedOrgs(conversion.SlicePtrToSlice(federatedSettingsIdentityProvider[i].AssociatedOrgs)), "audience_uri": federatedSettingsIdentityProvider[i].AudienceUri, "display_name": federatedSettingsIdentityProvider[i].DisplayName, "issuer_uri": federatedSettingsIdentityProvider[i].IssuerUri, @@ -53,7 +53,7 @@ func FlattenAssociatedOrgs(associatedOrgs []admin.ConnectedOrgConfig) []map[stri "identity_provider_id": associatedOrgs[i].IdentityProviderId, "org_id": associatedOrgs[i].OrgId, "post_auth_role_grants": associatedOrgs[i].PostAuthRoleGrants, - "role_mappings": FlattenAuthFederationRoleMapping(associatedOrgs[i].RoleMappings), + "role_mappings": FlattenAuthFederationRoleMapping(conversion.SlicePtrToSlice(associatedOrgs[i].RoleMappings)), "user_conflicts": nil, } } else { @@ -63,8 +63,8 @@ func FlattenAssociatedOrgs(associatedOrgs []admin.ConnectedOrgConfig) []map[stri "identity_provider_id": associatedOrgs[i].IdentityProviderId, "org_id": associatedOrgs[i].OrgId, "post_auth_role_grants": associatedOrgs[i].PostAuthRoleGrants, - "role_mappings": FlattenAuthFederationRoleMapping(associatedOrgs[i].RoleMappings), - "user_conflicts": FlattenFederatedUser(associatedOrgs[i].UserConflicts), + "role_mappings": FlattenAuthFederationRoleMapping(conversion.SlicePtrToSlice(associatedOrgs[i].RoleMappings)), + "user_conflicts": FlattenFederatedUser(conversion.SlicePtrToSlice(associatedOrgs[i].UserConflicts)), } } } @@ -154,7 +154,7 @@ func FlattenAuthFederationRoleMapping(roleMappings []admin.AuthFederationRoleMap roleMappingsMap[i] = map[string]any{ "external_group_name": roleMappings[i].ExternalGroupName, "id": roleMappings[i].Id, - "role_assignments": FlattenRoleAssignmentsV2(roleMappings[i].RoleAssignments), + "role_assignments": FlattenRoleAssignmentsV2(conversion.SlicePtrToSlice(roleMappings[i].RoleAssignments)), } } } @@ -165,11 +165,11 @@ func FlattenAuthFederationRoleMapping(roleMappings []admin.AuthFederationRoleMap func FlattenPemFileInfo(pemFileInfo admin.PemFileInfo) []map[string]any { var pemFileInfoMap []map[string]any - if len(pemFileInfo.Certificates) > 0 { + if certificates := conversion.SlicePtrToSlice(pemFileInfo.Certificates); len(certificates) > 0 { pemFileInfoMap = make([]map[string]any, 1) pemFileInfoMap[0] = map[string]any{ - "certificates": FlattenFederatedSettingsCertificates(pemFileInfo.Certificates), + "certificates": FlattenFederatedSettingsCertificates(certificates), "file_name": pemFileInfo.FileName, } } diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index cf0510dc22..aec5af4c51 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -237,7 +237,7 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderUpdate(ctx context.Con if d.HasChange("associated_domains") { associatedDomains := d.Get("associated_domains") - updateRequest.AssociatedDomains = cast.ToStringSlice(associatedDomains) + updateRequest.AssociatedDomains = conversion.NonEmptySliceToPtrSlice(cast.ToStringSlice(associatedDomains)) } if d.HasChange("name") { diff --git a/internal/service/onlinearchive/data_source_online_archive.go b/internal/service/onlinearchive/data_source_online_archive.go index e7097eb365..60e5640f83 100644 --- a/internal/service/onlinearchive/data_source_online_archive.go +++ b/internal/service/onlinearchive/data_source_online_archive.go @@ -255,10 +255,10 @@ func dataSourceMongoDBAtlasOnlineArchivesRead(ctx context.Context, d *schema.Res return diag.FromErr(fmt.Errorf("error getting Online Archives list for project(%s) in cluster (%s): (%s)", projectID, clusterName, err.Error())) } - results := make([]map[string]any, 0, len(archives.Results)) - - for i := range archives.Results { - archiveData := fromOnlineArchiveToMap(&archives.Results[i]) + input := conversion.SlicePtrToSlice(archives.Results) + results := make([]map[string]any, 0, len(input)) + for i := range input { + archiveData := fromOnlineArchiveToMap(&input[i]) archiveData["project_id"] = projectID results = append(results, archiveData) } diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index 01eb0a1a5d..e189a6a69e 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -414,7 +414,7 @@ func mapToArchivePayload(d *schema.ResourceData) admin.BackupOnlineArchiveCreate partitionList = append(partitionList, query) } - requestInput.PartitionFields = partitionList + requestInput.PartitionFields = conversion.NonEmptySliceToPtrSlice(partitionList) } } @@ -568,13 +568,12 @@ func fromOnlineArchiveToMap(in *admin.BackupOnlineArchive) map[string]any { schemaVals["data_process_region"] = []any{dataProcessRegion} } - // partitions fields - if len(in.PartitionFields) == 0 { + partitionFields := conversion.SlicePtrToSlice(in.PartitionFields) + if len(partitionFields) == 0 { return schemaVals } - - partitionFieldsMap := make([]map[string]any, 0, len(in.PartitionFields)) - for _, field := range in.PartitionFields { + partitionFieldsMap := make([]map[string]any, 0, len(partitionFields)) + for _, field := range partitionFields { fieldMap := map[string]any{ "field_name": field.FieldName, "field_type": field.FieldType, diff --git a/internal/service/project/data_source_project_test.go b/internal/service/project/data_source_project_test.go index bb99a711fe..a51a1e4a6e 100644 --- a/internal/service/project/data_source_project_test.go +++ b/internal/service/project/data_source_project_test.go @@ -27,11 +27,11 @@ func TestAccProjectDSProject_byID(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, )), @@ -59,12 +59,12 @@ func TestAccProjectDSProject_byName(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, )), @@ -92,12 +92,12 @@ func TestAccProjectDSProject_defaultFlags(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, )), diff --git a/internal/service/project/data_source_projects.go b/internal/service/project/data_source_projects.go index 022af1dbdc..4aa49505f3 100644 --- a/internal/service/project/data_source_projects.go +++ b/internal/service/project/data_source_projects.go @@ -170,9 +170,10 @@ func (d *ProjectsDS) Read(ctx context.Context, req datasource.ReadRequest, resp } func populateProjectsDataSourceModel(ctx context.Context, connV2 *admin.APIClient, stateModel *tfProjectsDSModel, projectsRes *admin.PaginatedAtlasGroup) error { - results := make([]*TfProjectDSModel, 0, len(projectsRes.Results)) - for i := range projectsRes.Results { - project := projectsRes.Results[i] + input := conversion.SlicePtrToSlice(projectsRes.Results) + results := make([]*TfProjectDSModel, 0, len(input)) + for i := range input { + project := input[i] atlasTeams, atlasLimits, atlasProjectSettings, err := GetProjectPropsFromAPI(ctx, ServiceFromClient(connV2), project.GetId()) if err == nil { // if the project is still valid, e.g. could have just been deleted projectModel := NewTFProjectDataSourceModel(ctx, &project, atlasTeams, atlasProjectSettings, atlasLimits) diff --git a/internal/service/project/data_source_projects_test.go b/internal/service/project/data_source_projects_test.go index ccdbf4c66c..2bcc24eb27 100644 --- a/internal/service/project/data_source_projects_test.go +++ b/internal/service/project/data_source_projects_test.go @@ -27,11 +27,11 @@ func TestAccProjectDSProjects_basic(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, ), @@ -62,11 +62,11 @@ func TestAccProjectDSProjects_withPagination(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, 2, 5, diff --git a/internal/service/project/model_project.go b/internal/service/project/model_project.go index 1ee707d429..d4c4100e9c 100644 --- a/internal/service/project/model_project.go +++ b/internal/service/project/model_project.go @@ -32,11 +32,10 @@ func NewTFTeamsDataSourceModel(ctx context.Context, atlasTeams *admin.PaginatedT if atlasTeams.GetTotalCount() == 0 { return nil } - teams := make([]*TfTeamDSModel, len(atlasTeams.Results)) - - for i, atlasTeam := range atlasTeams.Results { + results := conversion.SlicePtrToSlice(atlasTeams.Results) + teams := make([]*TfTeamDSModel, len(results)) + for i, atlasTeam := range results { roleNames, _ := types.ListValueFrom(ctx, types.StringType, atlasTeam.RoleNames) - teams[i] = &TfTeamDSModel{ TeamID: types.StringValue(atlasTeam.GetTeamId()), RoleNames: roleNames, @@ -104,11 +103,10 @@ func newTFLimitsResourceModel(ctx context.Context, dataFederationLimits []admin. } func newTFTeamsResourceModel(ctx context.Context, atlasTeams *admin.PaginatedTeamRole) types.Set { - teams := make([]TfTeamModel, len(atlasTeams.Results)) - - for i, atlasTeam := range atlasTeams.Results { + results := conversion.SlicePtrToSlice(atlasTeams.Results) + teams := make([]TfTeamModel, len(results)) + for i, atlasTeam := range results { roleNames, _ := types.SetValueFrom(ctx, types.StringType, atlasTeam.RoleNames) - teams[i] = TfTeamModel{ TeamID: types.StringValue(atlasTeam.GetTeamId()), RoleNames: roleNames, @@ -125,7 +123,7 @@ func NewTeamRoleList(ctx context.Context, teams []TfTeamModel) *[]admin.TeamRole for i, team := range teams { res[i] = admin.TeamRole{ TeamId: team.TeamID.ValueStringPointer(), - RoleNames: conversion.TypesSetToString(ctx, team.RoleNames), + RoleNames: conversion.NonEmptySliceToPtrSlice(conversion.TypesSetToString(ctx, team.RoleNames)), } } return &res diff --git a/internal/service/project/model_project_test.go b/internal/service/project/model_project_test.go index 17887436c9..c6f736a0df 100644 --- a/internal/service/project/model_project_test.go +++ b/internal/service/project/model_project_test.go @@ -30,7 +30,7 @@ var ( teamRolesSDK = []admin.TeamRole{ { TeamId: conversion.StringPtr("teamId"), - RoleNames: roles, + RoleNames: conversion.NonEmptySliceToPtrSlice(roles), }, } teamsDSTF = []*project.TfTeamDSModel{ @@ -88,7 +88,7 @@ func TestTeamsDataSourceSDKToTFModel(t *testing.T) { { name: "Complete TeamRole", paginatedTeamRole: &admin.PaginatedTeamRole{ - Results: teamRolesSDK, + Results: conversion.NonEmptySliceToPtrSlice(teamRolesSDK), TotalCount: conversion.IntPtr(1), }, expectedTFModel: teamsDSTF, @@ -141,7 +141,7 @@ func TestProjectDataSourceSDKToTFModel(t *testing.T) { name: "Project", project: &projectSDK, teams: &admin.PaginatedTeamRole{ - Results: teamRolesSDK, + Results: conversion.NonEmptySliceToPtrSlice(teamRolesSDK), TotalCount: conversion.IntPtr(1), }, projectSettings: &projectSettingsSDK, diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index 4efab44a4f..541128d95a 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -675,7 +675,7 @@ func UpdateProjectTeams(ctx context.Context, client GroupProjectService, project _, _, err := client.UpdateTeamRoles(ctx, projectID, teamID, &admin.TeamRole{ - RoleNames: conversion.TypesSetToString(ctx, team.RoleNames), + RoleNames: conversion.NonEmptySliceToPtrSlice(conversion.TypesSetToString(ctx, team.RoleNames)), }, ) if err != nil { @@ -768,8 +768,9 @@ func ResourceProjectDependentsDeletingRefreshFunc(ctx context.Context, projectID return dependents, projectDependentsStateIdle, nil } - for i := range dependents.AdvancedClusters.Results { - if *dependents.AdvancedClusters.Results[i].StateName != projectDependentsStateDeleting { + results := conversion.SlicePtrToSlice(dependents.AdvancedClusters.Results) + for i := range results { + if *results[i].StateName != projectDependentsStateDeleting { return dependents, projectDependentsStateIdle, nil } } diff --git a/internal/service/project/resource_project_migration_test.go b/internal/service/project/resource_project_migration_test.go index 0760959aad..fddc639ed8 100644 --- a/internal/service/project/resource_project_migration_test.go +++ b/internal/service/project/resource_project_migration_test.go @@ -68,11 +68,11 @@ func TestAccMigrationProjectRS_Teams(t *testing.T) { []*admin.TeamRole{ { TeamId: &teamsIds[0], - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: &teamsIds[1], - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }) ) diff --git a/internal/service/project/resource_project_test.go b/internal/service/project/resource_project_test.go index b70c8439a6..4864953d4d 100644 --- a/internal/service/project/resource_project_test.go +++ b/internal/service/project/resource_project_test.go @@ -433,7 +433,7 @@ func TestResourceProjectDependentsDeletingRefreshFunc(t *testing.T) { mockResponses: AdvancedClusterDescriptionResponse{ AdvancedClusterDescription: &admin.PaginatedAdvancedClusterDescription{ TotalCount: conversion.IntPtr(2), - Results: []admin.AdvancedClusterDescription{ + Results: &[]admin.AdvancedClusterDescription{ {StateName: conversion.StringPtr("IDLE")}, {StateName: conversion.StringPtr("DELETING")}, }, @@ -477,11 +477,11 @@ func TestAccProjectRSProject_basic(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, ), @@ -499,15 +499,15 @@ func TestAccProjectRSProject_basic(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_OWNER"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_READ_WRITE"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_READ_WRITE"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(2)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, }, ), @@ -526,11 +526,11 @@ func TestAccProjectRSProject_basic(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_READ_ONLY"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_READ_ONLY"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_OWNER", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_OWNER", "GROUP_DATA_ACCESS_ADMIN"}, }, }, ), diff --git a/internal/service/searchdeployment/model_search_deployment.go b/internal/service/searchdeployment/model_search_deployment.go index 39a3696c90..e7567e8cb7 100644 --- a/internal/service/searchdeployment/model_search_deployment.go +++ b/internal/service/searchdeployment/model_search_deployment.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "go.mongodb.org/atlas-sdk/v20231115003/admin" ) @@ -22,7 +23,7 @@ func NewSearchDeploymentReq(ctx context.Context, searchDeploymentPlan *TFSearchD } return admin.ApiSearchDeploymentRequest{ - Specs: resultSpecs, + Specs: conversion.NonEmptySliceToPtrSlice(resultSpecs), } } @@ -38,7 +39,7 @@ func NewTFSearchDeployment(ctx context.Context, clusterName string, deployResp * result.Timeouts = *timeout } - specsList, diagnostics := types.ListValueFrom(ctx, SpecObjectType, newTFSpecsModel(deployResp.Specs)) + specsList, diagnostics := types.ListValueFrom(ctx, SpecObjectType, newTFSpecsModel(conversion.SlicePtrToSlice(deployResp.Specs))) if diagnostics.HasError() { return nil, diagnostics } diff --git a/internal/service/searchdeployment/model_search_deployment_test.go b/internal/service/searchdeployment/model_search_deployment_test.go index 3914d23768..d74d9db54d 100644 --- a/internal/service/searchdeployment/model_search_deployment_test.go +++ b/internal/service/searchdeployment/model_search_deployment_test.go @@ -36,7 +36,7 @@ func TestSearchDeploymentSDKToTFModel(t *testing.T) { Id: admin.PtrString(dummyDeploymentID), GroupId: admin.PtrString(dummyProjectID), StateName: admin.PtrString(stateName), - Specs: []admin.ApiSearchDeploymentSpec{ + Specs: &[]admin.ApiSearchDeploymentSpec{ { InstanceSize: instanceSize, NodeCount: nodeCount, @@ -84,7 +84,7 @@ func TestSearchDeploymentTFModelToSDK(t *testing.T) { Specs: tfSpecsList(t, instanceSize, nodeCount), }, expectedSDKReq: admin.ApiSearchDeploymentRequest{ - Specs: []admin.ApiSearchDeploymentSpec{ + Specs: &[]admin.ApiSearchDeploymentSpec{ { InstanceSize: instanceSize, NodeCount: nodeCount, diff --git a/internal/service/searchdeployment/state_transition_search_deployment_test.go b/internal/service/searchdeployment/state_transition_search_deployment_test.go index 96de1a075a..d074002102 100644 --- a/internal/service/searchdeployment/state_transition_search_deployment_test.go +++ b/internal/service/searchdeployment/state_transition_search_deployment_test.go @@ -140,7 +140,7 @@ func responseWithState(state *string) *admin.ApiSearchDeploymentResponse { return &admin.ApiSearchDeploymentResponse{ GroupId: admin.PtrString(dummyProjectID), Id: admin.PtrString(dummyDeploymentID), - Specs: []admin.ApiSearchDeploymentSpec{ + Specs: &[]admin.ApiSearchDeploymentSpec{ { InstanceSize: instanceSize, NodeCount: nodeCount, diff --git a/internal/service/searchindex/data_source_search_index.go b/internal/service/searchindex/data_source_search_index.go index 4a2ce89959..ee02bfcbb8 100644 --- a/internal/service/searchindex/data_source_search_index.go +++ b/internal/service/searchindex/data_source_search_index.go @@ -128,8 +128,8 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour return diag.Errorf("error setting `analyzer` for search index (%s): %s", d.Id(), err) } - if len(searchIndex.Analyzers) > 0 { - searchIndexMappingFields, err := marshalSearchIndex(searchIndex.Analyzers) + if analyzers := conversion.SlicePtrToSlice(searchIndex.Analyzers); len(analyzers) > 0 { + searchIndexMappingFields, err := marshalSearchIndex(analyzers) if err != nil { return diag.FromErr(err) } @@ -155,7 +155,7 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour return diag.Errorf("error setting `searchAnalyzer` for search index (%s): %s", d.Id(), err) } - if err := d.Set("synonyms", flattenSearchIndexSynonyms(searchIndex.Synonyms)); err != nil { + if err := d.Set("synonyms", flattenSearchIndexSynonyms(conversion.SlicePtrToSlice(searchIndex.Synonyms))); err != nil { return diag.Errorf("error setting `synonyms` for search index (%s): %s", d.Id(), err) } @@ -175,13 +175,13 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour } } - if len(searchIndex.Fields) > 0 { - fields, err := marshalSearchIndex(searchIndex.Fields) + if fields := conversion.SlicePtrToSlice(searchIndex.Fields); len(fields) > 0 { + fieldsMarshaled, err := marshalSearchIndex(fields) if err != nil { return diag.FromErr(err) } - if err := d.Set("fields", fields); err != nil { + if err := d.Set("fields", fieldsMarshaled); err != nil { return diag.Errorf("error setting `fields` for for search index (%s): %s", d.Id(), err) } } diff --git a/internal/service/searchindex/data_source_search_indexes.go b/internal/service/searchindex/data_source_search_indexes.go index 31675fbdc3..250d7adf02 100644 --- a/internal/service/searchindex/data_source_search_indexes.go +++ b/internal/service/searchindex/data_source_search_indexes.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20231115003/admin" ) @@ -111,7 +112,7 @@ func flattenSearchIndexes(searchIndexes []admin.ClusterSearchIndex, projectID, c "name": searchIndexes[i].Name, "search_analyzer": searchIndexes[i].SearchAnalyzer, "status": searchIndexes[i].Status, - "synonyms": flattenSearchIndexSynonyms(searchIndexes[i].Synonyms), + "synonyms": flattenSearchIndexSynonyms(conversion.SlicePtrToSlice(searchIndexes[i].Synonyms)), "type": searchIndexes[i].Type, } @@ -127,20 +128,20 @@ func flattenSearchIndexes(searchIndexes []admin.ClusterSearchIndex, projectID, c } } - if len(searchIndexes[i].Analyzers) > 0 { - searchIndexAnalyzers, err := marshalSearchIndex(searchIndexes[i].Analyzers) + if analyzers := conversion.SlicePtrToSlice(searchIndexes[i].Analyzers); len(analyzers) > 0 { + searchIndexAnalyzers, err := marshalSearchIndex(analyzers) if err != nil { return nil, err } searchIndexesMap[i]["analyzers"] = searchIndexAnalyzers } - if len(searchIndexes[i].Fields) > 0 { - fields, err := marshalSearchIndex(searchIndexes[i].Fields) + if fields := conversion.SlicePtrToSlice(searchIndexes[i].Fields); len(fields) > 0 { + fieldsMarshaled, err := marshalSearchIndex(fields) if err != nil { return nil, err } - searchIndexesMap[i]["fields"] = fields + searchIndexesMap[i]["fields"] = fieldsMarshaled } } diff --git a/internal/service/searchindex/resource_search_index.go b/internal/service/searchindex/resource_search_index.go index fe01df9dc9..cb79f9c976 100644 --- a/internal/service/searchindex/resource_search_index.go +++ b/internal/service/searchindex/resource_search_index.go @@ -224,7 +224,7 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndex.Analyzers = analyzers + searchIndex.Analyzers = conversion.NonEmptySliceToPtrSlice(analyzers) } if d.HasChange("mappings_dynamic") { @@ -251,11 +251,11 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndex.Fields = fields + searchIndex.Fields = conversion.NonEmptySliceToPtrSlice(fields) } if d.HasChange("synonyms") { - searchIndex.Synonyms = expandSearchIndexSynonyms(d) + searchIndex.Synonyms = conversion.NonEmptySliceToPtrSlice(expandSearchIndexSynonyms(d)) } searchIndex.IndexID = conversion.StringPtr("") @@ -320,8 +320,8 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource return diag.Errorf("error setting `analyzer` for search index (%s): %s", d.Id(), err) } - if len(searchIndex.Analyzers) > 0 { - searchIndexMappingFields, err := marshalSearchIndex(searchIndex.Analyzers) + if analyzers := conversion.SlicePtrToSlice(searchIndex.Analyzers); len(analyzers) > 0 { + searchIndexMappingFields, err := marshalSearchIndex(analyzers) if err != nil { return diag.FromErr(err) } @@ -347,7 +347,7 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource return diag.Errorf("error setting `searchAnalyzer` for search index (%s): %s", d.Id(), err) } - if err := d.Set("synonyms", flattenSearchIndexSynonyms(searchIndex.Synonyms)); err != nil { + if err := d.Set("synonyms", flattenSearchIndexSynonyms(conversion.SlicePtrToSlice(searchIndex.Synonyms))); err != nil { return diag.Errorf("error setting `synonyms` for search index (%s): %s", d.Id(), err) } @@ -368,8 +368,8 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource } } - if len(searchIndex.Fields) > 0 { - fields, err := marshalSearchIndex(searchIndex.Fields) + if fields := conversion.SlicePtrToSlice(searchIndex.Fields); len(fields) > 0 { + fields, err := marshalSearchIndex(fields) if err != nil { return diag.FromErr(err) } @@ -413,7 +413,7 @@ func resourceMongoDBAtlasSearchIndexCreate(ctx context.Context, d *schema.Resour Name: d.Get("name").(string), SearchAnalyzer: conversion.StringPtr(d.Get("search_analyzer").(string)), Status: conversion.StringPtr(d.Get("status").(string)), - Synonyms: expandSearchIndexSynonyms(d), + Synonyms: conversion.NonEmptySliceToPtrSlice(expandSearchIndexSynonyms(d)), } if indexType == vectorSearch { @@ -421,13 +421,13 @@ func resourceMongoDBAtlasSearchIndexCreate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndexRequest.Fields = fields + searchIndexRequest.Fields = conversion.NonEmptySliceToPtrSlice(fields) } else { analyzers, err := unmarshalSearchIndexAnalyzersFields(d.Get("analyzers").(string)) if err != nil { return err } - searchIndexRequest.Analyzers = analyzers + searchIndexRequest.Analyzers = conversion.NonEmptySliceToPtrSlice(analyzers) mappingsFields, err := unmarshalSearchIndexMappingFields(d.Get("mappings_fields").(string)) if err != nil { return err diff --git a/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go b/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go index a1d9b4c214..f43dbed500 100644 --- a/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go +++ b/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go @@ -97,7 +97,7 @@ func dataSourceMongoDBAtlasCloudSharedTierRestoreJobRead(ctx context.Context, d return diag.FromErr(fmt.Errorf("error getting shared tier restore jobs for cluster '%s': %w", clusterName, err)) } - if err := d.Set("results", flattenShardTierRestoreJobs(jobs.Results)); err != nil { + if err := d.Set("results", flattenShardTierRestoreJobs(conversion.SlicePtrToSlice(jobs.Results))); err != nil { return diag.FromErr(fmt.Errorf("error setting `results`: %w", err)) } diff --git a/internal/service/sharedtier/data_source_shared_tier_snapshots.go b/internal/service/sharedtier/data_source_shared_tier_snapshots.go index a75cbf16d0..e3f30a78d5 100644 --- a/internal/service/sharedtier/data_source_shared_tier_snapshots.go +++ b/internal/service/sharedtier/data_source_shared_tier_snapshots.go @@ -80,7 +80,7 @@ func dataSourceMongoDBAtlasSharedTierSnapshotsRead(ctx context.Context, d *schem return diag.FromErr(fmt.Errorf("error getting shard-tier snapshots for cluster '%s': %w", clusterName, err)) } - if err := d.Set("results", flattenSharedTierSnapshots(snapshots.Results)); err != nil { + if err := d.Set("results", flattenSharedTierSnapshots(conversion.SlicePtrToSlice(snapshots.Results))); err != nil { return diag.FromErr(fmt.Errorf("error setting `results`: %w", err)) } diff --git a/internal/service/streamconnection/model_stream_connection.go b/internal/service/streamconnection/model_stream_connection.go index b7aafee88b..72b035959a 100644 --- a/internal/service/streamconnection/model_stream_connection.go +++ b/internal/service/streamconnection/model_stream_connection.go @@ -122,11 +122,12 @@ func newTFConnectionAuthenticationModel(ctx context.Context, currAuthConfig *typ func NewTFStreamConnections(ctx context.Context, streamConnectionsConfig *TFStreamConnectionsDSModel, paginatedResult *admin.PaginatedApiStreamsConnection) (*TFStreamConnectionsDSModel, diag.Diagnostics) { - results := make([]TFStreamConnectionModel, len(paginatedResult.Results)) - for i := range paginatedResult.Results { + input := conversion.SlicePtrToSlice(paginatedResult.Results) + results := make([]TFStreamConnectionModel, len(input)) + for i := range input { projectID := streamConnectionsConfig.ProjectID.ValueString() instanceName := streamConnectionsConfig.InstanceName.ValueString() - connectionModel, diags := NewTFStreamConnection(ctx, projectID, instanceName, nil, &paginatedResult.Results[i]) + connectionModel, diags := NewTFStreamConnection(ctx, projectID, instanceName, nil, &input[i]) if diags.HasError() { return nil, diags } diff --git a/internal/service/streamconnection/model_stream_connection_test.go b/internal/service/streamconnection/model_stream_connection_test.go index 0ba584cda0..bc727ce58e 100644 --- a/internal/service/streamconnection/model_stream_connection_test.go +++ b/internal/service/streamconnection/model_stream_connection_test.go @@ -168,7 +168,7 @@ func TestStreamConnectionsSDKToTFModel(t *testing.T) { { name: "Complete SDK response with configured page options", SDKResp: &admin.PaginatedApiStreamsConnection{ - Results: []admin.StreamsConnection{ + Results: &[]admin.StreamsConnection{ { Name: admin.PtrString(connectionName), Type: admin.PtrString("Kafka"), @@ -232,7 +232,7 @@ func TestStreamConnectionsSDKToTFModel(t *testing.T) { { name: "Without defining page options", SDKResp: &admin.PaginatedApiStreamsConnection{ - Results: []admin.StreamsConnection{}, + Results: &[]admin.StreamsConnection{}, TotalCount: admin.PtrInt(0), }, providedConfig: &streamconnection.TFStreamConnectionsDSModel{ diff --git a/internal/service/streaminstance/model_stream_instance.go b/internal/service/streaminstance/model_stream_instance.go index d54f7e1de4..998fa30736 100644 --- a/internal/service/streaminstance/model_stream_instance.go +++ b/internal/service/streaminstance/model_stream_instance.go @@ -63,9 +63,10 @@ func NewTFStreamInstance(ctx context.Context, apiResp *admin.StreamsTenant) (*TF } func NewTFStreamInstances(ctx context.Context, streamInstancesConfig *TFStreamInstancesModel, paginatedResult *admin.PaginatedApiStreamsTenant) (*TFStreamInstancesModel, diag.Diagnostics) { - results := make([]TFStreamInstanceModel, len(paginatedResult.Results)) - for i := range paginatedResult.Results { - instance, diags := NewTFStreamInstance(ctx, &paginatedResult.Results[i]) + input := conversion.SlicePtrToSlice(paginatedResult.Results) + results := make([]TFStreamInstanceModel, len(input)) + for i := range input { + instance, diags := NewTFStreamInstance(ctx, &input[i]) if diags.HasError() { return nil, diags } diff --git a/internal/service/streaminstance/model_stream_instance_test.go b/internal/service/streaminstance/model_stream_instance_test.go index 98aa289d40..92532c38a2 100644 --- a/internal/service/streaminstance/model_stream_instance_test.go +++ b/internal/service/streaminstance/model_stream_instance_test.go @@ -18,7 +18,7 @@ const ( instanceName = "InstanceName" ) -var hostnames = []string{"atlas-stream.virginia-usa.a.query.mongodb-dev.net"} +var hostnames = &[]string{"atlas-stream.virginia-usa.a.query.mongodb-dev.net"} type sdkToTFModelTestCase struct { SDKResp *admin.StreamsTenant @@ -90,7 +90,7 @@ func TestStreamInstancesSDKToTFModel(t *testing.T) { { name: "Complete SDK response with configured page options", SDKResp: &admin.PaginatedApiStreamsTenant{ - Results: []admin.StreamsTenant{ + Results: &[]admin.StreamsTenant{ { Id: admin.PtrString(dummyStreamInstanceID), DataProcessRegion: &admin.StreamsDataProcessRegion{ @@ -128,7 +128,7 @@ func TestStreamInstancesSDKToTFModel(t *testing.T) { { name: "Without defining page options", SDKResp: &admin.PaginatedApiStreamsTenant{ - Results: []admin.StreamsTenant{}, + Results: &[]admin.StreamsTenant{}, TotalCount: admin.PtrInt(0), }, providedConfig: &streaminstance.TFStreamInstancesModel{ @@ -246,7 +246,7 @@ func tfRegionObject(t *testing.T, cloudProvider, region string) types.Object { return dataProcessRegion } -func tfHostnamesList(t *testing.T, hostnames []string) types.List { +func tfHostnamesList(t *testing.T, hostnames *[]string) types.List { t.Helper() resultList, diags := types.ListValueFrom(context.Background(), types.StringType, hostnames) if diags.HasError() { From 404512e24e8cb83cf3e46fcbe41a46a1e51a7f4c Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 12 Jan 2024 16:28:00 +0100 Subject: [PATCH 05/21] TEMPORARY - remove DataProcessRegion to make it compile and run tests --- .../onlinearchive/resource_online_archive.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index e189a6a69e..f5e2f1d909 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -466,15 +466,6 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso } } - if dataProcessRegionHasChange { - newDataProcessRegion := mapDataProcessRegion(d) - if newDataProcessRegion == nil { - request.DataProcessRegion = &admin.DataProcessRegion{} - } else { - request.DataProcessRegion = newDataProcessRegion - } - } - if scheduleHasChange { request.Schedule = mapSchedule(d) } @@ -559,15 +550,6 @@ func fromOnlineArchiveToMap(in *admin.BackupOnlineArchive) map[string]any { schemaVals["data_expiration_rule"] = []any{dataExpirationRule} } - var dataProcessRegion map[string]any - if in.DataProcessRegion != nil && (in.DataProcessRegion.CloudProvider != nil || in.DataProcessRegion.Region != nil) { - dataProcessRegion = map[string]any{ - "cloud_provider": in.DataProcessRegion.CloudProvider, - "region": in.DataProcessRegion.Region, - } - schemaVals["data_process_region"] = []any{dataProcessRegion} - } - partitionFields := conversion.SlicePtrToSlice(in.PartitionFields) if len(partitionFields) == 0 { return schemaVals From f93464f165c7fdfcdd0872976d0d4bd7a3ee48ce Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 12 Jan 2024 16:42:35 +0100 Subject: [PATCH 06/21] fix linter: fieldalignment: struct with 32 pointer bytes could be 24 (govet) --- .../searchdeployment/model_search_deployment_test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/service/searchdeployment/model_search_deployment_test.go b/internal/service/searchdeployment/model_search_deployment_test.go index d74d9db54d..626cf6bc8b 100644 --- a/internal/service/searchdeployment/model_search_deployment_test.go +++ b/internal/service/searchdeployment/model_search_deployment_test.go @@ -66,14 +66,12 @@ func TestSearchDeploymentSDKToTFModel(t *testing.T) { } } -type tfToSDKModelTestCase struct { - name string - tfModel *searchdeployment.TFSearchDeploymentRSModel - expectedSDKReq admin.ApiSearchDeploymentRequest -} - func TestSearchDeploymentTFModelToSDK(t *testing.T) { - testCases := []tfToSDKModelTestCase{ + testCases := []struct { + tfModel *searchdeployment.TFSearchDeploymentRSModel + expectedSDKReq admin.ApiSearchDeploymentRequest + name string + }{ { name: "Complete TF state", tfModel: &searchdeployment.TFSearchDeploymentRSModel{ From 5651c2bac0368b336a81683610a5f5f6b940adcf Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 12 Jan 2024 18:38:32 +0100 Subject: [PATCH 07/21] fix project tests --- internal/testutil/acc/project.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/testutil/acc/project.go b/internal/testutil/acc/project.go index c17ef8a112..55b539d0e0 100644 --- a/internal/testutil/acc/project.go +++ b/internal/testutil/acc/project.go @@ -72,7 +72,7 @@ func ConfigProject(projectName, orgID string, teams []*admin.TeamRole) string { team_id = "%s" role_names = %s } - `, t.GetTeamId(), strings.ReplaceAll(fmt.Sprintf("%+q", t.RoleNames), " ", ",")) + `, t.GetTeamId(), strings.ReplaceAll(fmt.Sprintf("%+q", *t.RoleNames), " ", ",")) } return fmt.Sprintf(` From d0d2d670bdfe25716679176cd2ae7bbdfc1640e1 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 12 Jan 2024 20:02:12 +0100 Subject: [PATCH 08/21] Revert "TEMPORARY - remove DataProcessRegion to make it compile and run tests" This reverts commit 404512e24e8cb83cf3e46fcbe41a46a1e51a7f4c. --- .../onlinearchive/resource_online_archive.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index f5e2f1d909..e189a6a69e 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -466,6 +466,15 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso } } + if dataProcessRegionHasChange { + newDataProcessRegion := mapDataProcessRegion(d) + if newDataProcessRegion == nil { + request.DataProcessRegion = &admin.DataProcessRegion{} + } else { + request.DataProcessRegion = newDataProcessRegion + } + } + if scheduleHasChange { request.Schedule = mapSchedule(d) } @@ -550,6 +559,15 @@ func fromOnlineArchiveToMap(in *admin.BackupOnlineArchive) map[string]any { schemaVals["data_expiration_rule"] = []any{dataExpirationRule} } + var dataProcessRegion map[string]any + if in.DataProcessRegion != nil && (in.DataProcessRegion.CloudProvider != nil || in.DataProcessRegion.Region != nil) { + dataProcessRegion = map[string]any{ + "cloud_provider": in.DataProcessRegion.CloudProvider, + "region": in.DataProcessRegion.Region, + } + schemaVals["data_process_region"] = []any{dataProcessRegion} + } + partitionFields := conversion.SlicePtrToSlice(in.PartitionFields) if len(partitionFields) == 0 { return schemaVals From 58abc5f87d4892f86588d32048a623bd33e98f9c Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 12 Jan 2024 20:14:18 +0100 Subject: [PATCH 09/21] user old SDK for online archive as DataProcessRegion was removed --- .../data_source_online_archive.go | 10 +-- .../onlinearchive/resource_online_archive.go | 74 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/internal/service/onlinearchive/data_source_online_archive.go b/internal/service/onlinearchive/data_source_online_archive.go index 60e5640f83..4ab5fb20c6 100644 --- a/internal/service/onlinearchive/data_source_online_archive.go +++ b/internal/service/onlinearchive/data_source_online_archive.go @@ -216,12 +216,12 @@ func schemaOnlineArchive() map[string]*schema.Schema { } func dataSourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 projectID := d.Get("project_id").(string) clusterName := d.Get("cluster_name").(string) archiveID := d.Get("archive_id").(string) - archive, _, err := connV2.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() + archive, _, err := connOldV2.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error reading Online Archive datasource with id %s: %s", archiveID, err.Error())) @@ -245,17 +245,17 @@ func dataSourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.Reso } func dataSourceMongoDBAtlasOnlineArchivesRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 projectID := d.Get("project_id").(string) clusterName := d.Get("cluster_name").(string) - archives, _, err := connV2.OnlineArchiveApi.ListOnlineArchives(ctx, projectID, clusterName).Execute() + archives, _, err := connOldV2.OnlineArchiveApi.ListOnlineArchives(ctx, projectID, clusterName).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error getting Online Archives list for project(%s) in cluster (%s): (%s)", projectID, clusterName, err.Error())) } - input := conversion.SlicePtrToSlice(archives.Results) + input := archives.Results results := make([]map[string]any, 0, len(input)) for i := range input { archiveData := fromOnlineArchiveToMap(&input[i]) diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index e189a6a69e..a7c522e511 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -9,6 +9,8 @@ import ( "strings" "time" + oldAdmin "go.mongodb.org/atlas-sdk/v20231001002/admin" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -16,7 +18,6 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mwielbut/pointy" - "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( @@ -218,13 +219,12 @@ func getMongoDBAtlasOnlineArchiveSchema() map[string]*schema.Schema { } func resourceMongoDBAtlasOnlineArchiveCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - // Get client connection - connV2 := meta.(*config.MongoDBClient).AtlasV2 + connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 projectID := d.Get("project_id").(string) clusterName := d.Get("cluster_name").(string) inputRequest := mapToArchivePayload(d) - outputRequest, _, err := connV2.OnlineArchiveApi.CreateOnlineArchive(ctx, projectID, clusterName, &inputRequest).Execute() + outputRequest, _, err := connOldV2.OnlineArchiveApi.CreateOnlineArchive(ctx, projectID, clusterName, &inputRequest).Execute() if err != nil { return diag.FromErr(fmt.Errorf(errorOnlineArchivesCreate, err)) @@ -242,7 +242,7 @@ func resourceMongoDBAtlasOnlineArchiveCreate(ctx context.Context, d *schema.Reso stateConf := &retry.StateChangeConf{ Pending: []string{"PENDING", "ARCHIVING", "PAUSING", "PAUSED", "ORPHANED", "REPEATING"}, Target: []string{"IDLE", "ACTIVE"}, - Refresh: resourceOnlineRefreshFunc(ctx, projectID, clusterName, archiveID, connV2), + Refresh: resourceOnlineRefreshFunc(ctx, projectID, clusterName, archiveID, connOldV2), Timeout: 3 * time.Hour, MinTimeout: 1 * time.Minute, Delay: 3 * time.Minute, @@ -258,7 +258,7 @@ func resourceMongoDBAtlasOnlineArchiveCreate(ctx context.Context, d *schema.Reso return resourceMongoDBAtlasOnlineArchiveRead(ctx, d, meta) } -func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, archiveID string, client *admin.APIClient) retry.StateRefreshFunc { +func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, archiveID string, client *oldAdmin.APIClient) retry.StateRefreshFunc { return func() (any, string, error) { c, resp, err := client.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() @@ -287,14 +287,14 @@ func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, arch } func resourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 ids := conversion.DecodeStateID(d.Id()) archiveID := ids["archive_id"] projectID := ids["project_id"] clusterName := ids["cluster_name"] - onlineArchive, resp, err := connV2.OnlineArchiveApi.GetOnlineArchive(context.Background(), projectID, archiveID, clusterName).Execute() + onlineArchive, resp, err := connOldV2.OnlineArchiveApi.GetOnlineArchive(context.Background(), projectID, archiveID, clusterName).Execute() if err != nil { if resp != nil && resp.StatusCode == http.StatusNotFound { d.SetId("") @@ -334,7 +334,7 @@ func resourceMongoDBAtlasOnlineArchiveDelete(ctx context.Context, d *schema.Reso } func resourceMongoDBAtlasOnlineArchiveImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 parts := strings.Split(d.Id(), "-") var projectID, clusterName, archiveID string @@ -351,7 +351,7 @@ func resourceMongoDBAtlasOnlineArchiveImportState(ctx context.Context, d *schema projectID, clusterName, archiveID = parts[0], parts[1], parts[2] } - outOnlineArchive, _, err := connV2.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() + outOnlineArchive, _, err := connOldV2.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() if err != nil { return nil, fmt.Errorf("could not import Online Archive %s in project %s, error %s", archiveID, projectID, err.Error()) @@ -378,9 +378,9 @@ func resourceMongoDBAtlasOnlineArchiveImportState(ctx context.Context, d *schema return []*schema.ResourceData{d}, nil } -func mapToArchivePayload(d *schema.ResourceData) admin.BackupOnlineArchiveCreate { +func mapToArchivePayload(d *schema.ResourceData) oldAdmin.BackupOnlineArchiveCreate { // shared input - requestInput := admin.BackupOnlineArchiveCreate{ + requestInput := oldAdmin.BackupOnlineArchiveCreate{ DbName: d.Get("db_name").(string), CollName: d.Get("coll_name").(string), } @@ -397,24 +397,24 @@ func mapToArchivePayload(d *schema.ResourceData) admin.BackupOnlineArchiveCreate list := partitions.([]any) if len(list) > 0 { - partitionList := make([]admin.PartitionField, 0, len(list)) + partitionList := make([]oldAdmin.PartitionField, 0, len(list)) for _, partition := range list { item := partition.(map[string]any) - query := admin.PartitionField{ + query := oldAdmin.PartitionField{ FieldName: item["field_name"].(string), Order: item["order"].(int), } if dbType, ok := item["field_type"]; ok && dbType != nil { if dbType.(string) != "" { - query.FieldType = admin.PtrString(dbType.(string)) + query.FieldType = oldAdmin.PtrString(dbType.(string)) } } partitionList = append(partitionList, query) } - requestInput.PartitionFields = conversion.NonEmptySliceToPtrSlice(partitionList) + requestInput.PartitionFields = partitionList } } @@ -422,7 +422,7 @@ func mapToArchivePayload(d *schema.ResourceData) admin.BackupOnlineArchiveCreate } func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 ids := conversion.DecodeStateID(d.Id()) @@ -444,7 +444,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso return nil } - request := admin.BackupOnlineArchive{} + request := oldAdmin.BackupOnlineArchive{} // reading current value if pausedHasChange { @@ -460,7 +460,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso newExpirationRule := mapDataExpirationRule(d) if newExpirationRule == nil { // expiration rule has been removed from tf config, empty dataExpirationRule object needs to be sent in patch request - request.DataExpirationRule = &admin.DataExpirationRule{} + request.DataExpirationRule = &oldAdmin.DataExpirationRule{} } else { request.DataExpirationRule = newExpirationRule } @@ -469,7 +469,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso if dataProcessRegionHasChange { newDataProcessRegion := mapDataProcessRegion(d) if newDataProcessRegion == nil { - request.DataProcessRegion = &admin.DataProcessRegion{} + request.DataProcessRegion = &oldAdmin.DataProcessRegion{} } else { request.DataProcessRegion = newDataProcessRegion } @@ -480,10 +480,10 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso } if collType := d.Get("collection_type").(string); collectionTypeHasChange && collType != "" { - request.CollectionType = admin.PtrString(collType) + request.CollectionType = oldAdmin.PtrString(collType) } - _, _, err := connV2.OnlineArchiveApi.UpdateOnlineArchive(ctx, projectID, atlasID, clusterName, &request).Execute() + _, _, err := connOldV2.OnlineArchiveApi.UpdateOnlineArchive(ctx, projectID, atlasID, clusterName, &request).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error updating Mongo Online Archive id: %s %s", atlasID, err.Error())) @@ -492,7 +492,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso return resourceMongoDBAtlasOnlineArchiveRead(ctx, d, meta) } -func fromOnlineArchiveToMap(in *admin.BackupOnlineArchive) map[string]any { +func fromOnlineArchiveToMap(in *oldAdmin.BackupOnlineArchive) map[string]any { // computed attribute schemaVals := map[string]any{ "cluster_name": in.ClusterName, @@ -568,7 +568,7 @@ func fromOnlineArchiveToMap(in *admin.BackupOnlineArchive) map[string]any { schemaVals["data_process_region"] = []any{dataProcessRegion} } - partitionFields := conversion.SlicePtrToSlice(in.PartitionFields) + partitionFields := in.PartitionFields if len(partitionFields) == 0 { return schemaVals } @@ -587,10 +587,10 @@ func fromOnlineArchiveToMap(in *admin.BackupOnlineArchive) map[string]any { return schemaVals } -func mapDataExpirationRule(d *schema.ResourceData) *admin.DataExpirationRule { +func mapDataExpirationRule(d *schema.ResourceData) *oldAdmin.DataExpirationRule { if dataExpireRules, ok := d.GetOk("data_expiration_rule"); ok && len(dataExpireRules.([]any)) > 0 { dataExpireRule := dataExpireRules.([]any)[0].(map[string]any) - result := admin.DataExpirationRule{} + result := oldAdmin.DataExpirationRule{} if expireAfterDays, ok := dataExpireRule["expire_after_days"]; ok { result.ExpireAfterDays = pointy.Int(expireAfterDays.(int)) } @@ -599,10 +599,10 @@ func mapDataExpirationRule(d *schema.ResourceData) *admin.DataExpirationRule { return nil } -func mapDataProcessRegion(d *schema.ResourceData) *admin.DataProcessRegion { +func mapDataProcessRegion(d *schema.ResourceData) *oldAdmin.DataProcessRegion { if dataProcessRegions, ok := d.GetOk("data_process_region"); ok && len(dataProcessRegions.([]any)) > 0 { dataProcessRegion := dataProcessRegions.([]any)[0].(map[string]any) - result := admin.DataProcessRegion{} + result := oldAdmin.DataProcessRegion{} if cloudProvider, ok := dataProcessRegion["cloud_provider"]; ok { result.CloudProvider = pointy.String(cloudProvider.(string)) } @@ -614,31 +614,31 @@ func mapDataProcessRegion(d *schema.ResourceData) *admin.DataProcessRegion { return nil } -func mapCriteria(d *schema.ResourceData) admin.Criteria { +func mapCriteria(d *schema.ResourceData) oldAdmin.Criteria { criteriaList := d.Get("criteria").([]any) criteria := criteriaList[0].(map[string]any) - criteriaInput := admin.Criteria{ - Type: admin.PtrString(criteria["type"].(string)), + criteriaInput := oldAdmin.Criteria{ + Type: oldAdmin.PtrString(criteria["type"].(string)), } if criteriaInput.Type != nil && *criteriaInput.Type == "DATE" { if dateField := criteria["date_field"].(string); dateField != "" { - criteriaInput.DateField = admin.PtrString(dateField) + criteriaInput.DateField = oldAdmin.PtrString(dateField) } criteriaInput.ExpireAfterDays = pointy.Int(criteria["expire_after_days"].(int)) // optional if dformat, ok := criteria["date_format"]; ok && dformat.(string) != "" { - criteriaInput.DateFormat = admin.PtrString(dformat.(string)) + criteriaInput.DateFormat = oldAdmin.PtrString(dformat.(string)) } } if criteriaInput.Type != nil && *criteriaInput.Type == "CUSTOM" { if query := criteria["query"].(string); query != "" { - criteriaInput.Query = admin.PtrString(query) + criteriaInput.Query = oldAdmin.PtrString(query) } } @@ -646,11 +646,11 @@ func mapCriteria(d *schema.ResourceData) admin.Criteria { return criteriaInput } -func mapSchedule(d *schema.ResourceData) *admin.OnlineArchiveSchedule { +func mapSchedule(d *schema.ResourceData) *oldAdmin.OnlineArchiveSchedule { // scheduleInput := &matlas.OnlineArchiveSchedule{ // We have to provide schedule.type="DEFAULT" when the schedule block is not provided or removed - scheduleInput := &admin.OnlineArchiveSchedule{ + scheduleInput := &oldAdmin.OnlineArchiveSchedule{ Type: scheduleTypeDefault, } @@ -669,7 +669,7 @@ func mapSchedule(d *schema.ResourceData) *admin.OnlineArchiveSchedule { } scheduleTFConfig := scheduleTFConfigList[0].(map[string]any) - scheduleInput = &admin.OnlineArchiveSchedule{ + scheduleInput = &oldAdmin.OnlineArchiveSchedule{ Type: scheduleTFConfig["type"].(string), } From 06cc66ed22b849719bd0dcde4b906967b44784aa Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 08:19:48 +0100 Subject: [PATCH 10/21] update templates --- tools/scaffold/template/model.tmpl | 2 +- tools/scaffold/template/model_test.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/scaffold/template/model.tmpl b/tools/scaffold/template/model.tmpl index e3b6d2aa12..067365ef41 100644 --- a/tools/scaffold/template/model.tmpl +++ b/tools/scaffold/template/model.tmpl @@ -4,7 +4,7 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/diag" - // "go.mongodb.org/atlas-sdk/v20231115002/admin" use latest version + // "go.mongodb.org/atlas-sdk/v20231115003/admin" use latest version ) // TODO: `ctx` parameter and `diags` return value can be removed if tf schema has no complex data types (e.g., schema.ListAttribute, schema.SetAttribute) diff --git a/tools/scaffold/template/model_test.tmpl b/tools/scaffold/template/model_test.tmpl index e7ad41f3df..cc359058f7 100644 --- a/tools/scaffold/template/model_test.tmpl +++ b/tools/scaffold/template/model_test.tmpl @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/{{.NameLowerNoSpaces}}" - // "go.mongodb.org/atlas-sdk/v20231115002/admin" use latest version + // "go.mongodb.org/atlas-sdk/v20231115003/admin" use latest version ) type sdkToTFModelTestCase struct { From 1d0f3faadf2db612c227faf0d46a087861380571 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 08:24:34 +0100 Subject: [PATCH 11/21] rename to NonEmptySliceToSlicePtr --- internal/common/conversion/type_conversion.go | 2 +- .../model_alert_configuration.go | 2 +- .../model_alert_configuration_test.go | 4 ++-- .../resource_alert_configuration.go | 8 ++++---- .../service/databaseuser/model_database_user.go | 6 +++--- .../resource_federated_database_instance.go | 14 +++++++------- ...esource_federated_settings_identity_provider.go | 2 +- internal/service/project/model_project.go | 2 +- internal/service/project/model_project_test.go | 6 +++--- internal/service/project/resource_project.go | 2 +- .../searchdeployment/model_search_deployment.go | 2 +- .../service/searchindex/resource_search_index.go | 12 ++++++------ 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/internal/common/conversion/type_conversion.go b/internal/common/conversion/type_conversion.go index cbc1f17f75..d3556db5f5 100644 --- a/internal/common/conversion/type_conversion.go +++ b/internal/common/conversion/type_conversion.go @@ -64,7 +64,7 @@ func SlicePtrToSlice[T any](v *[]T) []T { return *v } -func NonEmptySliceToPtrSlice[T any](v []T) *[]T { +func NonEmptySliceToSlicePtr[T any](v []T) *[]T { if len(v) == 0 { return nil } diff --git a/internal/service/alertconfiguration/model_alert_configuration.go b/internal/service/alertconfiguration/model_alert_configuration.go index 9e03779127..66da61f5d8 100644 --- a/internal/service/alertconfiguration/model_alert_configuration.go +++ b/internal/service/alertconfiguration/model_alert_configuration.go @@ -43,7 +43,7 @@ func NewNotificationList(tfNotificationSlice []TfNotificationModel) ([]admin.Ale Username: n.Username.ValueStringPointer(), VictorOpsApiKey: n.VictorOpsAPIKey.ValueStringPointer(), VictorOpsRoutingKey: n.VictorOpsRoutingKey.ValueStringPointer(), - Roles: conversion.NonEmptySliceToPtrSlice(n.Roles), + Roles: conversion.NonEmptySliceToSlicePtr(n.Roles), MicrosoftTeamsWebhookUrl: n.MicrosoftTeamsWebhookURL.ValueStringPointer(), WebhookSecret: n.WebhookSecret.ValueStringPointer(), WebhookUrl: n.WebhookURL.ValueStringPointer(), diff --git a/internal/service/alertconfiguration/model_alert_configuration_test.go b/internal/service/alertconfiguration/model_alert_configuration_test.go index bfcb295d12..48f073156e 100644 --- a/internal/service/alertconfiguration/model_alert_configuration_test.go +++ b/internal/service/alertconfiguration/model_alert_configuration_test.go @@ -45,7 +45,7 @@ func TestNotificationSDKToTFModel(t *testing.T) { SmsEnabled: admin.PtrBool(disabled), EmailEnabled: admin.PtrBool(enabled), ChannelName: admin.PtrString("#channel"), - Roles: conversion.NonEmptySliceToPtrSlice(roles), + Roles: conversion.NonEmptySliceToSlicePtr(roles), ApiToken: admin.PtrString("newApiToken"), }, }, @@ -290,7 +290,7 @@ func TestNotificationTFModelToSDK(t *testing.T) { DelayMin: admin.PtrInt(delayMin), SmsEnabled: admin.PtrBool(disabled), EmailEnabled: admin.PtrBool(enabled), - Roles: conversion.NonEmptySliceToPtrSlice(roles), + Roles: conversion.NonEmptySliceToSlicePtr(roles), }, }, }, diff --git a/internal/service/alertconfiguration/resource_alert_configuration.go b/internal/service/alertconfiguration/resource_alert_configuration.go index b48828b4ef..cfed0a47ab 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration.go +++ b/internal/service/alertconfiguration/resource_alert_configuration.go @@ -380,7 +380,7 @@ func (r *alertConfigurationRS) Create(ctx context.Context, req resource.CreateRe apiReq := &admin.GroupAlertsConfig{ EventTypeName: alertConfigPlan.EventType.ValueStringPointer(), Enabled: alertConfigPlan.Enabled.ValueBoolPointer(), - Matchers: conversion.NonEmptySliceToPtrSlice(NewMatcherList(alertConfigPlan.Matcher)), + Matchers: conversion.NonEmptySliceToSlicePtr(NewMatcherList(alertConfigPlan.Matcher)), MetricThreshold: NewMetricThreshold(alertConfigPlan.MetricThresholdConfig), Threshold: NewThreshold(alertConfigPlan.ThresholdConfig), } @@ -390,7 +390,7 @@ func (r *alertConfigurationRS) Create(ctx context.Context, req resource.CreateRe resp.Diagnostics.AddError(errorCreateAlertConf, err.Error()) return } - apiReq.Notifications = conversion.NonEmptySliceToPtrSlice(notifications) + apiReq.Notifications = conversion.NonEmptySliceToSlicePtr(notifications) apiResp, _, err := connV2.AlertConfigurationsApi.CreateAlertConfiguration(ctx, projectID, apiReq).Execute() if err != nil { @@ -482,7 +482,7 @@ func (r *alertConfigurationRS) Update(ctx context.Context, req resource.UpdateRe } if !reflect.DeepEqual(alertConfigPlan.Matcher, alertConfigState.Matcher) { - apiReq.Matchers = conversion.NonEmptySliceToPtrSlice(NewMatcherList(alertConfigPlan.Matcher)) + apiReq.Matchers = conversion.NonEmptySliceToSlicePtr(NewMatcherList(alertConfigPlan.Matcher)) } // Always refresh structure to handle service keys being obfuscated coming back from read API call @@ -491,7 +491,7 @@ func (r *alertConfigurationRS) Update(ctx context.Context, req resource.UpdateRe resp.Diagnostics.AddError(errorUpdateAlertConf, err.Error()) return } - apiReq.Notifications = conversion.NonEmptySliceToPtrSlice(notifications) + apiReq.Notifications = conversion.NonEmptySliceToSlicePtr(notifications) var updatedAlertConfigResp *admin.GroupAlertsConfig diff --git a/internal/service/databaseuser/model_database_user.go b/internal/service/databaseuser/model_database_user.go index b86f7e9169..fc28ca63d8 100644 --- a/internal/service/databaseuser/model_database_user.go +++ b/internal/service/databaseuser/model_database_user.go @@ -40,9 +40,9 @@ func NewMongoDBDatabaseUser(ctx context.Context, dbUserModel *TfDatabaseUserMode OidcAuthType: dbUserModel.OIDCAuthType.ValueStringPointer(), LdapAuthType: dbUserModel.LDAPAuthType.ValueStringPointer(), DatabaseName: dbUserModel.AuthDatabaseName.ValueString(), - Roles: conversion.NonEmptySliceToPtrSlice(NewMongoDBAtlasRoles(rolesModel)), - Labels: conversion.NonEmptySliceToPtrSlice(NewMongoDBAtlasLabels(labelsModel)), - Scopes: conversion.NonEmptySliceToPtrSlice(NewMongoDBAtlasScopes(scopesModel)), + Roles: conversion.NonEmptySliceToSlicePtr(NewMongoDBAtlasRoles(rolesModel)), + Labels: conversion.NonEmptySliceToSlicePtr(NewMongoDBAtlasLabels(labelsModel)), + Scopes: conversion.NonEmptySliceToSlicePtr(NewMongoDBAtlasScopes(scopesModel)), }, nil } diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index a53cf8b5d6..1205e1acc1 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -528,8 +528,8 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex func newDataFederationStorage(d *schema.ResourceData) *admin.DataLakeStorage { return &admin.DataLakeStorage{ - Databases: conversion.NonEmptySliceToPtrSlice(newDataFederationDatabase(d)), - Stores: conversion.NonEmptySliceToPtrSlice(newStores(d)), + Databases: conversion.NonEmptySliceToSlicePtr(newDataFederationDatabase(d)), + Stores: conversion.NonEmptySliceToSlicePtr(newStores(d)), } } @@ -552,7 +552,7 @@ func newStores(d *schema.ResourceData) []admin.DataLakeStoreSettings { Prefix: conversion.StringPtr(storeFromConfMap["prefix"].(string)), Delimiter: conversion.StringPtr(storeFromConfMap["delimiter"].(string)), IncludeTags: conversion.Pointer(storeFromConfMap["include_tags"].(bool)), - AdditionalStorageClasses: conversion.NonEmptySliceToPtrSlice(newAdditionalStorageClasses(storeFromConfMap["additional_storage_classes"].([]any))), + AdditionalStorageClasses: conversion.NonEmptySliceToSlicePtr(newAdditionalStorageClasses(storeFromConfMap["additional_storage_classes"].([]any))), ReadPreference: newReadPreference(storeFromConfMap), } } @@ -582,7 +582,7 @@ func newReadPreference(storeFromConfMap map[string]any) *admin.DataLakeAtlasStor return &admin.DataLakeAtlasStoreReadPreference{ Mode: conversion.StringPtr(readPreferenceFromConfMap["mode"].(string)), MaxStalenessSeconds: conversion.IntPtr(readPreferenceFromConfMap["max_staleness_seconds"].(int)), - TagSets: conversion.NonEmptySliceToPtrSlice(newTagSets(readPreferenceFromConfMap)), + TagSets: conversion.NonEmptySliceToSlicePtr(newTagSets(readPreferenceFromConfMap)), } } @@ -626,7 +626,7 @@ func newDataFederationDatabase(d *schema.ResourceData) []admin.DataLakeDatabaseI dbs[i] = admin.DataLakeDatabaseInstance{ Name: conversion.StringPtr(storageDBFromConfMap["name"].(string)), MaxWildcardCollections: conversion.IntPtr(storageDBFromConfMap["max_wildcard_collections"].(int)), - Collections: conversion.NonEmptySliceToPtrSlice(newDataFederationCollections(storageDBFromConfMap)), + Collections: conversion.NonEmptySliceToSlicePtr(newDataFederationCollections(storageDBFromConfMap)), } } @@ -643,7 +643,7 @@ func newDataFederationCollections(storageDBFromConfMap map[string]any) []admin.D for i, collectionFromConf := range collectionsFromConf { collections[i] = admin.DataLakeDatabaseCollection{ Name: conversion.StringPtr(collectionFromConf.(map[string]any)["name"].(string)), - DataSources: conversion.NonEmptySliceToPtrSlice(newDataFederationDataSource(collectionFromConf.(map[string]any))), + DataSources: conversion.NonEmptySliceToSlicePtr(newDataFederationDataSource(collectionFromConf.(map[string]any))), } } @@ -670,7 +670,7 @@ func newDataFederationDataSource(collectionFromConf map[string]any) []admin.Data ProvenanceFieldName: conversion.StringPtr(dataSourceFromConfMap["provenance_field_name"].(string)), StoreName: conversion.StringPtr(dataSourceFromConfMap["store_name"].(string)), DatasetName: conversion.StringPtr(dataSourceFromConfMap["dataset_name"].(string)), - Urls: conversion.NonEmptySliceToPtrSlice(newUrls(dataSourceFromConfMap["urls"].([]any))), + Urls: conversion.NonEmptySliceToSlicePtr(newUrls(dataSourceFromConfMap["urls"].([]any))), } } diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index aec5af4c51..341a335d98 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -237,7 +237,7 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderUpdate(ctx context.Con if d.HasChange("associated_domains") { associatedDomains := d.Get("associated_domains") - updateRequest.AssociatedDomains = conversion.NonEmptySliceToPtrSlice(cast.ToStringSlice(associatedDomains)) + updateRequest.AssociatedDomains = conversion.NonEmptySliceToSlicePtr(cast.ToStringSlice(associatedDomains)) } if d.HasChange("name") { diff --git a/internal/service/project/model_project.go b/internal/service/project/model_project.go index d4c4100e9c..a2f16b9ae8 100644 --- a/internal/service/project/model_project.go +++ b/internal/service/project/model_project.go @@ -123,7 +123,7 @@ func NewTeamRoleList(ctx context.Context, teams []TfTeamModel) *[]admin.TeamRole for i, team := range teams { res[i] = admin.TeamRole{ TeamId: team.TeamID.ValueStringPointer(), - RoleNames: conversion.NonEmptySliceToPtrSlice(conversion.TypesSetToString(ctx, team.RoleNames)), + RoleNames: conversion.NonEmptySliceToSlicePtr(conversion.TypesSetToString(ctx, team.RoleNames)), } } return &res diff --git a/internal/service/project/model_project_test.go b/internal/service/project/model_project_test.go index c6f736a0df..3488b9f5c0 100644 --- a/internal/service/project/model_project_test.go +++ b/internal/service/project/model_project_test.go @@ -30,7 +30,7 @@ var ( teamRolesSDK = []admin.TeamRole{ { TeamId: conversion.StringPtr("teamId"), - RoleNames: conversion.NonEmptySliceToPtrSlice(roles), + RoleNames: conversion.NonEmptySliceToSlicePtr(roles), }, } teamsDSTF = []*project.TfTeamDSModel{ @@ -88,7 +88,7 @@ func TestTeamsDataSourceSDKToTFModel(t *testing.T) { { name: "Complete TeamRole", paginatedTeamRole: &admin.PaginatedTeamRole{ - Results: conversion.NonEmptySliceToPtrSlice(teamRolesSDK), + Results: conversion.NonEmptySliceToSlicePtr(teamRolesSDK), TotalCount: conversion.IntPtr(1), }, expectedTFModel: teamsDSTF, @@ -141,7 +141,7 @@ func TestProjectDataSourceSDKToTFModel(t *testing.T) { name: "Project", project: &projectSDK, teams: &admin.PaginatedTeamRole{ - Results: conversion.NonEmptySliceToPtrSlice(teamRolesSDK), + Results: conversion.NonEmptySliceToSlicePtr(teamRolesSDK), TotalCount: conversion.IntPtr(1), }, projectSettings: &projectSettingsSDK, diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index 541128d95a..1ba53a285f 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -675,7 +675,7 @@ func UpdateProjectTeams(ctx context.Context, client GroupProjectService, project _, _, err := client.UpdateTeamRoles(ctx, projectID, teamID, &admin.TeamRole{ - RoleNames: conversion.NonEmptySliceToPtrSlice(conversion.TypesSetToString(ctx, team.RoleNames)), + RoleNames: conversion.NonEmptySliceToSlicePtr(conversion.TypesSetToString(ctx, team.RoleNames)), }, ) if err != nil { diff --git a/internal/service/searchdeployment/model_search_deployment.go b/internal/service/searchdeployment/model_search_deployment.go index e7567e8cb7..e4543500a2 100644 --- a/internal/service/searchdeployment/model_search_deployment.go +++ b/internal/service/searchdeployment/model_search_deployment.go @@ -23,7 +23,7 @@ func NewSearchDeploymentReq(ctx context.Context, searchDeploymentPlan *TFSearchD } return admin.ApiSearchDeploymentRequest{ - Specs: conversion.NonEmptySliceToPtrSlice(resultSpecs), + Specs: conversion.NonEmptySliceToSlicePtr(resultSpecs), } } diff --git a/internal/service/searchindex/resource_search_index.go b/internal/service/searchindex/resource_search_index.go index cb79f9c976..e77729361e 100644 --- a/internal/service/searchindex/resource_search_index.go +++ b/internal/service/searchindex/resource_search_index.go @@ -224,7 +224,7 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndex.Analyzers = conversion.NonEmptySliceToPtrSlice(analyzers) + searchIndex.Analyzers = conversion.NonEmptySliceToSlicePtr(analyzers) } if d.HasChange("mappings_dynamic") { @@ -251,11 +251,11 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndex.Fields = conversion.NonEmptySliceToPtrSlice(fields) + searchIndex.Fields = conversion.NonEmptySliceToSlicePtr(fields) } if d.HasChange("synonyms") { - searchIndex.Synonyms = conversion.NonEmptySliceToPtrSlice(expandSearchIndexSynonyms(d)) + searchIndex.Synonyms = conversion.NonEmptySliceToSlicePtr(expandSearchIndexSynonyms(d)) } searchIndex.IndexID = conversion.StringPtr("") @@ -413,7 +413,7 @@ func resourceMongoDBAtlasSearchIndexCreate(ctx context.Context, d *schema.Resour Name: d.Get("name").(string), SearchAnalyzer: conversion.StringPtr(d.Get("search_analyzer").(string)), Status: conversion.StringPtr(d.Get("status").(string)), - Synonyms: conversion.NonEmptySliceToPtrSlice(expandSearchIndexSynonyms(d)), + Synonyms: conversion.NonEmptySliceToSlicePtr(expandSearchIndexSynonyms(d)), } if indexType == vectorSearch { @@ -421,13 +421,13 @@ func resourceMongoDBAtlasSearchIndexCreate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndexRequest.Fields = conversion.NonEmptySliceToPtrSlice(fields) + searchIndexRequest.Fields = conversion.NonEmptySliceToSlicePtr(fields) } else { analyzers, err := unmarshalSearchIndexAnalyzersFields(d.Get("analyzers").(string)) if err != nil { return err } - searchIndexRequest.Analyzers = conversion.NonEmptySliceToPtrSlice(analyzers) + searchIndexRequest.Analyzers = conversion.NonEmptySliceToSlicePtr(analyzers) mappingsFields, err := unmarshalSearchIndexMappingFields(d.Get("mappings_fields").(string)) if err != nil { return err From 879a09bca63d2f26e41684c88f29a8cd58875c19 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 10:14:39 +0100 Subject: [PATCH 12/21] tests for slice functions --- .../common/conversion/type_conversion_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/common/conversion/type_conversion_test.go b/internal/common/conversion/type_conversion_test.go index cb0cfa0995..ea92411037 100644 --- a/internal/common/conversion/type_conversion_test.go +++ b/internal/common/conversion/type_conversion_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/stretchr/testify/assert" ) func TestTimeToStringWithoutNanos(t *testing.T) { @@ -67,3 +68,31 @@ func TestMongoDBRegionToAWSRegion(t *testing.T) { } } } + +func TestSlice_SameBehavior(t *testing.T) { + tests := []struct { + ptr *[]string + slice []string + }{ + {nil, nil}, + {&[]string{"hello", "there"}, []string{"hello", "there"}}, + } + for _, test := range tests { + assert.Equal(t, test.slice, conversion.SlicePtrToSlice(test.ptr)) + assert.Equal(t, test.ptr, conversion.NonEmptySliceToSlicePtr(test.slice)) + } +} + +func TestSlice_DifferentBehavior(t *testing.T) { + var ( + nilSlice []string + emptyNonNilSlice = []string{} + ) + assert.Nil(t, conversion.SlicePtrToSlice(&nilSlice)) + assert.NotEqual(t, &nilSlice, conversion.NonEmptySliceToSlicePtr[string](nil)) + assert.Nil(t, conversion.NonEmptySliceToSlicePtr[string](nil)) + + assert.Equal(t, emptyNonNilSlice, conversion.SlicePtrToSlice(&emptyNonNilSlice)) + assert.NotNil(t, conversion.SlicePtrToSlice(&emptyNonNilSlice)) + assert.Nil(t, conversion.NonEmptySliceToSlicePtr(emptyNonNilSlice)) +} From 0ab1d20584700953aca150d7f4480fc642179606 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:11:02 +0100 Subject: [PATCH 13/21] use Run in tests --- internal/common/conversion/type_conversion_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/common/conversion/type_conversion_test.go b/internal/common/conversion/type_conversion_test.go index ea92411037..c348de8f78 100644 --- a/internal/common/conversion/type_conversion_test.go +++ b/internal/common/conversion/type_conversion_test.go @@ -71,15 +71,18 @@ func TestMongoDBRegionToAWSRegion(t *testing.T) { func TestSlice_SameBehavior(t *testing.T) { tests := []struct { + name string ptr *[]string slice []string }{ - {nil, nil}, - {&[]string{"hello", "there"}, []string{"hello", "there"}}, + {"nil pointer and slice", nil, nil}, + {"slice with content", &[]string{"hello", "there"}, []string{"hello", "there"}}, } - for _, test := range tests { - assert.Equal(t, test.slice, conversion.SlicePtrToSlice(test.ptr)) - assert.Equal(t, test.ptr, conversion.NonEmptySliceToSlicePtr(test.slice)) + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + assert.Equal(t, tc.slice, conversion.SlicePtrToSlice(tc.ptr)) + assert.Equal(t, tc.ptr, conversion.NonEmptySliceToSlicePtr(tc.slice)) + }) } } From 63671e72813bb6527254d6330155388178fdec05 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 12:18:45 +0100 Subject: [PATCH 14/21] remove SlicePtrToSlice --- internal/common/conversion/type_conversion.go | 7 ---- .../common/conversion/type_conversion_test.go | 33 +++++++------------ .../data_source_alert_configuration.go | 6 ++-- .../data_source_alert_configurations.go | 2 +- .../model_alert_configuration.go | 12 +++---- .../atlasuser/data_source_atlas_user.go | 6 ++-- .../atlasuser/data_source_atlas_users.go | 6 ++-- .../databaseuser/model_database_user.go | 12 +++---- ...data_source_federated_database_instance.go | 4 +-- ...ata_source_federated_database_instances.go | 5 ++- .../resource_federated_database_instance.go | 12 +++---- ...ce_federated_settings_identity_provider.go | 2 +- ...el_federated_settings_identity_provider.go | 12 +++---- .../service/project/data_source_projects.go | 2 +- internal/service/project/model_project.go | 4 +-- internal/service/project/resource_project.go | 2 +- .../model_search_deployment.go | 2 +- .../searchindex/data_source_search_index.go | 6 ++-- .../searchindex/data_source_search_indexes.go | 7 ++-- .../searchindex/resource_search_index.go | 6 ++-- ...a_source_cloud_shared_tier_restore_jobs.go | 2 +- .../data_source_shared_tier_snapshots.go | 2 +- .../model_stream_connection.go | 2 +- .../streaminstance/model_stream_instance.go | 2 +- 24 files changed, 69 insertions(+), 87 deletions(-) diff --git a/internal/common/conversion/type_conversion.go b/internal/common/conversion/type_conversion.go index d3556db5f5..391bca807d 100644 --- a/internal/common/conversion/type_conversion.go +++ b/internal/common/conversion/type_conversion.go @@ -57,13 +57,6 @@ func MongoDBRegionToAWSRegion(region string) string { return strings.ReplaceAll(strings.ToLower(region), "_", "-") } -func SlicePtrToSlice[T any](v *[]T) []T { - if v == nil { - return nil - } - return *v -} - func NonEmptySliceToSlicePtr[T any](v []T) *[]T { if len(v) == 0 { return nil diff --git a/internal/common/conversion/type_conversion_test.go b/internal/common/conversion/type_conversion_test.go index c348de8f78..c789c575b7 100644 --- a/internal/common/conversion/type_conversion_test.go +++ b/internal/common/conversion/type_conversion_test.go @@ -69,33 +69,24 @@ func TestMongoDBRegionToAWSRegion(t *testing.T) { } } -func TestSlice_SameBehavior(t *testing.T) { +func TestNonEmptySliceToSlicePtr(t *testing.T) { + var ( + nilSlice []string + emptyNonNilSlice = []string{} + ) tests := []struct { - name string - ptr *[]string - slice []string + name string + expected *[]string + given []string }{ - {"nil pointer and slice", nil, nil}, + {"nil pointer", nil, nil}, + {"nil slice", nil, nilSlice}, + {"empty non-nil slice", nil, emptyNonNilSlice}, {"slice with content", &[]string{"hello", "there"}, []string{"hello", "there"}}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - assert.Equal(t, tc.slice, conversion.SlicePtrToSlice(tc.ptr)) - assert.Equal(t, tc.ptr, conversion.NonEmptySliceToSlicePtr(tc.slice)) + assert.Equal(t, tc.expected, conversion.NonEmptySliceToSlicePtr(tc.given)) }) } } - -func TestSlice_DifferentBehavior(t *testing.T) { - var ( - nilSlice []string - emptyNonNilSlice = []string{} - ) - assert.Nil(t, conversion.SlicePtrToSlice(&nilSlice)) - assert.NotEqual(t, &nilSlice, conversion.NonEmptySliceToSlicePtr[string](nil)) - assert.Nil(t, conversion.NonEmptySliceToSlicePtr[string](nil)) - - assert.Equal(t, emptyNonNilSlice, conversion.SlicePtrToSlice(&emptyNonNilSlice)) - assert.NotNil(t, conversion.SlicePtrToSlice(&emptyNonNilSlice)) - assert.Nil(t, conversion.NonEmptySliceToSlicePtr(emptyNonNilSlice)) -} diff --git a/internal/service/alertconfiguration/data_source_alert_configuration.go b/internal/service/alertconfiguration/data_source_alert_configuration.go index 33e6fa77ba..5ac631fc52 100644 --- a/internal/service/alertconfiguration/data_source_alert_configuration.go +++ b/internal/service/alertconfiguration/data_source_alert_configuration.go @@ -319,7 +319,7 @@ func outputAlertConfigurationResourceHcl(label string, alert *admin.GroupAlertsC resource.SetAttributeValue("enabled", cty.BoolVal(*alert.Enabled)) } - for _, matcher := range conversion.SlicePtrToSlice(alert.Matchers) { + for _, matcher := range alert.GetMatchers() { appendBlockWithCtyValues(resource, "matcher", []string{}, convertMatcherToCtyValues(matcher)) } @@ -331,7 +331,7 @@ func outputAlertConfigurationResourceHcl(label string, alert *admin.GroupAlertsC appendBlockWithCtyValues(resource, "threshold_config", []string{}, convertThresholdToCtyValues(alert.Threshold)) } - notifications := conversion.SlicePtrToSlice(alert.Notifications) + notifications := alert.GetNotifications() for i := 0; i < len(notifications); i++ { appendBlockWithCtyValues(resource, "notification", []string{}, convertNotificationToCtyValues(¬ifications[i])) } @@ -439,7 +439,7 @@ func convertNotificationToCtyValues(notification *admin.AlertsNotificationRootFo values["sms_enabled"] = cty.BoolVal(*notification.SmsEnabled) } - if roles := conversion.SlicePtrToSlice(notification.Roles); len(roles) > 0 { + if roles := notification.GetRoles(); len(roles) > 0 { roleList := make([]cty.Value, 0) for _, r := range roles { if r != "" { diff --git a/internal/service/alertconfiguration/data_source_alert_configurations.go b/internal/service/alertconfiguration/data_source_alert_configurations.go index 018b8afa17..46d7e2faa0 100644 --- a/internal/service/alertconfiguration/data_source_alert_configurations.go +++ b/internal/service/alertconfiguration/data_source_alert_configurations.go @@ -143,7 +143,7 @@ func (d *AlertConfigurationsDS) Read(ctx context.Context, req datasource.ReadReq alertConfigurationsConfig.ID = types.StringValue(conversion.EncodeStateID(map[string]string{ "project_id": projectID, })) - alertConfigurationsConfig.Results = NewTFAlertConfigurationDSModelList(conversion.SlicePtrToSlice(alerts.Results), projectID, alertConfigurationsConfig.OutputType) + alertConfigurationsConfig.Results = NewTFAlertConfigurationDSModelList(alerts.GetResults(), projectID, alertConfigurationsConfig.OutputType) if *params.IncludeCount { alertConfigurationsConfig.TotalCount = types.Int64Value(int64(*alerts.TotalCount)) } diff --git a/internal/service/alertconfiguration/model_alert_configuration.go b/internal/service/alertconfiguration/model_alert_configuration.go index 66da61f5d8..9ff3d260e6 100644 --- a/internal/service/alertconfiguration/model_alert_configuration.go +++ b/internal/service/alertconfiguration/model_alert_configuration.go @@ -108,8 +108,8 @@ func NewTFAlertConfigurationModel(apiRespConfig *admin.GroupAlertsConfig, currSt Enabled: types.BoolPointerValue(apiRespConfig.Enabled), MetricThresholdConfig: NewTFMetricThresholdConfigModel(apiRespConfig.MetricThreshold, currState.MetricThresholdConfig), ThresholdConfig: NewTFThresholdConfigModel(apiRespConfig.Threshold, currState.ThresholdConfig), - Notification: NewTFNotificationModelList(conversion.SlicePtrToSlice(apiRespConfig.Notifications), currState.Notification), - Matcher: NewTFMatcherModelList(conversion.SlicePtrToSlice(apiRespConfig.Matchers), currState.Matcher), + Notification: NewTFNotificationModelList(apiRespConfig.GetNotifications(), currState.Notification), + Matcher: NewTFMatcherModelList(apiRespConfig.GetMatchers(), currState.Matcher), } } @@ -121,7 +121,7 @@ func NewTFNotificationModelList(n []admin.AlertsNotificationRootForGroup, currSt value := n[i] notifications[i] = TfNotificationModel{ TeamName: conversion.StringPtrNullIfEmpty(value.TeamName), - Roles: conversion.SlicePtrToSlice(value.Roles), + Roles: value.GetRoles(), ChannelName: conversion.StringPtrNullIfEmpty(value.ChannelName), DatadogRegion: conversion.StringPtrNullIfEmpty(value.DatadogRegion), DelayMin: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(value.DelayMin)), @@ -145,7 +145,7 @@ func NewTFNotificationModelList(n []admin.AlertsNotificationRootForGroup, currSt currState := currStateNotifications[i] newState := TfNotificationModel{ TeamName: conversion.StringPtrNullIfEmpty(value.TeamName), - Roles: conversion.SlicePtrToSlice(value.Roles), + Roles: value.GetRoles(), // sentive attributes do not use value returned from API APIToken: conversion.StringNullIfEmpty(currState.APIToken.ValueString()), DatadogAPIKey: conversion.StringNullIfEmpty(currState.DatadogAPIKey.ValueString()), @@ -303,8 +303,8 @@ func NewTfAlertConfigurationDSModel(apiRespConfig *admin.GroupAlertsConfig, proj Enabled: types.BoolPointerValue(apiRespConfig.Enabled), MetricThresholdConfig: NewTFMetricThresholdConfigModel(apiRespConfig.MetricThreshold, []TfMetricThresholdConfigModel{}), ThresholdConfig: NewTFThresholdConfigModel(apiRespConfig.Threshold, []TfThresholdConfigModel{}), - Notification: NewTFNotificationModelList(conversion.SlicePtrToSlice(apiRespConfig.Notifications), []TfNotificationModel{}), - Matcher: NewTFMatcherModelList(conversion.SlicePtrToSlice(apiRespConfig.Matchers), []TfMatcherModel{}), + Notification: NewTFNotificationModelList(apiRespConfig.GetNotifications(), []TfNotificationModel{}), + Matcher: NewTFMatcherModelList(apiRespConfig.GetMatchers(), []TfMatcherModel{}), } } diff --git a/internal/service/atlasuser/data_source_atlas_user.go b/internal/service/atlasuser/data_source_atlas_user.go index 72b9c77a0f..8ac9db790f 100644 --- a/internal/service/atlasuser/data_source_atlas_user.go +++ b/internal/service/atlasuser/data_source_atlas_user.go @@ -189,9 +189,9 @@ func newTFAtlasUserDSModel(user *admin.CloudAppUser) tfAtlasUserDSModel { LastAuth: types.StringPointerValue(conversion.TimePtrToStringPtr(user.LastAuth)), LastName: types.StringValue(user.LastName), MobileNumber: types.StringValue(user.MobileNumber), - TeamIDs: conversion.SlicePtrToSlice(user.TeamIds), - Links: newTFLinksList(conversion.SlicePtrToSlice(user.Links)), - Roles: newTFRolesList(conversion.SlicePtrToSlice(user.Roles)), + TeamIDs: user.GetTeamIds(), + Links: newTFLinksList(user.GetLinks()), + Roles: newTFRolesList(user.GetRoles()), } } diff --git a/internal/service/atlasuser/data_source_atlas_users.go b/internal/service/atlasuser/data_source_atlas_users.go index 81e8b543cd..0abd48d984 100644 --- a/internal/service/atlasuser/data_source_atlas_users.go +++ b/internal/service/atlasuser/data_source_atlas_users.go @@ -191,7 +191,7 @@ func (d *atlasUsersDS) Read(ctx context.Context, req datasource.ReadRequest, res resp.Diagnostics.AddError("error when getting users from Atlas", fmt.Sprintf(errorUsersRead, "project", projectID, err.Error())) return } - users = conversion.SlicePtrToSlice(apiResp.Results) + users = apiResp.GetResults() totalCount = *apiResp.TotalCount case !atlasUsersConfig.TeamID.IsNull() && !atlasUsersConfig.OrgID.IsNull(): teamID := atlasUsersConfig.TeamID.ValueString() @@ -205,7 +205,7 @@ func (d *atlasUsersDS) Read(ctx context.Context, req datasource.ReadRequest, res resp.Diagnostics.AddError("error when getting users from Atlas", fmt.Sprintf(errorUsersRead, "team", teamID, err.Error())) return } - users = conversion.SlicePtrToSlice(apiResp.Results) + users = apiResp.GetResults() totalCount = *apiResp.TotalCount default: // only org_id is defined orgID := atlasUsersConfig.OrgID.ValueString() @@ -218,7 +218,7 @@ func (d *atlasUsersDS) Read(ctx context.Context, req datasource.ReadRequest, res resp.Diagnostics.AddError("error when getting users from Atlas", fmt.Sprintf(errorUsersRead, "org", orgID, err.Error())) return } - users = conversion.SlicePtrToSlice(apiResp.Results) + users = apiResp.GetResults() totalCount = *apiResp.TotalCount } diff --git a/internal/service/databaseuser/model_database_user.go b/internal/service/databaseuser/model_database_user.go index fc28ca63d8..cc953e5a70 100644 --- a/internal/service/databaseuser/model_database_user.go +++ b/internal/service/databaseuser/model_database_user.go @@ -47,17 +47,17 @@ func NewMongoDBDatabaseUser(ctx context.Context, dbUserModel *TfDatabaseUserMode } func NewTfDatabaseUserModel(ctx context.Context, model *TfDatabaseUserModel, dbUser *admin.CloudDatabaseUser) (*TfDatabaseUserModel, diag.Diagnostics) { - rolesSet, diagnostic := types.SetValueFrom(ctx, RoleObjectType, NewTFRolesModel(conversion.SlicePtrToSlice(dbUser.Roles))) + rolesSet, diagnostic := types.SetValueFrom(ctx, RoleObjectType, NewTFRolesModel(dbUser.GetRoles())) if diagnostic.HasError() { return nil, diagnostic } - labelsSet, diagnostic := types.SetValueFrom(ctx, LabelObjectType, NewTFLabelsModel(conversion.SlicePtrToSlice(dbUser.Labels))) + labelsSet, diagnostic := types.SetValueFrom(ctx, LabelObjectType, NewTFLabelsModel(dbUser.GetLabels())) if diagnostic.HasError() { return nil, diagnostic } - scopesSet, diagnostic := types.SetValueFrom(ctx, ScopeObjectType, NewTFScopesModel(conversion.SlicePtrToSlice(dbUser.Scopes))) + scopesSet, diagnostic := types.SetValueFrom(ctx, ScopeObjectType, NewTFScopesModel(dbUser.GetScopes())) if diagnostic.HasError() { return nil, diagnostic } @@ -102,9 +102,9 @@ func NewTFDatabaseDSUserModel(ctx context.Context, dbUser *admin.CloudDatabaseUs OIDCAuthType: types.StringValue(dbUser.GetOidcAuthType()), LDAPAuthType: types.StringValue(dbUser.GetLdapAuthType()), AWSIAMType: types.StringValue(dbUser.GetAwsIAMType()), - Roles: NewTFRolesModel(conversion.SlicePtrToSlice(dbUser.Roles)), - Labels: NewTFLabelsModel(conversion.SlicePtrToSlice(dbUser.Labels)), - Scopes: NewTFScopesModel(conversion.SlicePtrToSlice(dbUser.Scopes)), + Roles: NewTFRolesModel(dbUser.GetRoles()), + Labels: NewTFLabelsModel(dbUser.GetLabels()), + Scopes: NewTFScopesModel(dbUser.GetScopes()), } return databaseUserModel, nil diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go index c9ea9c38c1..630443434e 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go @@ -347,13 +347,13 @@ func dataSourceMongoDBAtlasFederatedDatabaseInstanceRead(ctx context.Context, d return diag.FromErr(fmt.Errorf(errorFederatedDatabaseInstanceSetting, "data_process_region", name, err)) } - if storageDatabaseField := flattenDataFederationDatabase(conversion.SlicePtrToSlice(dataFederationInstance.Storage.Databases)); storageDatabaseField != nil { + if storageDatabaseField := flattenDataFederationDatabase(dataFederationInstance.Storage.GetDatabases()); storageDatabaseField != nil { if err := d.Set("storage_databases", storageDatabaseField); err != nil { return diag.FromErr(fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_databases", name, err)) } } - if err := d.Set("storage_stores", flattenDataFederationStores(conversion.SlicePtrToSlice(dataFederationInstance.Storage.Stores))); err != nil { + if err := d.Set("storage_stores", flattenDataFederationStores(dataFederationInstance.Storage.GetStores())); err != nil { return diag.FromErr(fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_stores", name, err)) } diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go index 44c7b49347..00eddfa75f 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -147,8 +146,8 @@ func flattenFederatedDatabaseInstances(d *schema.ResourceData, projectID string, "hostnames": federatedDatabaseInstances[i].GetHostnames(), "cloud_provider_config": flattenCloudProviderConfig(d, federatedDatabaseInstances[i].CloudProviderConfig), "data_process_region": flattenDataProcessRegion(federatedDatabaseInstances[i].DataProcessRegion), - "storage_databases": flattenDataFederationDatabase(conversion.SlicePtrToSlice(federatedDatabaseInstances[i].Storage.Databases)), - "storage_stores": flattenDataFederationStores(conversion.SlicePtrToSlice(federatedDatabaseInstances[i].Storage.Stores)), + "storage_databases": flattenDataFederationDatabase(federatedDatabaseInstances[i].Storage.GetDatabases()), + "storage_stores": flattenDataFederationStores(federatedDatabaseInstances[i].Storage.GetStores()), } } } diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index 1205e1acc1..955e7844f6 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -496,7 +496,7 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex if storage, ok := dataFederationInstance.GetStorageOk(); ok { if databases, ok := storage.GetDatabasesOk(); ok { - if storageDatabaseField := flattenDataFederationDatabase(conversion.SlicePtrToSlice(databases)); storageDatabaseField != nil { + if storageDatabaseField := flattenDataFederationDatabase(*databases); storageDatabaseField != nil { if err := d.Set("storage_databases", storageDatabaseField); err != nil { return nil, fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_databases", name, err) } @@ -504,7 +504,7 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex } if stores, ok := storage.GetStoresOk(); ok { - if err := d.Set("storage_stores", flattenDataFederationStores(conversion.SlicePtrToSlice(stores))); err != nil { + if err := d.Set("storage_stores", flattenDataFederationStores(*stores)); err != nil { return nil, fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_stores", name, err) } } @@ -777,8 +777,8 @@ func flattenDataFederationDatabase(atlasDatabases []admin.DataLakeDatabaseInstan dbs[i] = map[string]any{ "name": atlasDatabase.GetName(), "max_wildcard_collections": atlasDatabase.GetMaxWildcardCollections(), - "collections": flattenDataFederationCollections(conversion.SlicePtrToSlice(atlasDatabase.Collections)), - "views": flattenDataFederationDatabaseViews(conversion.SlicePtrToSlice(atlasDatabase.Views)), + "collections": flattenDataFederationCollections(atlasDatabase.GetCollections()), + "views": flattenDataFederationDatabaseViews(atlasDatabase.GetViews()), } } @@ -805,7 +805,7 @@ func flattenDataFederationCollections(atlasCollections []admin.DataLakeDatabaseC for i, atlasCollection := range atlasCollections { colls[i] = map[string]any{ "name": atlasCollection.GetName(), - "data_sources": flattenDataFederationDataSources(conversion.SlicePtrToSlice(atlasCollection.DataSources)), + "data_sources": flattenDataFederationDataSources(atlasCollection.GetDataSources()), } } @@ -869,7 +869,7 @@ func newReadPreferenceField(atlasReadPreference *admin.DataLakeAtlasStoreReadPre { "mode": atlasReadPreference.GetMode(), "max_staleness_seconds": atlasReadPreference.GetMaxStalenessSeconds(), - "tag_sets": flattenReadPreferenceTagSets(conversion.SlicePtrToSlice(atlasReadPreference.TagSets)), + "tag_sets": flattenReadPreferenceTagSets(atlasReadPreference.GetTagSets()), }, } } diff --git a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go index ecb26f4c92..6d6804a8a6 100644 --- a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go @@ -242,7 +242,7 @@ func dataSourceMongoDBAtlasFederatedSettingsIdentityProviderRead(ctx context.Con return diag.FromErr(fmt.Errorf("error setting `associated_domains` for federatedSettings IdentityProviders: %s", err)) } - if err := d.Set("associated_orgs", FlattenAssociatedOrgs(conversion.SlicePtrToSlice(federatedSettingsIdentityProvider.AssociatedOrgs))); err != nil { + if err := d.Set("associated_orgs", FlattenAssociatedOrgs(federatedSettingsIdentityProvider.GetAssociatedOrgs())); err != nil { return diag.FromErr(fmt.Errorf("error setting `associated_orgs` for federatedSettings IdentityProviders: %s", err)) } diff --git a/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go index 75770af640..782c9250bb 100644 --- a/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go @@ -19,7 +19,7 @@ func FlattenFederatedSettingsIdentityProvider(federatedSettingsIdentityProvider federatedSettingsIdentityProviderMap[i] = map[string]any{ "acs_url": federatedSettingsIdentityProvider[i].AcsUrl, "associated_domains": federatedSettingsIdentityProvider[i].AssociatedDomains, - "associated_orgs": FlattenAssociatedOrgs(conversion.SlicePtrToSlice(federatedSettingsIdentityProvider[i].AssociatedOrgs)), + "associated_orgs": FlattenAssociatedOrgs(federatedSettingsIdentityProvider[i].GetAssociatedOrgs()), "audience_uri": federatedSettingsIdentityProvider[i].AudienceUri, "display_name": federatedSettingsIdentityProvider[i].DisplayName, "issuer_uri": federatedSettingsIdentityProvider[i].IssuerUri, @@ -53,7 +53,7 @@ func FlattenAssociatedOrgs(associatedOrgs []admin.ConnectedOrgConfig) []map[stri "identity_provider_id": associatedOrgs[i].IdentityProviderId, "org_id": associatedOrgs[i].OrgId, "post_auth_role_grants": associatedOrgs[i].PostAuthRoleGrants, - "role_mappings": FlattenAuthFederationRoleMapping(conversion.SlicePtrToSlice(associatedOrgs[i].RoleMappings)), + "role_mappings": FlattenAuthFederationRoleMapping(associatedOrgs[i].GetRoleMappings()), "user_conflicts": nil, } } else { @@ -63,8 +63,8 @@ func FlattenAssociatedOrgs(associatedOrgs []admin.ConnectedOrgConfig) []map[stri "identity_provider_id": associatedOrgs[i].IdentityProviderId, "org_id": associatedOrgs[i].OrgId, "post_auth_role_grants": associatedOrgs[i].PostAuthRoleGrants, - "role_mappings": FlattenAuthFederationRoleMapping(conversion.SlicePtrToSlice(associatedOrgs[i].RoleMappings)), - "user_conflicts": FlattenFederatedUser(conversion.SlicePtrToSlice(associatedOrgs[i].UserConflicts)), + "role_mappings": FlattenAuthFederationRoleMapping(associatedOrgs[i].GetRoleMappings()), + "user_conflicts": FlattenFederatedUser(associatedOrgs[i].GetUserConflicts()), } } } @@ -154,7 +154,7 @@ func FlattenAuthFederationRoleMapping(roleMappings []admin.AuthFederationRoleMap roleMappingsMap[i] = map[string]any{ "external_group_name": roleMappings[i].ExternalGroupName, "id": roleMappings[i].Id, - "role_assignments": FlattenRoleAssignmentsV2(conversion.SlicePtrToSlice(roleMappings[i].RoleAssignments)), + "role_assignments": FlattenRoleAssignmentsV2(roleMappings[i].GetRoleAssignments()), } } } @@ -165,7 +165,7 @@ func FlattenAuthFederationRoleMapping(roleMappings []admin.AuthFederationRoleMap func FlattenPemFileInfo(pemFileInfo admin.PemFileInfo) []map[string]any { var pemFileInfoMap []map[string]any - if certificates := conversion.SlicePtrToSlice(pemFileInfo.Certificates); len(certificates) > 0 { + if certificates := pemFileInfo.GetCertificates(); len(certificates) > 0 { pemFileInfoMap = make([]map[string]any, 1) pemFileInfoMap[0] = map[string]any{ diff --git a/internal/service/project/data_source_projects.go b/internal/service/project/data_source_projects.go index 4aa49505f3..0681bef193 100644 --- a/internal/service/project/data_source_projects.go +++ b/internal/service/project/data_source_projects.go @@ -170,7 +170,7 @@ func (d *ProjectsDS) Read(ctx context.Context, req datasource.ReadRequest, resp } func populateProjectsDataSourceModel(ctx context.Context, connV2 *admin.APIClient, stateModel *tfProjectsDSModel, projectsRes *admin.PaginatedAtlasGroup) error { - input := conversion.SlicePtrToSlice(projectsRes.Results) + input := projectsRes.GetResults() results := make([]*TfProjectDSModel, 0, len(input)) for i := range input { project := input[i] diff --git a/internal/service/project/model_project.go b/internal/service/project/model_project.go index a2f16b9ae8..eee5f5829c 100644 --- a/internal/service/project/model_project.go +++ b/internal/service/project/model_project.go @@ -32,7 +32,7 @@ func NewTFTeamsDataSourceModel(ctx context.Context, atlasTeams *admin.PaginatedT if atlasTeams.GetTotalCount() == 0 { return nil } - results := conversion.SlicePtrToSlice(atlasTeams.Results) + results := atlasTeams.GetResults() teams := make([]*TfTeamDSModel, len(results)) for i, atlasTeam := range results { roleNames, _ := types.ListValueFrom(ctx, types.StringType, atlasTeam.RoleNames) @@ -103,7 +103,7 @@ func newTFLimitsResourceModel(ctx context.Context, dataFederationLimits []admin. } func newTFTeamsResourceModel(ctx context.Context, atlasTeams *admin.PaginatedTeamRole) types.Set { - results := conversion.SlicePtrToSlice(atlasTeams.Results) + results := atlasTeams.GetResults() teams := make([]TfTeamModel, len(results)) for i, atlasTeam := range results { roleNames, _ := types.SetValueFrom(ctx, types.StringType, atlasTeam.RoleNames) diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index 1ba53a285f..9eb79400b6 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -768,7 +768,7 @@ func ResourceProjectDependentsDeletingRefreshFunc(ctx context.Context, projectID return dependents, projectDependentsStateIdle, nil } - results := conversion.SlicePtrToSlice(dependents.AdvancedClusters.Results) + results := dependents.AdvancedClusters.GetResults() for i := range results { if *results[i].StateName != projectDependentsStateDeleting { return dependents, projectDependentsStateIdle, nil diff --git a/internal/service/searchdeployment/model_search_deployment.go b/internal/service/searchdeployment/model_search_deployment.go index e4543500a2..9569899b0c 100644 --- a/internal/service/searchdeployment/model_search_deployment.go +++ b/internal/service/searchdeployment/model_search_deployment.go @@ -39,7 +39,7 @@ func NewTFSearchDeployment(ctx context.Context, clusterName string, deployResp * result.Timeouts = *timeout } - specsList, diagnostics := types.ListValueFrom(ctx, SpecObjectType, newTFSpecsModel(conversion.SlicePtrToSlice(deployResp.Specs))) + specsList, diagnostics := types.ListValueFrom(ctx, SpecObjectType, newTFSpecsModel(deployResp.GetSpecs())) if diagnostics.HasError() { return nil, diagnostics } diff --git a/internal/service/searchindex/data_source_search_index.go b/internal/service/searchindex/data_source_search_index.go index ee02bfcbb8..f4738b1e92 100644 --- a/internal/service/searchindex/data_source_search_index.go +++ b/internal/service/searchindex/data_source_search_index.go @@ -128,7 +128,7 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour return diag.Errorf("error setting `analyzer` for search index (%s): %s", d.Id(), err) } - if analyzers := conversion.SlicePtrToSlice(searchIndex.Analyzers); len(analyzers) > 0 { + if analyzers := searchIndex.GetAnalyzers(); len(analyzers) > 0 { searchIndexMappingFields, err := marshalSearchIndex(analyzers) if err != nil { return diag.FromErr(err) @@ -155,7 +155,7 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour return diag.Errorf("error setting `searchAnalyzer` for search index (%s): %s", d.Id(), err) } - if err := d.Set("synonyms", flattenSearchIndexSynonyms(conversion.SlicePtrToSlice(searchIndex.Synonyms))); err != nil { + if err := d.Set("synonyms", flattenSearchIndexSynonyms(searchIndex.GetSynonyms())); err != nil { return diag.Errorf("error setting `synonyms` for search index (%s): %s", d.Id(), err) } @@ -175,7 +175,7 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour } } - if fields := conversion.SlicePtrToSlice(searchIndex.Fields); len(fields) > 0 { + if fields := searchIndex.GetFields(); len(fields) > 0 { fieldsMarshaled, err := marshalSearchIndex(fields) if err != nil { return diag.FromErr(err) diff --git a/internal/service/searchindex/data_source_search_indexes.go b/internal/service/searchindex/data_source_search_indexes.go index 250d7adf02..fcac27216c 100644 --- a/internal/service/searchindex/data_source_search_indexes.go +++ b/internal/service/searchindex/data_source_search_indexes.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20231115003/admin" ) @@ -112,7 +111,7 @@ func flattenSearchIndexes(searchIndexes []admin.ClusterSearchIndex, projectID, c "name": searchIndexes[i].Name, "search_analyzer": searchIndexes[i].SearchAnalyzer, "status": searchIndexes[i].Status, - "synonyms": flattenSearchIndexSynonyms(conversion.SlicePtrToSlice(searchIndexes[i].Synonyms)), + "synonyms": flattenSearchIndexSynonyms(searchIndexes[i].GetSynonyms()), "type": searchIndexes[i].Type, } @@ -128,7 +127,7 @@ func flattenSearchIndexes(searchIndexes []admin.ClusterSearchIndex, projectID, c } } - if analyzers := conversion.SlicePtrToSlice(searchIndexes[i].Analyzers); len(analyzers) > 0 { + if analyzers := searchIndexes[i].GetAnalyzers(); len(analyzers) > 0 { searchIndexAnalyzers, err := marshalSearchIndex(analyzers) if err != nil { return nil, err @@ -136,7 +135,7 @@ func flattenSearchIndexes(searchIndexes []admin.ClusterSearchIndex, projectID, c searchIndexesMap[i]["analyzers"] = searchIndexAnalyzers } - if fields := conversion.SlicePtrToSlice(searchIndexes[i].Fields); len(fields) > 0 { + if fields := searchIndexes[i].GetFields(); len(fields) > 0 { fieldsMarshaled, err := marshalSearchIndex(fields) if err != nil { return nil, err diff --git a/internal/service/searchindex/resource_search_index.go b/internal/service/searchindex/resource_search_index.go index e77729361e..2884b778e3 100644 --- a/internal/service/searchindex/resource_search_index.go +++ b/internal/service/searchindex/resource_search_index.go @@ -320,7 +320,7 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource return diag.Errorf("error setting `analyzer` for search index (%s): %s", d.Id(), err) } - if analyzers := conversion.SlicePtrToSlice(searchIndex.Analyzers); len(analyzers) > 0 { + if analyzers := searchIndex.GetAnalyzers(); len(analyzers) > 0 { searchIndexMappingFields, err := marshalSearchIndex(analyzers) if err != nil { return diag.FromErr(err) @@ -347,7 +347,7 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource return diag.Errorf("error setting `searchAnalyzer` for search index (%s): %s", d.Id(), err) } - if err := d.Set("synonyms", flattenSearchIndexSynonyms(conversion.SlicePtrToSlice(searchIndex.Synonyms))); err != nil { + if err := d.Set("synonyms", flattenSearchIndexSynonyms(searchIndex.GetSynonyms())); err != nil { return diag.Errorf("error setting `synonyms` for search index (%s): %s", d.Id(), err) } @@ -368,7 +368,7 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource } } - if fields := conversion.SlicePtrToSlice(searchIndex.Fields); len(fields) > 0 { + if fields := searchIndex.GetFields(); len(fields) > 0 { fields, err := marshalSearchIndex(fields) if err != nil { return diag.FromErr(err) diff --git a/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go b/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go index f43dbed500..6fac777bb2 100644 --- a/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go +++ b/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go @@ -97,7 +97,7 @@ func dataSourceMongoDBAtlasCloudSharedTierRestoreJobRead(ctx context.Context, d return diag.FromErr(fmt.Errorf("error getting shared tier restore jobs for cluster '%s': %w", clusterName, err)) } - if err := d.Set("results", flattenShardTierRestoreJobs(conversion.SlicePtrToSlice(jobs.Results))); err != nil { + if err := d.Set("results", flattenShardTierRestoreJobs(jobs.GetResults())); err != nil { return diag.FromErr(fmt.Errorf("error setting `results`: %w", err)) } diff --git a/internal/service/sharedtier/data_source_shared_tier_snapshots.go b/internal/service/sharedtier/data_source_shared_tier_snapshots.go index e3f30a78d5..59b69208d6 100644 --- a/internal/service/sharedtier/data_source_shared_tier_snapshots.go +++ b/internal/service/sharedtier/data_source_shared_tier_snapshots.go @@ -80,7 +80,7 @@ func dataSourceMongoDBAtlasSharedTierSnapshotsRead(ctx context.Context, d *schem return diag.FromErr(fmt.Errorf("error getting shard-tier snapshots for cluster '%s': %w", clusterName, err)) } - if err := d.Set("results", flattenSharedTierSnapshots(conversion.SlicePtrToSlice(snapshots.Results))); err != nil { + if err := d.Set("results", flattenSharedTierSnapshots(snapshots.GetResults())); err != nil { return diag.FromErr(fmt.Errorf("error setting `results`: %w", err)) } diff --git a/internal/service/streamconnection/model_stream_connection.go b/internal/service/streamconnection/model_stream_connection.go index 72b035959a..9ac2b2a06c 100644 --- a/internal/service/streamconnection/model_stream_connection.go +++ b/internal/service/streamconnection/model_stream_connection.go @@ -122,7 +122,7 @@ func newTFConnectionAuthenticationModel(ctx context.Context, currAuthConfig *typ func NewTFStreamConnections(ctx context.Context, streamConnectionsConfig *TFStreamConnectionsDSModel, paginatedResult *admin.PaginatedApiStreamsConnection) (*TFStreamConnectionsDSModel, diag.Diagnostics) { - input := conversion.SlicePtrToSlice(paginatedResult.Results) + input := paginatedResult.GetResults() results := make([]TFStreamConnectionModel, len(input)) for i := range input { projectID := streamConnectionsConfig.ProjectID.ValueString() diff --git a/internal/service/streaminstance/model_stream_instance.go b/internal/service/streaminstance/model_stream_instance.go index 998fa30736..c3c7334d52 100644 --- a/internal/service/streaminstance/model_stream_instance.go +++ b/internal/service/streaminstance/model_stream_instance.go @@ -63,7 +63,7 @@ func NewTFStreamInstance(ctx context.Context, apiResp *admin.StreamsTenant) (*TF } func NewTFStreamInstances(ctx context.Context, streamInstancesConfig *TFStreamInstancesModel, paginatedResult *admin.PaginatedApiStreamsTenant) (*TFStreamInstancesModel, diag.Diagnostics) { - input := conversion.SlicePtrToSlice(paginatedResult.Results) + input := paginatedResult.GetResults() results := make([]TFStreamInstanceModel, len(input)) for i := range input { instance, diags := NewTFStreamInstance(ctx, &input[i]) From e9cb867fb657c234364d5246de7c4a13baa4ab90 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 14:39:49 +0100 Subject: [PATCH 15/21] use GetResults --- internal/service/atlasuser/data_source_atlas_users_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/atlasuser/data_source_atlas_users_test.go b/internal/service/atlasuser/data_source_atlas_users_test.go index 0d3376d4f7..2fb5054b0e 100644 --- a/internal/service/atlasuser/data_source_atlas_users_test.go +++ b/internal/service/atlasuser/data_source_atlas_users_test.go @@ -224,7 +224,7 @@ func dataSourceChecksForUsers(dataSourceName, orgID string, users *admin.Paginat resource.TestCheckResourceAttr(dataSourceName, "total_count", fmt.Sprintf("%d", totalCountValue)), } for i := range *users.Results { - checks = append(checks, dataSourceChecksForUser(dataSourceName, fmt.Sprintf("results.%d.", i), &(*users.Results)[i])...) + checks = append(checks, dataSourceChecksForUser(dataSourceName, fmt.Sprintf("results.%d.", i), &users.GetResults()[i])...) } return checks From 3e77d827f77f09b7ec01a2af0112fe04aa87185f Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 14:49:07 +0100 Subject: [PATCH 16/21] extract results --- internal/service/atlasuser/data_source_atlas_users_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/atlasuser/data_source_atlas_users_test.go b/internal/service/atlasuser/data_source_atlas_users_test.go index 2fb5054b0e..dbd0aaf26a 100644 --- a/internal/service/atlasuser/data_source_atlas_users_test.go +++ b/internal/service/atlasuser/data_source_atlas_users_test.go @@ -223,10 +223,10 @@ func dataSourceChecksForUsers(dataSourceName, orgID string, users *admin.Paginat resource.TestCheckResourceAttr(dataSourceName, "org_id", orgID), resource.TestCheckResourceAttr(dataSourceName, "total_count", fmt.Sprintf("%d", totalCountValue)), } - for i := range *users.Results { - checks = append(checks, dataSourceChecksForUser(dataSourceName, fmt.Sprintf("results.%d.", i), &users.GetResults()[i])...) + results := users.GetResults() + for i := range results { + checks = append(checks, dataSourceChecksForUser(dataSourceName, fmt.Sprintf("results.%d.", i), &results[i])...) } - return checks } From 46a67a1526fbf43ff5d35330a8ee800420dbc784 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 15:00:27 +0100 Subject: [PATCH 17/21] implement suggestion preallocating slice --- .../alertconfiguration/data_source_alert_configuration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/alertconfiguration/data_source_alert_configuration.go b/internal/service/alertconfiguration/data_source_alert_configuration.go index 5ac631fc52..dafac342cc 100644 --- a/internal/service/alertconfiguration/data_source_alert_configuration.go +++ b/internal/service/alertconfiguration/data_source_alert_configuration.go @@ -440,7 +440,7 @@ func convertNotificationToCtyValues(notification *admin.AlertsNotificationRootFo } if roles := notification.GetRoles(); len(roles) > 0 { - roleList := make([]cty.Value, 0) + roleList := make([]cty.Value, 0, len(roles)) for _, r := range roles { if r != "" { roleList = append(roleList, cty.StringVal(r)) From ee26ed2aee06171938cc1a09923cd716ffee8364 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:09:35 +0100 Subject: [PATCH 18/21] rename to NonEmptyToPtr as it works for arrays and slices --- internal/common/conversion/type_conversion.go | 2 +- internal/common/conversion/type_conversion_test.go | 4 ++-- .../model_alert_configuration.go | 2 +- .../model_alert_configuration_test.go | 4 ++-- .../resource_alert_configuration.go | 8 ++++---- .../service/databaseuser/model_database_user.go | 6 +++--- .../resource_federated_database_instance.go | 14 +++++++------- ...esource_federated_settings_identity_provider.go | 2 +- internal/service/project/model_project.go | 2 +- internal/service/project/model_project_test.go | 6 +++--- internal/service/project/resource_project.go | 2 +- .../searchdeployment/model_search_deployment.go | 2 +- .../service/searchindex/resource_search_index.go | 12 ++++++------ 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/internal/common/conversion/type_conversion.go b/internal/common/conversion/type_conversion.go index 391bca807d..2ef66f7363 100644 --- a/internal/common/conversion/type_conversion.go +++ b/internal/common/conversion/type_conversion.go @@ -57,7 +57,7 @@ func MongoDBRegionToAWSRegion(region string) string { return strings.ReplaceAll(strings.ToLower(region), "_", "-") } -func NonEmptySliceToSlicePtr[T any](v []T) *[]T { +func NonEmptyToPtr[T any](v []T) *[]T { if len(v) == 0 { return nil } diff --git a/internal/common/conversion/type_conversion_test.go b/internal/common/conversion/type_conversion_test.go index c789c575b7..d5da040ede 100644 --- a/internal/common/conversion/type_conversion_test.go +++ b/internal/common/conversion/type_conversion_test.go @@ -69,7 +69,7 @@ func TestMongoDBRegionToAWSRegion(t *testing.T) { } } -func TestNonEmptySliceToSlicePtr(t *testing.T) { +func TestNonEmptyToPtr(t *testing.T) { var ( nilSlice []string emptyNonNilSlice = []string{} @@ -86,7 +86,7 @@ func TestNonEmptySliceToSlicePtr(t *testing.T) { } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - assert.Equal(t, tc.expected, conversion.NonEmptySliceToSlicePtr(tc.given)) + assert.Equal(t, tc.expected, conversion.NonEmptyToPtr(tc.given)) }) } } diff --git a/internal/service/alertconfiguration/model_alert_configuration.go b/internal/service/alertconfiguration/model_alert_configuration.go index 9ff3d260e6..01b3d7b04a 100644 --- a/internal/service/alertconfiguration/model_alert_configuration.go +++ b/internal/service/alertconfiguration/model_alert_configuration.go @@ -43,7 +43,7 @@ func NewNotificationList(tfNotificationSlice []TfNotificationModel) ([]admin.Ale Username: n.Username.ValueStringPointer(), VictorOpsApiKey: n.VictorOpsAPIKey.ValueStringPointer(), VictorOpsRoutingKey: n.VictorOpsRoutingKey.ValueStringPointer(), - Roles: conversion.NonEmptySliceToSlicePtr(n.Roles), + Roles: conversion.NonEmptyToPtr(n.Roles), MicrosoftTeamsWebhookUrl: n.MicrosoftTeamsWebhookURL.ValueStringPointer(), WebhookSecret: n.WebhookSecret.ValueStringPointer(), WebhookUrl: n.WebhookURL.ValueStringPointer(), diff --git a/internal/service/alertconfiguration/model_alert_configuration_test.go b/internal/service/alertconfiguration/model_alert_configuration_test.go index 48f073156e..e8cd0ae4eb 100644 --- a/internal/service/alertconfiguration/model_alert_configuration_test.go +++ b/internal/service/alertconfiguration/model_alert_configuration_test.go @@ -45,7 +45,7 @@ func TestNotificationSDKToTFModel(t *testing.T) { SmsEnabled: admin.PtrBool(disabled), EmailEnabled: admin.PtrBool(enabled), ChannelName: admin.PtrString("#channel"), - Roles: conversion.NonEmptySliceToSlicePtr(roles), + Roles: conversion.NonEmptyToPtr(roles), ApiToken: admin.PtrString("newApiToken"), }, }, @@ -290,7 +290,7 @@ func TestNotificationTFModelToSDK(t *testing.T) { DelayMin: admin.PtrInt(delayMin), SmsEnabled: admin.PtrBool(disabled), EmailEnabled: admin.PtrBool(enabled), - Roles: conversion.NonEmptySliceToSlicePtr(roles), + Roles: conversion.NonEmptyToPtr(roles), }, }, }, diff --git a/internal/service/alertconfiguration/resource_alert_configuration.go b/internal/service/alertconfiguration/resource_alert_configuration.go index cfed0a47ab..fae08ed5ac 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration.go +++ b/internal/service/alertconfiguration/resource_alert_configuration.go @@ -380,7 +380,7 @@ func (r *alertConfigurationRS) Create(ctx context.Context, req resource.CreateRe apiReq := &admin.GroupAlertsConfig{ EventTypeName: alertConfigPlan.EventType.ValueStringPointer(), Enabled: alertConfigPlan.Enabled.ValueBoolPointer(), - Matchers: conversion.NonEmptySliceToSlicePtr(NewMatcherList(alertConfigPlan.Matcher)), + Matchers: conversion.NonEmptyToPtr(NewMatcherList(alertConfigPlan.Matcher)), MetricThreshold: NewMetricThreshold(alertConfigPlan.MetricThresholdConfig), Threshold: NewThreshold(alertConfigPlan.ThresholdConfig), } @@ -390,7 +390,7 @@ func (r *alertConfigurationRS) Create(ctx context.Context, req resource.CreateRe resp.Diagnostics.AddError(errorCreateAlertConf, err.Error()) return } - apiReq.Notifications = conversion.NonEmptySliceToSlicePtr(notifications) + apiReq.Notifications = conversion.NonEmptyToPtr(notifications) apiResp, _, err := connV2.AlertConfigurationsApi.CreateAlertConfiguration(ctx, projectID, apiReq).Execute() if err != nil { @@ -482,7 +482,7 @@ func (r *alertConfigurationRS) Update(ctx context.Context, req resource.UpdateRe } if !reflect.DeepEqual(alertConfigPlan.Matcher, alertConfigState.Matcher) { - apiReq.Matchers = conversion.NonEmptySliceToSlicePtr(NewMatcherList(alertConfigPlan.Matcher)) + apiReq.Matchers = conversion.NonEmptyToPtr(NewMatcherList(alertConfigPlan.Matcher)) } // Always refresh structure to handle service keys being obfuscated coming back from read API call @@ -491,7 +491,7 @@ func (r *alertConfigurationRS) Update(ctx context.Context, req resource.UpdateRe resp.Diagnostics.AddError(errorUpdateAlertConf, err.Error()) return } - apiReq.Notifications = conversion.NonEmptySliceToSlicePtr(notifications) + apiReq.Notifications = conversion.NonEmptyToPtr(notifications) var updatedAlertConfigResp *admin.GroupAlertsConfig diff --git a/internal/service/databaseuser/model_database_user.go b/internal/service/databaseuser/model_database_user.go index cc953e5a70..47cc14bb09 100644 --- a/internal/service/databaseuser/model_database_user.go +++ b/internal/service/databaseuser/model_database_user.go @@ -40,9 +40,9 @@ func NewMongoDBDatabaseUser(ctx context.Context, dbUserModel *TfDatabaseUserMode OidcAuthType: dbUserModel.OIDCAuthType.ValueStringPointer(), LdapAuthType: dbUserModel.LDAPAuthType.ValueStringPointer(), DatabaseName: dbUserModel.AuthDatabaseName.ValueString(), - Roles: conversion.NonEmptySliceToSlicePtr(NewMongoDBAtlasRoles(rolesModel)), - Labels: conversion.NonEmptySliceToSlicePtr(NewMongoDBAtlasLabels(labelsModel)), - Scopes: conversion.NonEmptySliceToSlicePtr(NewMongoDBAtlasScopes(scopesModel)), + Roles: conversion.NonEmptyToPtr(NewMongoDBAtlasRoles(rolesModel)), + Labels: conversion.NonEmptyToPtr(NewMongoDBAtlasLabels(labelsModel)), + Scopes: conversion.NonEmptyToPtr(NewMongoDBAtlasScopes(scopesModel)), }, nil } diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index 955e7844f6..1b26ea220d 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -528,8 +528,8 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex func newDataFederationStorage(d *schema.ResourceData) *admin.DataLakeStorage { return &admin.DataLakeStorage{ - Databases: conversion.NonEmptySliceToSlicePtr(newDataFederationDatabase(d)), - Stores: conversion.NonEmptySliceToSlicePtr(newStores(d)), + Databases: conversion.NonEmptyToPtr(newDataFederationDatabase(d)), + Stores: conversion.NonEmptyToPtr(newStores(d)), } } @@ -552,7 +552,7 @@ func newStores(d *schema.ResourceData) []admin.DataLakeStoreSettings { Prefix: conversion.StringPtr(storeFromConfMap["prefix"].(string)), Delimiter: conversion.StringPtr(storeFromConfMap["delimiter"].(string)), IncludeTags: conversion.Pointer(storeFromConfMap["include_tags"].(bool)), - AdditionalStorageClasses: conversion.NonEmptySliceToSlicePtr(newAdditionalStorageClasses(storeFromConfMap["additional_storage_classes"].([]any))), + AdditionalStorageClasses: conversion.NonEmptyToPtr(newAdditionalStorageClasses(storeFromConfMap["additional_storage_classes"].([]any))), ReadPreference: newReadPreference(storeFromConfMap), } } @@ -582,7 +582,7 @@ func newReadPreference(storeFromConfMap map[string]any) *admin.DataLakeAtlasStor return &admin.DataLakeAtlasStoreReadPreference{ Mode: conversion.StringPtr(readPreferenceFromConfMap["mode"].(string)), MaxStalenessSeconds: conversion.IntPtr(readPreferenceFromConfMap["max_staleness_seconds"].(int)), - TagSets: conversion.NonEmptySliceToSlicePtr(newTagSets(readPreferenceFromConfMap)), + TagSets: conversion.NonEmptyToPtr(newTagSets(readPreferenceFromConfMap)), } } @@ -626,7 +626,7 @@ func newDataFederationDatabase(d *schema.ResourceData) []admin.DataLakeDatabaseI dbs[i] = admin.DataLakeDatabaseInstance{ Name: conversion.StringPtr(storageDBFromConfMap["name"].(string)), MaxWildcardCollections: conversion.IntPtr(storageDBFromConfMap["max_wildcard_collections"].(int)), - Collections: conversion.NonEmptySliceToSlicePtr(newDataFederationCollections(storageDBFromConfMap)), + Collections: conversion.NonEmptyToPtr(newDataFederationCollections(storageDBFromConfMap)), } } @@ -643,7 +643,7 @@ func newDataFederationCollections(storageDBFromConfMap map[string]any) []admin.D for i, collectionFromConf := range collectionsFromConf { collections[i] = admin.DataLakeDatabaseCollection{ Name: conversion.StringPtr(collectionFromConf.(map[string]any)["name"].(string)), - DataSources: conversion.NonEmptySliceToSlicePtr(newDataFederationDataSource(collectionFromConf.(map[string]any))), + DataSources: conversion.NonEmptyToPtr(newDataFederationDataSource(collectionFromConf.(map[string]any))), } } @@ -670,7 +670,7 @@ func newDataFederationDataSource(collectionFromConf map[string]any) []admin.Data ProvenanceFieldName: conversion.StringPtr(dataSourceFromConfMap["provenance_field_name"].(string)), StoreName: conversion.StringPtr(dataSourceFromConfMap["store_name"].(string)), DatasetName: conversion.StringPtr(dataSourceFromConfMap["dataset_name"].(string)), - Urls: conversion.NonEmptySliceToSlicePtr(newUrls(dataSourceFromConfMap["urls"].([]any))), + Urls: conversion.NonEmptyToPtr(newUrls(dataSourceFromConfMap["urls"].([]any))), } } diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index 341a335d98..e59856a4ea 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -237,7 +237,7 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderUpdate(ctx context.Con if d.HasChange("associated_domains") { associatedDomains := d.Get("associated_domains") - updateRequest.AssociatedDomains = conversion.NonEmptySliceToSlicePtr(cast.ToStringSlice(associatedDomains)) + updateRequest.AssociatedDomains = conversion.NonEmptyToPtr(cast.ToStringSlice(associatedDomains)) } if d.HasChange("name") { diff --git a/internal/service/project/model_project.go b/internal/service/project/model_project.go index eee5f5829c..f8e57e13ff 100644 --- a/internal/service/project/model_project.go +++ b/internal/service/project/model_project.go @@ -123,7 +123,7 @@ func NewTeamRoleList(ctx context.Context, teams []TfTeamModel) *[]admin.TeamRole for i, team := range teams { res[i] = admin.TeamRole{ TeamId: team.TeamID.ValueStringPointer(), - RoleNames: conversion.NonEmptySliceToSlicePtr(conversion.TypesSetToString(ctx, team.RoleNames)), + RoleNames: conversion.NonEmptyToPtr(conversion.TypesSetToString(ctx, team.RoleNames)), } } return &res diff --git a/internal/service/project/model_project_test.go b/internal/service/project/model_project_test.go index 3488b9f5c0..d756ea00fe 100644 --- a/internal/service/project/model_project_test.go +++ b/internal/service/project/model_project_test.go @@ -30,7 +30,7 @@ var ( teamRolesSDK = []admin.TeamRole{ { TeamId: conversion.StringPtr("teamId"), - RoleNames: conversion.NonEmptySliceToSlicePtr(roles), + RoleNames: conversion.NonEmptyToPtr(roles), }, } teamsDSTF = []*project.TfTeamDSModel{ @@ -88,7 +88,7 @@ func TestTeamsDataSourceSDKToTFModel(t *testing.T) { { name: "Complete TeamRole", paginatedTeamRole: &admin.PaginatedTeamRole{ - Results: conversion.NonEmptySliceToSlicePtr(teamRolesSDK), + Results: conversion.NonEmptyToPtr(teamRolesSDK), TotalCount: conversion.IntPtr(1), }, expectedTFModel: teamsDSTF, @@ -141,7 +141,7 @@ func TestProjectDataSourceSDKToTFModel(t *testing.T) { name: "Project", project: &projectSDK, teams: &admin.PaginatedTeamRole{ - Results: conversion.NonEmptySliceToSlicePtr(teamRolesSDK), + Results: conversion.NonEmptyToPtr(teamRolesSDK), TotalCount: conversion.IntPtr(1), }, projectSettings: &projectSettingsSDK, diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index 9eb79400b6..584699ddd4 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -675,7 +675,7 @@ func UpdateProjectTeams(ctx context.Context, client GroupProjectService, project _, _, err := client.UpdateTeamRoles(ctx, projectID, teamID, &admin.TeamRole{ - RoleNames: conversion.NonEmptySliceToSlicePtr(conversion.TypesSetToString(ctx, team.RoleNames)), + RoleNames: conversion.NonEmptyToPtr(conversion.TypesSetToString(ctx, team.RoleNames)), }, ) if err != nil { diff --git a/internal/service/searchdeployment/model_search_deployment.go b/internal/service/searchdeployment/model_search_deployment.go index 9569899b0c..8d322ea977 100644 --- a/internal/service/searchdeployment/model_search_deployment.go +++ b/internal/service/searchdeployment/model_search_deployment.go @@ -23,7 +23,7 @@ func NewSearchDeploymentReq(ctx context.Context, searchDeploymentPlan *TFSearchD } return admin.ApiSearchDeploymentRequest{ - Specs: conversion.NonEmptySliceToSlicePtr(resultSpecs), + Specs: conversion.NonEmptyToPtr(resultSpecs), } } diff --git a/internal/service/searchindex/resource_search_index.go b/internal/service/searchindex/resource_search_index.go index 2884b778e3..347970c5d3 100644 --- a/internal/service/searchindex/resource_search_index.go +++ b/internal/service/searchindex/resource_search_index.go @@ -224,7 +224,7 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndex.Analyzers = conversion.NonEmptySliceToSlicePtr(analyzers) + searchIndex.Analyzers = conversion.NonEmptyToPtr(analyzers) } if d.HasChange("mappings_dynamic") { @@ -251,11 +251,11 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndex.Fields = conversion.NonEmptySliceToSlicePtr(fields) + searchIndex.Fields = conversion.NonEmptyToPtr(fields) } if d.HasChange("synonyms") { - searchIndex.Synonyms = conversion.NonEmptySliceToSlicePtr(expandSearchIndexSynonyms(d)) + searchIndex.Synonyms = conversion.NonEmptyToPtr(expandSearchIndexSynonyms(d)) } searchIndex.IndexID = conversion.StringPtr("") @@ -413,7 +413,7 @@ func resourceMongoDBAtlasSearchIndexCreate(ctx context.Context, d *schema.Resour Name: d.Get("name").(string), SearchAnalyzer: conversion.StringPtr(d.Get("search_analyzer").(string)), Status: conversion.StringPtr(d.Get("status").(string)), - Synonyms: conversion.NonEmptySliceToSlicePtr(expandSearchIndexSynonyms(d)), + Synonyms: conversion.NonEmptyToPtr(expandSearchIndexSynonyms(d)), } if indexType == vectorSearch { @@ -421,13 +421,13 @@ func resourceMongoDBAtlasSearchIndexCreate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndexRequest.Fields = conversion.NonEmptySliceToSlicePtr(fields) + searchIndexRequest.Fields = conversion.NonEmptyToPtr(fields) } else { analyzers, err := unmarshalSearchIndexAnalyzersFields(d.Get("analyzers").(string)) if err != nil { return err } - searchIndexRequest.Analyzers = conversion.NonEmptySliceToSlicePtr(analyzers) + searchIndexRequest.Analyzers = conversion.NonEmptyToPtr(analyzers) mappingsFields, err := unmarshalSearchIndexMappingFields(d.Get("mappings_fields").(string)) if err != nil { return err From 5bdf6d04982e10d87bd4a3af02f005d999fee87c Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:18:15 +0100 Subject: [PATCH 19/21] add online_archive to old sdk comment --- internal/config/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/client.go b/internal/config/client.go index 4cffb723a4..4ae8813f9f 100644 --- a/internal/config/client.go +++ b/internal/config/client.go @@ -31,7 +31,7 @@ var ( type MongoDBClient struct { Atlas *matlasClient.Client AtlasV2 *atlasSDK.APIClient - OldAtlasV2 *oldAtlasSDK.APIClient // Needed to avoid sudden breaking changes in federated_settings_identity_provider resource. Will be removed in terraform-provider-1.16.0 + OldAtlasV2 *oldAtlasSDK.APIClient // Needed to avoid sudden breaking changes in federated_settings_identity_provider and online_archive resources. Will be removed in terraform-provider-1.16.0 Config *Config } From d475744cb8d66369097becf930f38a935f0b8f91 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:27:09 +0100 Subject: [PATCH 20/21] comment NonEmptyToPtr --- internal/common/conversion/type_conversion.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/common/conversion/type_conversion.go b/internal/common/conversion/type_conversion.go index 2ef66f7363..cedd7a392d 100644 --- a/internal/common/conversion/type_conversion.go +++ b/internal/common/conversion/type_conversion.go @@ -57,6 +57,7 @@ func MongoDBRegionToAWSRegion(region string) string { return strings.ReplaceAll(strings.ToLower(region), "_", "-") } +// NonEmptyToPtr accepts an array or slice and returns a pointer to it, except if it's empty, in that case it returns nil. func NonEmptyToPtr[T any](v []T) *[]T { if len(v) == 0 { return nil From 94879f46dcf01861e55be7e62ba8ee63f6387857 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:37:05 +0100 Subject: [PATCH 21/21] use date to refer to the old sdk version --- internal/config/client.go | 50 +++++++------- ...ce_federated_settings_identity_provider.go | 23 +++---- ...ce_federated_settings_identity_provider.go | 23 ++++--- .../data_source_online_archive.go | 9 +-- .../onlinearchive/resource_online_archive.go | 69 +++++++++---------- 5 files changed, 87 insertions(+), 87 deletions(-) diff --git a/internal/config/client.go b/internal/config/client.go index 4ae8813f9f..040a3ad858 100644 --- a/internal/config/client.go +++ b/internal/config/client.go @@ -12,8 +12,8 @@ import ( "github.com/mongodb-forks/digest" "github.com/mongodb/terraform-provider-mongodbatlas/version" "github.com/spf13/cast" - oldAtlasSDK "go.mongodb.org/atlas-sdk/v20231001002/admin" - atlasSDK "go.mongodb.org/atlas-sdk/v20231115003/admin" + admin20231001002 "go.mongodb.org/atlas-sdk/v20231001002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" matlasClient "go.mongodb.org/atlas/mongodbatlas" realmAuth "go.mongodb.org/realm/auth" "go.mongodb.org/realm/realm" @@ -29,10 +29,10 @@ var ( // MongoDBClient contains the mongodbatlas clients and configurations type MongoDBClient struct { - Atlas *matlasClient.Client - AtlasV2 *atlasSDK.APIClient - OldAtlasV2 *oldAtlasSDK.APIClient // Needed to avoid sudden breaking changes in federated_settings_identity_provider and online_archive resources. Will be removed in terraform-provider-1.16.0 - Config *Config + Atlas *matlasClient.Client + AtlasV2 *admin.APIClient + Atlas20231001002 *admin20231001002.APIClient // Needed to avoid breaking changes in federated_settings_identity_provider and online_archive resources. + Config *Config } // Config contains the configurations needed to use SDKs @@ -89,30 +89,30 @@ func (c *Config) NewClient(ctx context.Context) (any, error) { if err != nil { return nil, err } - sdkOldV2Client, err := c.newOldSDKV2Client(client) + sdk20231001002Client, err := c.newSDK20231001002Client(client) if err != nil { return nil, err } clients := &MongoDBClient{ - Atlas: atlasClient, - AtlasV2: sdkV2Client, - OldAtlasV2: sdkOldV2Client, - Config: c, + Atlas: atlasClient, + AtlasV2: sdkV2Client, + Atlas20231001002: sdk20231001002Client, + Config: c, } return clients, nil } -func (c *Config) newSDKV2Client(client *http.Client) (*atlasSDK.APIClient, error) { - opts := []atlasSDK.ClientModifier{ - atlasSDK.UseHTTPClient(client), - atlasSDK.UseUserAgent(userAgent), - atlasSDK.UseBaseURL(c.BaseURL), - atlasSDK.UseDebug(false)} +func (c *Config) newSDKV2Client(client *http.Client) (*admin.APIClient, error) { + opts := []admin.ClientModifier{ + admin.UseHTTPClient(client), + admin.UseUserAgent(userAgent), + admin.UseBaseURL(c.BaseURL), + admin.UseDebug(false)} // Initialize the MongoDB Versioned Atlas Client. - sdkv2, err := atlasSDK.NewClient(opts...) + sdkv2, err := admin.NewClient(opts...) if err != nil { return nil, err } @@ -120,15 +120,15 @@ func (c *Config) newSDKV2Client(client *http.Client) (*atlasSDK.APIClient, error return sdkv2, nil } -func (c *Config) newOldSDKV2Client(client *http.Client) (*oldAtlasSDK.APIClient, error) { - opts := []oldAtlasSDK.ClientModifier{ - oldAtlasSDK.UseHTTPClient(client), - oldAtlasSDK.UseUserAgent(userAgent), - oldAtlasSDK.UseBaseURL(c.BaseURL), - oldAtlasSDK.UseDebug(false)} +func (c *Config) newSDK20231001002Client(client *http.Client) (*admin20231001002.APIClient, error) { + opts := []admin20231001002.ClientModifier{ + admin20231001002.UseHTTPClient(client), + admin20231001002.UseUserAgent(userAgent), + admin20231001002.UseBaseURL(c.BaseURL), + admin20231001002.UseDebug(false)} // Initialize the MongoDB Versioned Atlas Client. - sdkv2, err := oldAtlasSDK.NewClient(opts...) + sdkv2, err := admin20231001002.NewClient(opts...) if err != nil { return nil, err } diff --git a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go index 6d6804a8a6..4142a45091 100644 --- a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go @@ -7,12 +7,11 @@ import ( "sort" "strings" - oldAdmin "go.mongodb.org/atlas-sdk/v20231001002/admin" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + admin20231001002 "go.mongodb.org/atlas-sdk/v20231001002/admin" ) func DataSource() *schema.Resource { @@ -292,8 +291,8 @@ func dataSourceMongoDBAtlasFederatedSettingsIdentityProviderRead(ctx context.Con } func oldSDKDSRead(ctx context.Context, federationSettingsID, idpID string, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 - federatedSettingsIdentityProvider, _, err := connOldV2.FederatedAuthenticationApi.GetIdentityProvider(ctx, federationSettingsID, idpID).Execute() + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 + federatedSettingsIdentityProvider, _, err := conn20231001002.FederatedAuthenticationApi.GetIdentityProvider(ctx, federationSettingsID, idpID).Execute() if err != nil { return diag.Errorf("error getting federatedSettings IdentityProviders assigned (%s): %s", federationSettingsID, err) } @@ -351,7 +350,7 @@ func oldSDKDSRead(ctx context.Context, federationSettingsID, idpID string, d *sc return nil } -func oldSDKFlattenAssociatedOrgs(associatedOrgs []oldAdmin.ConnectedOrgConfig) []map[string]any { +func oldSDKFlattenAssociatedOrgs(associatedOrgs []admin20231001002.ConnectedOrgConfig) []map[string]any { var associatedOrgsMap []map[string]any if len(associatedOrgs) == 0 { @@ -386,7 +385,7 @@ func oldSDKFlattenAssociatedOrgs(associatedOrgs []oldAdmin.ConnectedOrgConfig) [ return associatedOrgsMap } -func oldSDKFlattenFederatedUser(federatedUsers []oldAdmin.FederatedUser) []map[string]any { +func oldSDKFlattenFederatedUser(federatedUsers []admin20231001002.FederatedUser) []map[string]any { var userConflictsMap []map[string]any if len(federatedUsers) == 0 { @@ -407,7 +406,7 @@ func oldSDKFlattenFederatedUser(federatedUsers []oldAdmin.FederatedUser) []map[s return userConflictsMap } -type oldSDKAuthFederationoleMappingsByGroupName []oldAdmin.AuthFederationRoleMapping +type oldSDKAuthFederationoleMappingsByGroupName []admin20231001002.AuthFederationRoleMapping func (ra oldSDKAuthFederationoleMappingsByGroupName) Len() int { return len(ra) } func (ra oldSDKAuthFederationoleMappingsByGroupName) Swap(i, j int) { ra[i], ra[j] = ra[j], ra[i] } @@ -416,7 +415,7 @@ func (ra oldSDKAuthFederationoleMappingsByGroupName) Less(i, j int) bool { return ra[i].ExternalGroupName < ra[j].ExternalGroupName } -func oldSDKFlattenAuthFederationRoleMapping(roleMappings []oldAdmin.AuthFederationRoleMapping) []map[string]any { +func oldSDKFlattenAuthFederationRoleMapping(roleMappings []admin20231001002.AuthFederationRoleMapping) []map[string]any { sort.Sort(oldSDKAuthFederationoleMappingsByGroupName(roleMappings)) var roleMappingsMap []map[string]any @@ -436,7 +435,7 @@ func oldSDKFlattenAuthFederationRoleMapping(roleMappings []oldAdmin.AuthFederati return roleMappingsMap } -type mRoleAssignmentOldV2 []oldAdmin.RoleAssignment +type mRoleAssignmentOldV2 []admin20231001002.RoleAssignment func (ra mRoleAssignmentOldV2) Len() int { return len(ra) } func (ra mRoleAssignmentOldV2) Swap(i, j int) { ra[i], ra[j] = ra[j], ra[i] } @@ -456,7 +455,7 @@ func (ra mRoleAssignmentOldV2) Less(i, j int) bool { return *ra[i].Role < *ra[j].Role } -func oldSDKFlattenRoleAssignmentsV2(roleAssignments []oldAdmin.RoleAssignment) []map[string]any { +func oldSDKFlattenRoleAssignmentsV2(roleAssignments []admin20231001002.RoleAssignment) []map[string]any { sort.Sort(mRoleAssignmentOldV2(roleAssignments)) var roleAssignmentsMap []map[string]any @@ -476,7 +475,7 @@ func oldSDKFlattenRoleAssignmentsV2(roleAssignments []oldAdmin.RoleAssignment) [ return roleAssignmentsMap } -func oldSDKFlattenPemFileInfo(pemFileInfo oldAdmin.PemFileInfo) []map[string]any { +func oldSDKFlattenPemFileInfo(pemFileInfo admin20231001002.PemFileInfo) []map[string]any { var pemFileInfoMap []map[string]any if len(pemFileInfo.Certificates) > 0 { @@ -491,7 +490,7 @@ func oldSDKFlattenPemFileInfo(pemFileInfo oldAdmin.PemFileInfo) []map[string]any return pemFileInfoMap } -func oldSDKFlattenFederatedSettingsCertificates(certificates []oldAdmin.X509Certificate) []map[string]any { +func oldSDKFlattenFederatedSettingsCertificates(certificates []admin20231001002.X509Certificate) []map[string]any { var certificatesMap []map[string]any if len(certificates) > 0 { diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index e59856a4ea..f566e7db02 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -7,7 +7,7 @@ import ( "net/http" "regexp" - oldAdmin "go.mongodb.org/atlas-sdk/v20231001002/admin" + admin20231001002 "go.mongodb.org/atlas-sdk/v20231001002/admin" "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -154,8 +154,9 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderRead(ctx context.Conte } func oldSDKRead(federationSettingsID, oktaIdpID string, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 - federatedSettingsIdentityProvider, resp, err := connOldV2.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), federationSettingsID, oktaIdpID).Execute() + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 + + federatedSettingsIdentityProvider, resp, err := conn20231001002.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), federationSettingsID, oktaIdpID).Execute() if err != nil { // case 404 // deleted in the backend case @@ -281,9 +282,9 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderUpdate(ctx context.Con } func oldSDKUpdate(ctx context.Context, federationSettingsID, oktaIdpID string, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 - var updateRequest *oldAdmin.SamlIdentityProviderUpdate - _, _, err := connOldV2.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), federationSettingsID, oktaIdpID).Execute() + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 + var updateRequest *admin20231001002.SamlIdentityProviderUpdate + _, _, err := conn20231001002.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), federationSettingsID, oktaIdpID).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error retreiving federation settings identity provider (%s): %s", federationSettingsID, err)) @@ -331,7 +332,7 @@ func oldSDKUpdate(ctx context.Context, federationSettingsID, oktaIdpID string, d updateRequest.PemFileInfo = nil - _, _, err = connOldV2.FederatedAuthenticationApi.UpdateIdentityProvider(ctx, federationSettingsID, oktaIdpID, updateRequest).Execute() + _, _, err = conn20231001002.FederatedAuthenticationApi.UpdateIdentityProvider(ctx, federationSettingsID, oktaIdpID, updateRequest).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error updating federation settings identity provider (%s): %s", federationSettingsID, err)) } @@ -345,7 +346,7 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderDelete(ctx context.Con } func resourceMongoDBAtlasFederatedSettingsIdentityProviderImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 federationSettingsID, oktaIdpID, err := splitFederatedSettingsIdentityProviderImportID(d.Id()) if err != nil { return nil, err @@ -356,7 +357,7 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderImportState(ctx contex return oldSDKImport(federationSettingsID, oktaIdpID, d, meta) } - federatedSettingsIdentityProvider, _, err := connV2.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), *federationSettingsID, *oktaIdpID).Execute() + federatedSettingsIdentityProvider, _, err := conn20231001002.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), *federationSettingsID, *oktaIdpID).Execute() if err != nil { return nil, fmt.Errorf("couldn't import Organization config (%s) in Federation settings (%s), error: %s", *oktaIdpID, *federationSettingsID, err) } @@ -402,8 +403,8 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderImportState(ctx contex } func oldSDKImport(federationSettingsID, oktaIdpID *string, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 - federatedSettingsIdentityProvider, _, err := connOldV2.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), *federationSettingsID, *oktaIdpID).Execute() + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 + federatedSettingsIdentityProvider, _, err := conn20231001002.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), *federationSettingsID, *oktaIdpID).Execute() if err != nil { return nil, fmt.Errorf("couldn't import Organization config (%s) in Federation settings (%s), error: %s", *oktaIdpID, *federationSettingsID, err) } diff --git a/internal/service/onlinearchive/data_source_online_archive.go b/internal/service/onlinearchive/data_source_online_archive.go index 4ab5fb20c6..1f074126f2 100644 --- a/internal/service/onlinearchive/data_source_online_archive.go +++ b/internal/service/onlinearchive/data_source_online_archive.go @@ -216,12 +216,12 @@ func schemaOnlineArchive() map[string]*schema.Schema { } func dataSourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 projectID := d.Get("project_id").(string) clusterName := d.Get("cluster_name").(string) archiveID := d.Get("archive_id").(string) - archive, _, err := connOldV2.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() + archive, _, err := conn20231001002.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error reading Online Archive datasource with id %s: %s", archiveID, err.Error())) @@ -245,11 +245,12 @@ func dataSourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.Reso } func dataSourceMongoDBAtlasOnlineArchivesRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 + projectID := d.Get("project_id").(string) clusterName := d.Get("cluster_name").(string) - archives, _, err := connOldV2.OnlineArchiveApi.ListOnlineArchives(ctx, projectID, clusterName).Execute() + archives, _, err := conn20231001002.OnlineArchiveApi.ListOnlineArchives(ctx, projectID, clusterName).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error getting Online Archives list for project(%s) in cluster (%s): (%s)", projectID, clusterName, err.Error())) diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index a7c522e511..fc29255e45 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -9,8 +9,6 @@ import ( "strings" "time" - oldAdmin "go.mongodb.org/atlas-sdk/v20231001002/admin" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -18,6 +16,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mwielbut/pointy" + admin20231001002 "go.mongodb.org/atlas-sdk/v20231001002/admin" ) const ( @@ -219,12 +218,12 @@ func getMongoDBAtlasOnlineArchiveSchema() map[string]*schema.Schema { } func resourceMongoDBAtlasOnlineArchiveCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 projectID := d.Get("project_id").(string) clusterName := d.Get("cluster_name").(string) inputRequest := mapToArchivePayload(d) - outputRequest, _, err := connOldV2.OnlineArchiveApi.CreateOnlineArchive(ctx, projectID, clusterName, &inputRequest).Execute() + outputRequest, _, err := conn20231001002.OnlineArchiveApi.CreateOnlineArchive(ctx, projectID, clusterName, &inputRequest).Execute() if err != nil { return diag.FromErr(fmt.Errorf(errorOnlineArchivesCreate, err)) @@ -242,7 +241,7 @@ func resourceMongoDBAtlasOnlineArchiveCreate(ctx context.Context, d *schema.Reso stateConf := &retry.StateChangeConf{ Pending: []string{"PENDING", "ARCHIVING", "PAUSING", "PAUSED", "ORPHANED", "REPEATING"}, Target: []string{"IDLE", "ACTIVE"}, - Refresh: resourceOnlineRefreshFunc(ctx, projectID, clusterName, archiveID, connOldV2), + Refresh: resourceOnlineRefreshFunc(ctx, projectID, clusterName, archiveID, conn20231001002), Timeout: 3 * time.Hour, MinTimeout: 1 * time.Minute, Delay: 3 * time.Minute, @@ -258,7 +257,7 @@ func resourceMongoDBAtlasOnlineArchiveCreate(ctx context.Context, d *schema.Reso return resourceMongoDBAtlasOnlineArchiveRead(ctx, d, meta) } -func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, archiveID string, client *oldAdmin.APIClient) retry.StateRefreshFunc { +func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, archiveID string, client *admin20231001002.APIClient) retry.StateRefreshFunc { return func() (any, string, error) { c, resp, err := client.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() @@ -287,14 +286,14 @@ func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, arch } func resourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 ids := conversion.DecodeStateID(d.Id()) archiveID := ids["archive_id"] projectID := ids["project_id"] clusterName := ids["cluster_name"] - onlineArchive, resp, err := connOldV2.OnlineArchiveApi.GetOnlineArchive(context.Background(), projectID, archiveID, clusterName).Execute() + onlineArchive, resp, err := conn20231001002.OnlineArchiveApi.GetOnlineArchive(context.Background(), projectID, archiveID, clusterName).Execute() if err != nil { if resp != nil && resp.StatusCode == http.StatusNotFound { d.SetId("") @@ -334,7 +333,7 @@ func resourceMongoDBAtlasOnlineArchiveDelete(ctx context.Context, d *schema.Reso } func resourceMongoDBAtlasOnlineArchiveImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 parts := strings.Split(d.Id(), "-") var projectID, clusterName, archiveID string @@ -351,7 +350,7 @@ func resourceMongoDBAtlasOnlineArchiveImportState(ctx context.Context, d *schema projectID, clusterName, archiveID = parts[0], parts[1], parts[2] } - outOnlineArchive, _, err := connOldV2.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() + outOnlineArchive, _, err := conn20231001002.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() if err != nil { return nil, fmt.Errorf("could not import Online Archive %s in project %s, error %s", archiveID, projectID, err.Error()) @@ -378,9 +377,9 @@ func resourceMongoDBAtlasOnlineArchiveImportState(ctx context.Context, d *schema return []*schema.ResourceData{d}, nil } -func mapToArchivePayload(d *schema.ResourceData) oldAdmin.BackupOnlineArchiveCreate { +func mapToArchivePayload(d *schema.ResourceData) admin20231001002.BackupOnlineArchiveCreate { // shared input - requestInput := oldAdmin.BackupOnlineArchiveCreate{ + requestInput := admin20231001002.BackupOnlineArchiveCreate{ DbName: d.Get("db_name").(string), CollName: d.Get("coll_name").(string), } @@ -397,17 +396,17 @@ func mapToArchivePayload(d *schema.ResourceData) oldAdmin.BackupOnlineArchiveCre list := partitions.([]any) if len(list) > 0 { - partitionList := make([]oldAdmin.PartitionField, 0, len(list)) + partitionList := make([]admin20231001002.PartitionField, 0, len(list)) for _, partition := range list { item := partition.(map[string]any) - query := oldAdmin.PartitionField{ + query := admin20231001002.PartitionField{ FieldName: item["field_name"].(string), Order: item["order"].(int), } if dbType, ok := item["field_type"]; ok && dbType != nil { if dbType.(string) != "" { - query.FieldType = oldAdmin.PtrString(dbType.(string)) + query.FieldType = admin20231001002.PtrString(dbType.(string)) } } @@ -422,7 +421,7 @@ func mapToArchivePayload(d *schema.ResourceData) oldAdmin.BackupOnlineArchiveCre } func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 ids := conversion.DecodeStateID(d.Id()) @@ -444,7 +443,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso return nil } - request := oldAdmin.BackupOnlineArchive{} + request := admin20231001002.BackupOnlineArchive{} // reading current value if pausedHasChange { @@ -460,7 +459,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso newExpirationRule := mapDataExpirationRule(d) if newExpirationRule == nil { // expiration rule has been removed from tf config, empty dataExpirationRule object needs to be sent in patch request - request.DataExpirationRule = &oldAdmin.DataExpirationRule{} + request.DataExpirationRule = &admin20231001002.DataExpirationRule{} } else { request.DataExpirationRule = newExpirationRule } @@ -469,7 +468,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso if dataProcessRegionHasChange { newDataProcessRegion := mapDataProcessRegion(d) if newDataProcessRegion == nil { - request.DataProcessRegion = &oldAdmin.DataProcessRegion{} + request.DataProcessRegion = &admin20231001002.DataProcessRegion{} } else { request.DataProcessRegion = newDataProcessRegion } @@ -480,10 +479,10 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso } if collType := d.Get("collection_type").(string); collectionTypeHasChange && collType != "" { - request.CollectionType = oldAdmin.PtrString(collType) + request.CollectionType = admin20231001002.PtrString(collType) } - _, _, err := connOldV2.OnlineArchiveApi.UpdateOnlineArchive(ctx, projectID, atlasID, clusterName, &request).Execute() + _, _, err := conn20231001002.OnlineArchiveApi.UpdateOnlineArchive(ctx, projectID, atlasID, clusterName, &request).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error updating Mongo Online Archive id: %s %s", atlasID, err.Error())) @@ -492,7 +491,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso return resourceMongoDBAtlasOnlineArchiveRead(ctx, d, meta) } -func fromOnlineArchiveToMap(in *oldAdmin.BackupOnlineArchive) map[string]any { +func fromOnlineArchiveToMap(in *admin20231001002.BackupOnlineArchive) map[string]any { // computed attribute schemaVals := map[string]any{ "cluster_name": in.ClusterName, @@ -587,10 +586,10 @@ func fromOnlineArchiveToMap(in *oldAdmin.BackupOnlineArchive) map[string]any { return schemaVals } -func mapDataExpirationRule(d *schema.ResourceData) *oldAdmin.DataExpirationRule { +func mapDataExpirationRule(d *schema.ResourceData) *admin20231001002.DataExpirationRule { if dataExpireRules, ok := d.GetOk("data_expiration_rule"); ok && len(dataExpireRules.([]any)) > 0 { dataExpireRule := dataExpireRules.([]any)[0].(map[string]any) - result := oldAdmin.DataExpirationRule{} + result := admin20231001002.DataExpirationRule{} if expireAfterDays, ok := dataExpireRule["expire_after_days"]; ok { result.ExpireAfterDays = pointy.Int(expireAfterDays.(int)) } @@ -599,10 +598,10 @@ func mapDataExpirationRule(d *schema.ResourceData) *oldAdmin.DataExpirationRule return nil } -func mapDataProcessRegion(d *schema.ResourceData) *oldAdmin.DataProcessRegion { +func mapDataProcessRegion(d *schema.ResourceData) *admin20231001002.DataProcessRegion { if dataProcessRegions, ok := d.GetOk("data_process_region"); ok && len(dataProcessRegions.([]any)) > 0 { dataProcessRegion := dataProcessRegions.([]any)[0].(map[string]any) - result := oldAdmin.DataProcessRegion{} + result := admin20231001002.DataProcessRegion{} if cloudProvider, ok := dataProcessRegion["cloud_provider"]; ok { result.CloudProvider = pointy.String(cloudProvider.(string)) } @@ -614,31 +613,31 @@ func mapDataProcessRegion(d *schema.ResourceData) *oldAdmin.DataProcessRegion { return nil } -func mapCriteria(d *schema.ResourceData) oldAdmin.Criteria { +func mapCriteria(d *schema.ResourceData) admin20231001002.Criteria { criteriaList := d.Get("criteria").([]any) criteria := criteriaList[0].(map[string]any) - criteriaInput := oldAdmin.Criteria{ - Type: oldAdmin.PtrString(criteria["type"].(string)), + criteriaInput := admin20231001002.Criteria{ + Type: admin20231001002.PtrString(criteria["type"].(string)), } if criteriaInput.Type != nil && *criteriaInput.Type == "DATE" { if dateField := criteria["date_field"].(string); dateField != "" { - criteriaInput.DateField = oldAdmin.PtrString(dateField) + criteriaInput.DateField = admin20231001002.PtrString(dateField) } criteriaInput.ExpireAfterDays = pointy.Int(criteria["expire_after_days"].(int)) // optional if dformat, ok := criteria["date_format"]; ok && dformat.(string) != "" { - criteriaInput.DateFormat = oldAdmin.PtrString(dformat.(string)) + criteriaInput.DateFormat = admin20231001002.PtrString(dformat.(string)) } } if criteriaInput.Type != nil && *criteriaInput.Type == "CUSTOM" { if query := criteria["query"].(string); query != "" { - criteriaInput.Query = oldAdmin.PtrString(query) + criteriaInput.Query = admin20231001002.PtrString(query) } } @@ -646,11 +645,11 @@ func mapCriteria(d *schema.ResourceData) oldAdmin.Criteria { return criteriaInput } -func mapSchedule(d *schema.ResourceData) *oldAdmin.OnlineArchiveSchedule { +func mapSchedule(d *schema.ResourceData) *admin20231001002.OnlineArchiveSchedule { // scheduleInput := &matlas.OnlineArchiveSchedule{ // We have to provide schedule.type="DEFAULT" when the schedule block is not provided or removed - scheduleInput := &oldAdmin.OnlineArchiveSchedule{ + scheduleInput := &admin20231001002.OnlineArchiveSchedule{ Type: scheduleTypeDefault, } @@ -669,7 +668,7 @@ func mapSchedule(d *schema.ResourceData) *oldAdmin.OnlineArchiveSchedule { } scheduleTFConfig := scheduleTFConfigList[0].(map[string]any) - scheduleInput = &oldAdmin.OnlineArchiveSchedule{ + scheduleInput = &admin20231001002.OnlineArchiveSchedule{ Type: scheduleTFConfig["type"].(string), }