From 27df3ca9090d7d14bbeb77c415620bb4e77e47a8 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/46] 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 c2e5a407cb6922f6c8799e34cb2b9fd57850a39d 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/46] 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 258cff2eac5bbc8caf493b7c345cb2cc9711fa01 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/46] 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 25ea035e4adf9f54e3ab10ced2c33f0fa9a184f5 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/46] 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 b3e01d938f5a0c09daf583de5da8f4ea3809fc83 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/46] 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 8c4856527a12479ac2090569d4453440958035f0 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/46] 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 23793e58bd6b34f57cb4e7289a4aab6ad2cc36b2 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/46] 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 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 08/46] 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 09/46] 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 10/46] 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 11/46] 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 12/46] 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 13/46] 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 14/46] 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 15/46] 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 37c0ace438a4b7cd62babaa9eac89399312424a8 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 11:56:53 +0000 Subject: [PATCH 16/46] upgrade to atlas sdk --- .../organization/data_source_organization.go | 9 ++- .../organization/resource_organization.go | 54 +++++++++------ .../resource_organization_migration_test.go | 49 ++++++++++++++ .../resource_organization_test.go | 67 +++++++++++++++---- 4 files changed, 141 insertions(+), 38 deletions(-) create mode 100644 internal/service/organization/resource_organization_migration_test.go diff --git a/internal/service/organization/data_source_organization.go b/internal/service/organization/data_source_organization.go index cb6bd83283..f582e147db 100644 --- a/internal/service/organization/data_source_organization.go +++ b/internal/service/organization/data_source_organization.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -47,10 +48,12 @@ func DataSource() *schema.Resource { func dataSourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { // Get client connection. - conn := meta.(*config.MongoDBClient).Atlas + conn := meta.(*config.MongoDBClient).AtlasV2 orgID := d.Get("org_id").(string) - organization, _, err := conn.Organizations.Get(ctx, orgID) + // organization, _, err := conn.Organizations.Get(ctx, orgID) + organization, _, err := conn.OrganizationsApi.GetOrganization(ctx, orgID).Execute() + if err != nil { return diag.FromErr(fmt.Errorf("error getting organizations information: %s", err)) } @@ -67,7 +70,7 @@ func dataSourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("error setting `is_deleted`: %s", err)) } - d.SetId(organization.ID) + d.SetId(*organization.Id) return nil } diff --git a/internal/service/organization/resource_organization.go b/internal/service/organization/resource_organization.go index 91085ffb18..b255a19cd5 100644 --- a/internal/service/organization/resource_organization.go +++ b/internal/service/organization/resource_organization.go @@ -6,12 +6,14 @@ import ( "log" "net/http" + "go.mongodb.org/atlas-sdk/v20231115002/admin" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mwielbut/pointy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "github.com/mwielbut/pointy" - matlas "go.mongodb.org/atlas/mongodbatlas" ) func Resource() *schema.Resource { @@ -64,8 +66,8 @@ func Resource() *schema.Resource { } func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - conn := meta.(*config.MongoDBClient).Atlas - organization, resp, err := conn.Organizations.Create(ctx, newCreateOrganizationRequest(d)) + conn := meta.(*config.MongoDBClient).AtlasV2 + organization, resp, err := conn.OrganizationsApi.CreateOrganization(ctx, newCreateOrganizationRequest(d)).Execute() if err != nil { if resp != nil && resp.StatusCode == http.StatusNotFound { d.SetId("") @@ -75,25 +77,34 @@ func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("error create Organization: %s", err)) } - if err := d.Set("private_key", organization.APIKey.PrivateKey); err != nil { + if err := d.Set("private_key", organization.ApiKey.PrivateKey); err != nil { return diag.FromErr(fmt.Errorf("error setting `private_key`: %s", err)) } - if err := d.Set("public_key", organization.APIKey.PublicKey); err != nil { + if err := d.Set("public_key", organization.ApiKey.PublicKey); err != nil { return diag.FromErr(fmt.Errorf("error setting `public_key`: %s", err)) } - if err := d.Set("org_id", organization.Organization.ID); err != nil { + if err := d.Set("org_id", *organization.Organization.Id); err != nil { return diag.FromErr(fmt.Errorf("error setting `org_id`: %s", err)) } d.SetId(conversion.EncodeStateID(map[string]string{ - "org_id": organization.Organization.ID, + "org_id": *organization.Organization.Id, })) return resourceMongoDBAtlasOrganizationRead(ctx, d, meta) } +// func validateSchema(d *schema.ResourceData) error { +// if !conversion.IsStringPresent(d.Get("org_owner_id").(*string)) { + +// } +// if + +// return nil +// } + func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { // Get client connection. cfg := config.Config{ @@ -103,12 +114,12 @@ func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resourc } clients, _ := cfg.NewClient(ctx) - conn := clients.(*config.MongoDBClient).Atlas + conn := clients.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) orgID := ids["org_id"] - organization, resp, err := conn.Organizations.Get(ctx, orgID) + organization, resp, err := conn.OrganizationsApi.GetOrganization(ctx, orgID).Execute() if err != nil { if resp != nil && resp.StatusCode == http.StatusNotFound { log.Printf("warning Organization deleted will recreate: %s \n", err.Error()) @@ -118,7 +129,7 @@ func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resourc return diag.FromErr(fmt.Errorf("error reading organization information: %s", err)) } d.SetId(conversion.EncodeStateID(map[string]string{ - "org_id": organization.ID, + "org_id": *organization.Id, })) return nil } @@ -132,14 +143,14 @@ func resourceMongoDBAtlasOrganizationUpdate(ctx context.Context, d *schema.Resou } clients, _ := cfg.NewClient(ctx) - conn := clients.(*config.MongoDBClient).Atlas + conn := clients.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) orgID := ids["org_id"] - updateRequest := new(matlas.Organization) + updateRequest := new(admin.AtlasOrganization) if d.HasChange("name") { updateRequest.Name = d.Get("name").(string) - _, _, err := conn.Organizations.Update(ctx, orgID, updateRequest) + _, _, err := conn.OrganizationsApi.RenameOrganization(ctx, orgID, updateRequest).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error updating Organization: %s", err)) } @@ -156,28 +167,29 @@ func resourceMongoDBAtlasOrganizationDelete(ctx context.Context, d *schema.Resou } clients, _ := cfg.NewClient(ctx) - conn := clients.(*config.MongoDBClient).Atlas + conn := clients.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) orgID := ids["org_id"] - if _, err := conn.Organizations.Delete(ctx, orgID); err != nil { + if _, _, err := conn.OrganizationsApi.DeleteOrganization(ctx, orgID).Execute(); err != nil { return diag.FromErr(fmt.Errorf("error Organization: %s", err)) } return nil } -func newCreateOrganizationRequest(d *schema.ResourceData) *matlas.CreateOrganizationRequest { - createRequest := &matlas.CreateOrganizationRequest{ +func newCreateOrganizationRequest(d *schema.ResourceData) *admin.CreateOrganizationRequest { + createRequest := &admin.CreateOrganizationRequest{ Name: d.Get("name").(string), - OrgOwnerID: pointy.String(d.Get("org_owner_id").(string)), - APIKey: &matlas.APIKeyInput{ + OrgOwnerId: pointy.String(d.Get("org_owner_id").(string)), + + ApiKey: &admin.CreateAtlasOrganizationApiKey{ Roles: conversion.ExpandStringList(d.Get("role_names").(*schema.Set).List()), Desc: d.Get("description").(string), }, } if federationSettingsID, ok := d.Get("federation_settings_id").(string); ok && federationSettingsID != "" { - createRequest.FederationSettingsID = &federationSettingsID + createRequest.FederationSettingsId = &federationSettingsID } return createRequest diff --git a/internal/service/organization/resource_organization_migration_test.go b/internal/service/organization/resource_organization_migration_test.go new file mode 100644 index 0000000000..75d01b9b2c --- /dev/null +++ b/internal/service/organization/resource_organization_migration_test.go @@ -0,0 +1,49 @@ +package organization_test + +import ( + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" + + "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig" +) + +func TestAccMigrationConfigRSOrganization_Basic(t *testing.T) { + acc.SkipTestForCI(t) + var ( + resourceName = "mongodbatlas_organization.test" + orgOwnerID = os.Getenv("MONGODB_ATLAS_ORG_OWNER_ID") + name = fmt.Sprintf("test-acc-organization-%s", acctest.RandString(5)) + description = "test Key for Acceptance tests" + roleName = "ORG_OWNER" + ) + + resource.Test(t, resource.TestCase{ + Steps: []resource.TestStep{ + { + ExternalProviders: mig.ExternalProviders(), + Config: testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, name, description, roleName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "org_id"), + resource.TestCheckResourceAttrSet(resourceName, "description"), + resource.TestCheckResourceAttr(resourceName, "description", description), + ), + }, + { + ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, + Config: testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, name, description, roleName), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + acc.DebugPlan(), + plancheck.ExpectEmptyPlan(), + }, + }, + }, + }, + }) +} diff --git a/internal/service/organization/resource_organization_test.go b/internal/service/organization/resource_organization_test.go index f4a442ffe8..893a04c31a 100644 --- a/internal/service/organization/resource_organization_test.go +++ b/internal/service/organization/resource_organization_test.go @@ -9,10 +9,10 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "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" - matlas "go.mongodb.org/atlas/mongodbatlas" ) func TestAccConfigRSOrganization_Basic(t *testing.T) { @@ -39,14 +39,21 @@ func TestAccConfigRSOrganization_Basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "description", description), ), }, + { + Config: testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, "org-name-updated", description, roleName), + Check: resource.ComposeTestCheckFunc( + testAccCheckMongoDBAtlasOrganizationExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "org_id"), + resource.TestCheckResourceAttrSet(resourceName, "description"), + resource.TestCheckResourceAttr(resourceName, "description", description), + ), + }, }, }) } func testAccCheckMongoDBAtlasOrganizationExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - rs, ok := s.RootModule().Resources[resourceName] if !ok { return fmt.Errorf("not found: %s", resourceName) @@ -56,17 +63,34 @@ func testAccCheckMongoDBAtlasOrganizationExists(resourceName string) resource.Te return fmt.Errorf("no ID is set") } + if rs.Primary.Attributes["public_key"] == "" { + return fmt.Errorf("no public_key is set") + } + + if rs.Primary.Attributes["private_key"] == "" { + return fmt.Errorf("no private_key is set") + } + ids := conversion.DecodeStateID(rs.Primary.ID) - organizationOptions := &matlas.OrganizationsListOptions{} - orgs, _, err := conn.Organizations.List(context.Background(), organizationOptions) + cfg := config.Config{ + PublicKey: rs.Primary.Attributes["public_key"], + PrivateKey: rs.Primary.Attributes["private_key"], + BaseURL: acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Config.BaseURL, + } + + ctx := context.Background() + clients, _ := cfg.NewClient(ctx) + conn := clients.(*config.MongoDBClient).AtlasV2 + + orgs, _, err := conn.OrganizationsApi.ListOrganizations(ctx).Execute() if err == nil { for _, val := range orgs.Results { - if val.ID == ids["org_id"] { - return fmt.Errorf("Organization (%s) still exists", ids["role_name"]) + if *val.Id == ids["org_id"] { + return nil } } - return nil + return fmt.Errorf("Organization (%s) doesn't exist", ids["org_id"]) } return nil @@ -74,21 +98,36 @@ func testAccCheckMongoDBAtlasOrganizationExists(resourceName string) resource.Te } func testAccCheckMongoDBAtlasOrganizationDestroy(s *terraform.State) error { - conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas - for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_organization" { continue } + if rs.Primary.Attributes["public_key"] == "" { + return fmt.Errorf("no public_key is set") + } + + if rs.Primary.Attributes["private_key"] == "" { + return fmt.Errorf("no private_key is set") + } + ids := conversion.DecodeStateID(rs.Primary.ID) - organizationOptions := &matlas.OrganizationsListOptions{} - orgs, _, err := conn.Organizations.List(context.Background(), organizationOptions) + cfg := config.Config{ + PublicKey: rs.Primary.Attributes["public_key"], + PrivateKey: rs.Primary.Attributes["private_key"], + BaseURL: acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Config.BaseURL, + } + + ctx := context.Background() + clients, _ := cfg.NewClient(ctx) + conn := clients.(*config.MongoDBClient).AtlasV2 + + orgs, _, err := conn.OrganizationsApi.ListOrganizations(context.Background()).Execute() if err == nil { for _, val := range orgs.Results { - if val.ID == ids["org_id"] { - return fmt.Errorf("Organization (%s) still exists", ids["role_name"]) + if *val.Id == ids["org_id"] { + return fmt.Errorf("Organization (%s) still exists", ids["org_id"]) } } return nil From d9ca6cc388d5b3dccebb8db99aaea97d6e63ab44 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 11:57:09 +0000 Subject: [PATCH 17/46] upgrade plural DS to atlas sdk --- .../organization/data_source_organizations.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/service/organization/data_source_organizations.go b/internal/service/organization/data_source_organizations.go index 0d613c5e50..66f9ad6ff2 100644 --- a/internal/service/organization/data_source_organizations.go +++ b/internal/service/organization/data_source_organizations.go @@ -4,13 +4,14 @@ import ( "context" "fmt" + "go.mongodb.org/atlas-sdk/v20231115002/admin" + "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/config" "github.com/mwielbut/pointy" - matlas "go.mongodb.org/atlas/mongodbatlas" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) func PluralDataSource() *schema.Resource { @@ -79,20 +80,22 @@ func PluralDataSource() *schema.Resource { func dataSourceMongoDBAtlasOrganizationsRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { // Get client connection. - conn := meta.(*config.MongoDBClient).Atlas + conn := meta.(*config.MongoDBClient).AtlasV2 options := &matlas.ListOptions{ PageNum: d.Get("page_num").(int), ItemsPerPage: d.Get("items_per_page").(int), } - organizationOptions := &matlas.OrganizationsListOptions{ + organizationOptions := &*admin.ListOrganizationsApiParams{ Name: d.Get("name").(string), IncludeDeletedOrgs: pointy.Bool(d.Get("include_deleted_orgs").(bool)), ListOptions: *options, } organizations, _, err := conn.Organizations.List(ctx, organizationOptions) + organizations, _, err := conn.OrganizationsApi.ListOrganizationsWithParams(ctx) + if err != nil { return diag.FromErr(fmt.Errorf("error getting organization information: %s", err)) } @@ -110,7 +113,7 @@ func dataSourceMongoDBAtlasOrganizationsRead(ctx context.Context, d *schema.Reso return nil } -func flattenOrganizationLinks(links []*matlas.Link) []map[string]any { +func flattenOrganizationLinks(links []admin.Link) []map[string]any { linksList := make([]map[string]any, 0) for _, link := range links { From db96b10a6c42d613967916a822bc1293dcd7a870 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 17:04:03 +0000 Subject: [PATCH 18/46] migrate plural DS to new atlas SDK --- .../organization/data_source_organizations.go | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/internal/service/organization/data_source_organizations.go b/internal/service/organization/data_source_organizations.go index 66f9ad6ff2..b88907acc9 100644 --- a/internal/service/organization/data_source_organizations.go +++ b/internal/service/organization/data_source_organizations.go @@ -82,19 +82,13 @@ func dataSourceMongoDBAtlasOrganizationsRead(ctx context.Context, d *schema.Reso // Get client connection. conn := meta.(*config.MongoDBClient).AtlasV2 - options := &matlas.ListOptions{ - PageNum: d.Get("page_num").(int), - ItemsPerPage: d.Get("items_per_page").(int), + organizationOptions := &admin.ListOrganizationsApiParams{ + PageNum: pointy.Int(d.Get("page_num").(int)), + ItemsPerPage: pointy.Int(d.Get("items_per_page").(int)), + Name: pointy.String(d.Get("name").(string)), } - organizationOptions := &*admin.ListOrganizationsApiParams{ - Name: d.Get("name").(string), - IncludeDeletedOrgs: pointy.Bool(d.Get("include_deleted_orgs").(bool)), - ListOptions: *options, - } - - organizations, _, err := conn.Organizations.List(ctx, organizationOptions) - organizations, _, err := conn.OrganizationsApi.ListOrganizationsWithParams(ctx) + organizations, _, err := conn.OrganizationsApi.ListOrganizationsWithParams(ctx, organizationOptions).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error getting organization information: %s", err)) @@ -127,7 +121,7 @@ func flattenOrganizationLinks(links []admin.Link) []map[string]any { return linksList } -func flattenOrganizations(organizations []*matlas.Organization) []map[string]any { +func flattenOrganizations(organizations []admin.AtlasOrganization) []map[string]any { var results []map[string]any if len(organizations) == 0 { @@ -138,7 +132,7 @@ func flattenOrganizations(organizations []*matlas.Organization) []map[string]any for k, organization := range organizations { results[k] = map[string]any{ - "id": organization.ID, + "id": organization.Id, "name": organization.Name, "is_deleted": organization.IsDeleted, "links": flattenOrganizationLinks(organization.Links), From 479afb8b0459c1cd8c7b9185eef5f540fc7a6e71 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 17:12:28 +0000 Subject: [PATCH 19/46] migrate plural DS to new atlas SDK --- .../service/organization/data_source_organization.go | 1 - internal/service/organization/resource_organization.go | 9 --------- 2 files changed, 10 deletions(-) diff --git a/internal/service/organization/data_source_organization.go b/internal/service/organization/data_source_organization.go index f582e147db..18b9549902 100644 --- a/internal/service/organization/data_source_organization.go +++ b/internal/service/organization/data_source_organization.go @@ -51,7 +51,6 @@ func dataSourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resou conn := meta.(*config.MongoDBClient).AtlasV2 orgID := d.Get("org_id").(string) - // organization, _, err := conn.Organizations.Get(ctx, orgID) organization, _, err := conn.OrganizationsApi.GetOrganization(ctx, orgID).Execute() if err != nil { diff --git a/internal/service/organization/resource_organization.go b/internal/service/organization/resource_organization.go index b255a19cd5..da81d4a3c4 100644 --- a/internal/service/organization/resource_organization.go +++ b/internal/service/organization/resource_organization.go @@ -96,15 +96,6 @@ func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.Resou return resourceMongoDBAtlasOrganizationRead(ctx, d, meta) } -// func validateSchema(d *schema.ResourceData) error { -// if !conversion.IsStringPresent(d.Get("org_owner_id").(*string)) { - -// } -// if - -// return nil -// } - func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { // Get client connection. cfg := config.Config{ From c98bab9ffcb31bcaf126513a778032aa8073999e Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 17:38:19 +0000 Subject: [PATCH 20/46] migrate plural DS to new atlas SDK --- internal/service/organization/data_source_organizations.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/service/organization/data_source_organizations.go b/internal/service/organization/data_source_organizations.go index b88907acc9..6520b30dbb 100644 --- a/internal/service/organization/data_source_organizations.go +++ b/internal/service/organization/data_source_organizations.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mwielbut/pointy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -23,8 +24,9 @@ func PluralDataSource() *schema.Resource { Optional: true, }, "include_deleted_orgs": { - Type: schema.TypeBool, - Optional: true, + Type: schema.TypeBool, + Optional: true, + Deprecated: fmt.Sprintf(constant.DeprecationParamByDate, "January 2025"), }, "page_num": { Type: schema.TypeInt, From f9146094db3a1d50971603537ea672840479ea3b Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 17:53:26 +0000 Subject: [PATCH 21/46] update sdk to latest --- internal/service/organization/data_source_organizations.go | 2 +- internal/service/organization/resource_organization.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/organization/data_source_organizations.go b/internal/service/organization/data_source_organizations.go index 6520b30dbb..793786812c 100644 --- a/internal/service/organization/data_source_organizations.go +++ b/internal/service/organization/data_source_organizations.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/organization/resource_organization.go b/internal/service/organization/resource_organization.go index da81d4a3c4..318cea3392 100644 --- a/internal/service/organization/resource_organization.go +++ b/internal/service/organization/resource_organization.go @@ -6,7 +6,7 @@ import ( "log" "net/http" - "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" From 08593318a64313b48db2f1a019739f17539dc7fa Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 17:58:40 +0000 Subject: [PATCH 22/46] update sdk to latest --- go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/go.mod b/go.mod index 84a44ac9fd..a0a594d924 100644 --- a/go.mod +++ b/go.mod @@ -128,6 +128,7 @@ require ( github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty-yaml v1.0.2 // indirect + go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.17.0 // indirect golang.org/x/mod v0.14.0 // indirect From 7a1caae0b1d34eeba4057736c21f558a5dc3b55e Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 18:16:38 +0000 Subject: [PATCH 23/46] update sdk to latest --- internal/config/client.go | 10 ++++++---- .../service/organization/data_source_organization.go | 3 ++- .../service/organization/data_source_organizations.go | 5 +++-- .../service/organization/resource_organization_test.go | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/config/client.go b/internal/config/client.go index 4cffb723a4..5fc1fb3ec6 100644 --- a/internal/config/client.go +++ b/internal/config/client.go @@ -8,15 +8,17 @@ import ( "net/url" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" - "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" matlasClient "go.mongodb.org/atlas/mongodbatlas" realmAuth "go.mongodb.org/realm/auth" "go.mongodb.org/realm/realm" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" + "github.com/mongodb-forks/digest" + "github.com/spf13/cast" + + "github.com/mongodb/terraform-provider-mongodbatlas/version" ) const ( diff --git a/internal/service/organization/data_source_organization.go b/internal/service/organization/data_source_organization.go index 18b9549902..e5f0b45ded 100644 --- a/internal/service/organization/data_source_organization.go +++ b/internal/service/organization/data_source_organization.go @@ -7,6 +7,7 @@ import ( "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" ) @@ -65,7 +66,7 @@ func dataSourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("error setting `is_deleted`: %s", err)) } - if err := d.Set("links", flattenOrganizationLinks(organization.Links)); err != nil { + if err := d.Set("links", flattenOrganizationLinks(conversion.SlicePtrToSlice(organization.Links))); err != nil { return diag.FromErr(fmt.Errorf("error setting `is_deleted`: %s", err)) } diff --git a/internal/service/organization/data_source_organizations.go b/internal/service/organization/data_source_organizations.go index 793786812c..5d4efa0f6a 100644 --- a/internal/service/organization/data_source_organizations.go +++ b/internal/service/organization/data_source_organizations.go @@ -12,6 +12,7 @@ import ( "github.com/mwielbut/pointy" "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" ) @@ -96,7 +97,7 @@ func dataSourceMongoDBAtlasOrganizationsRead(ctx context.Context, d *schema.Reso return diag.FromErr(fmt.Errorf("error getting organization information: %s", err)) } - if err := d.Set("results", flattenOrganizations(organizations.Results)); err != nil { + if err := d.Set("results", flattenOrganizations(conversion.SlicePtrToSlice(organizations.Results))); err != nil { return diag.FromErr(fmt.Errorf("error setting `results`: %s", err)) } @@ -137,7 +138,7 @@ func flattenOrganizations(organizations []admin.AtlasOrganization) []map[string] "id": organization.Id, "name": organization.Name, "is_deleted": organization.IsDeleted, - "links": flattenOrganizationLinks(organization.Links), + "links": flattenOrganizationLinks(conversion.SlicePtrToSlice(organization.Links)), } } diff --git a/internal/service/organization/resource_organization_test.go b/internal/service/organization/resource_organization_test.go index 893a04c31a..25398bfebe 100644 --- a/internal/service/organization/resource_organization_test.go +++ b/internal/service/organization/resource_organization_test.go @@ -85,7 +85,7 @@ func testAccCheckMongoDBAtlasOrganizationExists(resourceName string) resource.Te orgs, _, err := conn.OrganizationsApi.ListOrganizations(ctx).Execute() if err == nil { - for _, val := range orgs.Results { + for _, val := range *orgs.Results { if *val.Id == ids["org_id"] { return nil } @@ -125,7 +125,7 @@ func testAccCheckMongoDBAtlasOrganizationDestroy(s *terraform.State) error { orgs, _, err := conn.OrganizationsApi.ListOrganizations(context.Background()).Execute() if err == nil { - for _, val := range orgs.Results { + for _, val := range *orgs.Results { if *val.Id == ids["org_id"] { return fmt.Errorf("Organization (%s) still exists", ids["org_id"]) } 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 24/46] 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 0ab62a38a43f70435c4a0d77bc745e50c25381f7 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 19:20:23 +0000 Subject: [PATCH 25/46] fix merge --- CONTRIBUTING.md | 55 +++++++++++++++++++++++++++++++++++--- GNUmakefile | 12 +++++++-- go.mod | 1 - internal/config/client.go | 10 +++---- scripts/generate-doc.sh | 2 +- scripts/schema-scaffold.sh | 54 +++++++++++++++++++++++++++++++++++++ 6 files changed, 121 insertions(+), 13 deletions(-) create mode 100644 scripts/schema-scaffold.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f80dafa4e2..d160a71eb2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,7 +12,10 @@ Thanks for your interest in contributing to MongoDB Atlas Terraform Provider, th - [Running Acceptance Tests](#running-acceptance-tests) - [Code and Test Best Practices](#code-and-test-best-practices) - [Creating New Resource and Data Sources](#creating-new-resources-and-data-sources) + - [Scaffolding Initial Code and File Structure](#scaffolding-initial-code-and-file-structure) + - [Scaffolding Schema and Model Definitions](#scaffolding-schema-and-model-definitions) - [Documentation Best Practices](#documentation-best-practices) + - [Creating Resource and Data source Documentation](#creating-resource-and-data-source-documentation) - [Discovering New API features](#discovering-new-api-features) @@ -309,21 +312,67 @@ To do this you can: ### Creating New Resource and Data Sources -A scaffolding command was defined with the intention of speeding up development process, while also preserving common conventions throughout our codebase. +A set of commands have been defined with the intention of speeding up development process, while also preserving common conventions throughout our codebase. + +#### Scaffolding Initial Code and File Structure This command can be used the following way: ```bash -make scaffold name=streamInstance type=resource +make scaffold resource_name=streamInstance type=resource ``` -- **name**: The name of the resource, which must be defined in camel case. +- **resource_name**: The name of the resource, which must be defined in camel case. - **type**: Describes the type of resource being created. There are 3 different types: `resource`, `data-source`, `plural-data-source`. This will generate resource/data source files and accompanying test files needed for starting the development, and will contain multiple comments with `TODO:` statements which give guidance for the development. +#### Scaffolding Schema and Model Definitions + +Complementary to the `scaffold` command, there is a command which generates the initial Terraform schema definition and associated Go types for a resource or data source. This processes leverages [Code Generation Tools](https://developer.hashicorp.com/terraform/plugin/code-generation) developed by HashiCorp, which in turn make use of the [Atlas Admin API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/) OpenAPI Specification. + +##### Running the command + +Both `tfplugingen-openapi` and `tfplugingen-framework` must be installed. This can be done by running `make tools`. + +The command takes a single argument which specifies the resource or data source where the code generation is run, defined in camel case, e.g.: +```bash +make scaffold-schemas resource_name=streamInstance +``` + +As a pre-requiste, the relevant resource/data source directory must define a configuration file in the path `./internal/service//tfplugingen/generator_config.yml`. The content of this file will define which resource and/or data source schemas will be generated by providing the API endpoints they are mapped to. See the [Generator Config](https://developer.hashicorp.com/terraform/plugin/code-generation/openapi-generator#generator-config) documentation for more information on configuration options. An example defined in our repository can be found in [searchdeployment/tfplugingen/generator_config.yml](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/internal/service/searchdeployment/tfplugingen/generator_config.yml). + +As a result of the execution, the schema definitions and associated model types will be defined in separate files depending on the resources and data sources that were configured in the generator_config.yml file: +- `data_source__schema.go` +- `resource__schema.go` + +Note: if the resulting file paths already exist the content will be stored in files with a `_gen.go` postfix, and in this case any content will be overwritten. This can be useful for comparing the latest autogenerated schema against the existing implementation. + +##### Considerations over generated schema and types + +- Generated Go type should include a TF prefix to follow the convention in our codebase, this will not be present in generated code. +- Some attribute names may need to be adjusted if there is a difference in how they are named in Terraform vs the API. An examples of this is `group_id` → `project_id`. +- Inferred characteristics of an attribute (computed, optional, required) may not always be an accurate representation and should be revised. Details of inference logic can be found in [OAS Types to Provider Attributes](https://github.com/hashicorp/terraform-plugin-codegen-openapi/blob/main/DESIGN.md#oas-types-to-provider-attributes). +- Missing [sensitive](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/attributes/string#sensitive) field in attributes. +- Missing plan modifiers such as `RequiresReplace()` in attributes. +- Terraform specific attributes such as [timeouts](https://developer.hashicorp.com/terraform/plugin/framework/resources/timeouts#specifying-timeouts-in-configuration) need to be included manually. +- If nested attributes are defined a set of helper functions are generated for using the model. The usage of the generated functions can be considered optional as the current documentation is not very clear on the usage (More details in [terraform-plugin-codegen-framework/issues/80](https://github.com/hashicorp/terraform-plugin-codegen-framework/issues/80)). + + ## Documentation Best Practices - In our documentation, when a resource field allows a maximum of only one item, we do not format that field as an array. Instead, we create a subsection specifically for this field. Within this new subsection, we enumerate all the attributes of the field. Let's illustrate this with an example: [cloud_backup_schedule.html.markdown](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/website/docs/r/cloud_backup_schedule.html.markdown?plain=1#L207) +### Creating Resource and Data source Documentation +We autogenerate the documentation of our provider resources and data sources via [tfplugindocs](https://github.com/hashicorp/terraform-plugin-docs). + +#### How to generate the documentation for a resource +- Make sure that the resource and data source schemas have defined the fields `MarkdownDescription` and `Description`. + - We recommend to use [Scaffolding Schema and Model Definitions](#scaffolding-schema-and-model-definitions) to autogenerate the schema via the Open API specification. +- Add the resource/data source templates to the [templates](templates) folder. See [README.md](templates/README.md) for more info. +- Run the Makefile command `generate-doc` +```bash +export resource_name=search_deployment && make generate-doc +``` + ## Discovering New API features Most of the new features of the provider are using [atlas-sdk](https://github.com/mongodb/atlas-sdk-go) diff --git a/GNUmakefile b/GNUmakefile index 7756a4cc73..a68b4d3f7f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -115,12 +115,20 @@ link-git-hooks: ## Install git hooks update-atlas-sdk: ## Update the atlas-sdk dependency ./scripts/update-sdk.sh -# details on usage can be found in CONTRIBUTING.md under "Creating New Resource and Data Sources" +# e.g. run: make scaffold resource_name=streamInstance type=resource +# - type argument can have the values: `resource`, `data-source`, `plural-data-source`. +# details on usage can be found in CONTRIBUTING.md under "Scaffolding initial Code and File Structure" .PHONY: scaffold scaffold: - @go run ./tools/scaffold/*.go $(name) $(type) + @go run ./tools/scaffold/*.go $(resource_name) $(type) @echo "Reminder: configure the new $(type) in provider.go" +# e.g. run: make scaffold-schemas resource_name=streamInstance +# details on usage can be found in CONTRIBUTING.md under "Scaffolding Schema and Model Definitions" +.PHONY: scaffold-schemas +scaffold-schemas: + @scripts/schema-scaffold.sh $(resource_name) + .PHONY: generate-doc generate-doc: ## Generate the resource documentation via tfplugindocs diff --git a/go.mod b/go.mod index a0a594d924..84a44ac9fd 100644 --- a/go.mod +++ b/go.mod @@ -128,7 +128,6 @@ require ( github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty-yaml v1.0.2 // indirect - go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.17.0 // indirect golang.org/x/mod v0.14.0 // indirect diff --git a/internal/config/client.go b/internal/config/client.go index 5fc1fb3ec6..4cffb723a4 100644 --- a/internal/config/client.go +++ b/internal/config/client.go @@ -8,17 +8,15 @@ import ( "net/url" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" + "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" matlasClient "go.mongodb.org/atlas/mongodbatlas" realmAuth "go.mongodb.org/realm/auth" "go.mongodb.org/realm/realm" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" - "github.com/mongodb-forks/digest" - "github.com/spf13/cast" - - "github.com/mongodb/terraform-provider-mongodbatlas/version" ) const ( diff --git a/scripts/generate-doc.sh b/scripts/generate-doc.sh index 5b48017132..60a92a248f 100755 --- a/scripts/generate-doc.sh +++ b/scripts/generate-doc.sh @@ -32,7 +32,7 @@ set -euo pipefail -TF_VERSION="${TF_VERSION:-"1.6"}" # TF version to use when running tfplugindocs. Default: 1.6.6 +TF_VERSION="${TF_VERSION:-"1.6"}" # TF version to use when running tfplugindocs. Default: 1.6 TEMPLATE_FOLDER_PATH="${TEMPLATE_FOLDER_PATH:-"templates"}" # PATH to the templates folder. Default: templates diff --git a/scripts/schema-scaffold.sh b/scripts/schema-scaffold.sh new file mode 100644 index 0000000000..fb79fad5fc --- /dev/null +++ b/scripts/schema-scaffold.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -euo pipefail + +: "${1?"Name of resource or data source must be provided."}" + +# URL to download Atlas Admin API Spec +atlas_admin_api_spec="https://raw.githubusercontent.com/mongodb/atlas-sdk-go/main/openapi/atlas-api-transformed.yaml" + +echo "Downloading api spec" +curl -L "$atlas_admin_api_spec" -o "./api-spec.yml" + +resource_name=$1 +resource_name_lower_case="$(echo "$resource_name" | awk '{print tolower($0)}')" +resource_name_snake_case="$(echo "$resource_name" | perl -pe 's/([a-z0-9])([A-Z])/$1_\L$2/g')" + +pushd "./internal/service/$resource_name_lower_case" || exit + +# Running HashiCorp code generation tools + +echo "Generating provider code specification" +# Generate provider code specification using api spec and generator config +tfplugingen-openapi generate --config ./tfplugingen/generator_config.yml --output provider-code-spec.json ../../../api-spec.yml + +echo "Generating resource and data source schemas and models" +# Generate resource and data sources schemas using provider code specification +tfplugingen-framework generate data-sources --input provider-code-spec.json --output ./ --package "$resource_name_lower_case" +tfplugingen-framework generate resources --input provider-code-spec.json --output ./ --package "$resource_name_lower_case" + + +rm ../../../api-spec.yml +rm provider-code-spec.json + + +rename_file() { + local old_name=$1 + local new_name=$2 + + # Check if the original file exists + if [ -e "$old_name" ]; then + # If the target new name exists, use the alternative name with _gen + if [ -e "$new_name" ]; then + echo "File $new_name already exists, writing content in ${new_name%.*}_gen.go" + new_name="${new_name%.*}_gen.go" + fi + + echo "Created file in $new_name" + # Rename the file + mv "$old_name" "$new_name" + fi +} + +rename_file "${resource_name_snake_case}_data_source_gen.go" "data_source_${resource_name_snake_case}_schema.go" +rename_file "${resource_name_snake_case}s_data_source_gen.go" "data_source_${resource_name_snake_case}s_schema.go" +rename_file "${resource_name_snake_case}_resource_gen.go" "resource_${resource_name_snake_case}_schema.go" From 1d8dec4f11b5c35252f7cb8ecc081ab7fab6d8ab Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 19:27:51 +0000 Subject: [PATCH 26/46] fix merge --- internal/service/onlinearchive/data_source_online_archive.go | 1 - internal/service/onlinearchive/resource_online_archive.go | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/service/onlinearchive/data_source_online_archive.go b/internal/service/onlinearchive/data_source_online_archive.go index ffdf3d1b37..4ab5fb20c6 100644 --- a/internal/service/onlinearchive/data_source_online_archive.go +++ b/internal/service/onlinearchive/data_source_online_archive.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/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index a9e10bfd15..a7c522e511 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -15,10 +15,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/mwielbut/pointy" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mwielbut/pointy" ) const ( @@ -415,7 +414,7 @@ func mapToArchivePayload(d *schema.ResourceData) oldAdmin.BackupOnlineArchiveCre partitionList = append(partitionList, query) } - requestInput.PartitionFields = conversion.NonEmptySliceToPtrSlice(partitionList) + requestInput.PartitionFields = partitionList } } From b7818a946eac7c29284a7f02a00b3ea97376a465 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Wed, 10 Jan 2024 12:32:26 +0000 Subject: [PATCH 27/46] add new API support --- .../organization/resource_organization.go | 89 ++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/internal/service/organization/resource_organization.go b/internal/service/organization/resource_organization.go index 318cea3392..d285f77dfd 100644 --- a/internal/service/organization/resource_organization.go +++ b/internal/service/organization/resource_organization.go @@ -61,6 +61,21 @@ func Resource() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "api_access_list_required": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "multi_factor_auth_required": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "restrict_employee_access": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, }, } } @@ -77,6 +92,28 @@ func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("error create Organization: %s", err)) } + orgID := *organization.Organization.Id + + // update settings using new keys for this created org + cfg := config.Config{ + PublicKey: *organization.ApiKey.PublicKey, + PrivateKey: *organization.ApiKey.PrivateKey, + BaseURL: meta.(*config.MongoDBClient).Config.BaseURL, + } + + clients, _ := cfg.NewClient(ctx) + conn = clients.(*config.MongoDBClient).AtlasV2 + + _, _, err = conn.OrganizationsApi.UpdateOrganizationSettings(ctx, orgID, newOrganizationSettings(d)).Execute() + if err != nil { + if _, _, err := conn.OrganizationsApi.DeleteOrganization(ctx, orgID).Execute(); err != nil { + d.SetId("") + return diag.FromErr(fmt.Errorf("unable to delete organization because of create failure. An error occurred when updating Organization settings: %s", err)) + } + + return diag.FromErr(fmt.Errorf("error create Organization: %s", err)) + } + if err := d.Set("private_key", organization.ApiKey.PrivateKey); err != nil { return diag.FromErr(fmt.Errorf("error setting `private_key`: %s", err)) } @@ -110,6 +147,7 @@ func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resourc ids := conversion.DecodeStateID(d.Id()) orgID := ids["org_id"] + // organization, resp, err := conn.Organizations.Get(ctx, orgID) organization, resp, err := conn.OrganizationsApi.GetOrganization(ctx, orgID).Execute() if err != nil { if resp != nil && resp.StatusCode == http.StatusNotFound { @@ -119,6 +157,23 @@ func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resourc } return diag.FromErr(fmt.Errorf("error reading organization information: %s", err)) } + + if err := d.Set("name", organization.Name); err != nil { + return diag.Errorf("error setting `name` for organization (%s): %s", *organization.Id, err) + } + + settings, _, err := conn.OrganizationsApi.GetOrganizationSettings(ctx, orgID).Execute() + + if err := d.Set("api_access_list_required", settings.ApiAccessListRequired); err != nil { + return diag.Errorf("error setting `api_access_list_required` for organization (%s): %s", orgID, err) + } + if err := d.Set("multi_factor_auth_required", settings.MultiFactorAuthRequired); err != nil { + return diag.Errorf("error setting `multi_factor_auth_required` for organization (%s): %s", orgID, err) + } + if err := d.Set("restrict_employee_access", settings.RestrictEmployeeAccess); err != nil { + return diag.Errorf("error setting `restrict_employee_access` for organization (%s): %s", orgID, err) + } + d.SetId(conversion.EncodeStateID(map[string]string{ "org_id": *organization.Id, })) @@ -143,9 +198,16 @@ func resourceMongoDBAtlasOrganizationUpdate(ctx context.Context, d *schema.Resou updateRequest.Name = d.Get("name").(string) _, _, err := conn.OrganizationsApi.RenameOrganization(ctx, orgID, updateRequest).Execute() if err != nil { - return diag.FromErr(fmt.Errorf("error updating Organization: %s", err)) + return diag.FromErr(fmt.Errorf("error updating Organization name: %s", err)) } } + + if d.HasChange("api_access_list_required") || d.HasChange("multi_factor_auth_required") || d.HasChange("restrict_employee_access") { + if _, _, err := conn.OrganizationsApi.UpdateOrganizationSettings(ctx, orgID, newOrganizationSettings(d)).Execute(); err != nil { + return diag.FromErr(fmt.Errorf("error updating Organization settings: %s", err)) + } + } + return resourceMongoDBAtlasOrganizationRead(ctx, d, meta) } @@ -168,6 +230,23 @@ func resourceMongoDBAtlasOrganizationDelete(ctx context.Context, d *schema.Resou return nil } +// func newCreateOrganizationRequest(d *schema.ResourceData) *matlas.CreateOrganizationRequest { +// createRequest := &matlas.CreateOrganizationRequest{ +// Name: d.Get("name").(string), +// OrgOwnerID: pointy.String(d.Get("org_owner_id").(string)), +// APIKey: &matlas.APIKeyInput{ +// Roles: conversion.ExpandStringList(d.Get("role_names").(*schema.Set).List()), +// Desc: d.Get("description").(string), +// }, +// } + +// if federationSettingsID, ok := d.Get("federation_settings_id").(string); ok && federationSettingsID != "" { +// createRequest.FederationSettingsID = &federationSettingsID +// } + +// return createRequest +// } + func newCreateOrganizationRequest(d *schema.ResourceData) *admin.CreateOrganizationRequest { createRequest := &admin.CreateOrganizationRequest{ Name: d.Get("name").(string), @@ -185,3 +264,11 @@ func newCreateOrganizationRequest(d *schema.ResourceData) *admin.CreateOrganizat return createRequest } + +func newOrganizationSettings(d *schema.ResourceData) *admin.OrganizationSettings { + return &admin.OrganizationSettings{ + ApiAccessListRequired: pointy.Bool(d.Get("api_access_list_required").(bool)), + MultiFactorAuthRequired: pointy.Bool(d.Get("multi_factor_auth_required").(bool)), + RestrictEmployeeAccess: pointy.Bool(d.Get("restrict_employee_access").(bool)), + } +} From 5dd60dfbec932edb1153dd1bcb56a426f355bd22 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 22:23:07 +0000 Subject: [PATCH 28/46] add new APIs and params --- .../organization/data_source_organization.go | 26 ++++++++ .../data_source_organization_test.go | 11 +++- .../organization/data_source_organizations.go | 33 ++++++++-- .../data_source_organizations_test.go | 4 ++ .../organization/resource_organization.go | 48 +++++++------- .../resource_organization_test.go | 63 +++++++++++++++++++ 6 files changed, 152 insertions(+), 33 deletions(-) diff --git a/internal/service/organization/data_source_organization.go b/internal/service/organization/data_source_organization.go index e5f0b45ded..9981961514 100644 --- a/internal/service/organization/data_source_organization.go +++ b/internal/service/organization/data_source_organization.go @@ -43,6 +43,18 @@ func DataSource() *schema.Resource { }, }, }, + "api_access_list_required": { + Type: schema.TypeBool, + Computed: true, + }, + "multi_factor_auth_required": { + Type: schema.TypeBool, + Computed: true, + }, + "restrict_employee_access": { + Type: schema.TypeBool, + Computed: true, + }, }, } } @@ -70,6 +82,20 @@ func dataSourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("error setting `is_deleted`: %s", err)) } + settings, _, err := conn.OrganizationsApi.GetOrganizationSettings(ctx, orgID).Execute() + if err != nil { + return diag.FromErr(fmt.Errorf("error getting organization settings: %s", err)) + } + if err := d.Set("api_access_list_required", settings.ApiAccessListRequired); err != nil { + return diag.Errorf("error setting `api_access_list_required` for organization (%s): %s", orgID, err) + } + if err := d.Set("multi_factor_auth_required", settings.MultiFactorAuthRequired); err != nil { + return diag.Errorf("error setting `multi_factor_auth_required` for organization (%s): %s", orgID, err) + } + if err := d.Set("restrict_employee_access", settings.RestrictEmployeeAccess); err != nil { + return diag.Errorf("error setting `restrict_employee_access` for organization (%s): %s", orgID, err) + } + d.SetId(*organization.Id) return nil diff --git a/internal/service/organization/data_source_organization_test.go b/internal/service/organization/data_source_organization_test.go index d6623d807e..1aebdaebfa 100644 --- a/internal/service/organization/data_source_organization_test.go +++ b/internal/service/organization/data_source_organization_test.go @@ -6,12 +6,14 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) func TestAccConfigDSOrganization_basic(t *testing.T) { var ( - orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + datasourceName = "data.mongodbatlas_organization.test" ) resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, @@ -19,8 +21,11 @@ func TestAccConfigDSOrganization_basic(t *testing.T) { { Config: testAccMongoDBAtlasOrganizationConfigWithDS(orgID), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.mongodbatlas_organization.test", "name"), - resource.TestCheckResourceAttrSet("data.mongodbatlas_organization.test", "id"), + resource.TestCheckResourceAttrSet(datasourceName, "name"), + resource.TestCheckResourceAttrSet(datasourceName, "id"), + resource.TestCheckResourceAttrSet(datasourceName, "restrict_employee_access"), + resource.TestCheckResourceAttrSet(datasourceName, "multi_factor_auth_required"), + resource.TestCheckResourceAttrSet(datasourceName, "api_access_list_required"), ), }, }, diff --git a/internal/service/organization/data_source_organizations.go b/internal/service/organization/data_source_organizations.go index 5d4efa0f6a..feab29ce6a 100644 --- a/internal/service/organization/data_source_organizations.go +++ b/internal/service/organization/data_source_organizations.go @@ -3,6 +3,7 @@ package organization import ( "context" "fmt" + "log" "go.mongodb.org/atlas-sdk/v20231115003/admin" @@ -70,6 +71,18 @@ func PluralDataSource() *schema.Resource { }, }, }, + "api_access_list_required": { + Type: schema.TypeBool, + Computed: true, + }, + "multi_factor_auth_required": { + Type: schema.TypeBool, + Computed: true, + }, + "restrict_employee_access": { + Type: schema.TypeBool, + Computed: true, + }, }, }, }, @@ -97,7 +110,7 @@ func dataSourceMongoDBAtlasOrganizationsRead(ctx context.Context, d *schema.Reso return diag.FromErr(fmt.Errorf("error getting organization information: %s", err)) } - if err := d.Set("results", flattenOrganizations(conversion.SlicePtrToSlice(organizations.Results))); err != nil { + if err := d.Set("results", flattenOrganizations(ctx, conn, conversion.SlicePtrToSlice(organizations.Results))); err != nil { return diag.FromErr(fmt.Errorf("error setting `results`: %s", err)) } @@ -124,7 +137,7 @@ func flattenOrganizationLinks(links []admin.Link) []map[string]any { return linksList } -func flattenOrganizations(organizations []admin.AtlasOrganization) []map[string]any { +func flattenOrganizations(ctx context.Context, conn *admin.APIClient, organizations []admin.AtlasOrganization) []map[string]any { var results []map[string]any if len(organizations) == 0 { @@ -134,11 +147,19 @@ func flattenOrganizations(organizations []admin.AtlasOrganization) []map[string] results = make([]map[string]any, len(organizations)) for k, organization := range organizations { + settings, _, err := conn.OrganizationsApi.GetOrganizationSettings(ctx, *organization.Id).Execute() + if err != nil { + log.Printf("[WARN] Error getting organization settings (organization ID: %s): %s", *organization.Id, err) + + } results[k] = map[string]any{ - "id": organization.Id, - "name": organization.Name, - "is_deleted": organization.IsDeleted, - "links": flattenOrganizationLinks(conversion.SlicePtrToSlice(organization.Links)), + "id": organization.Id, + "name": organization.Name, + "is_deleted": organization.IsDeleted, + "links": flattenOrganizationLinks(conversion.SlicePtrToSlice(organization.Links)), + "api_access_list_required": settings.ApiAccessListRequired, + "multi_factor_auth_required": settings.MultiFactorAuthRequired, + "restrict_employee_access": settings.RestrictEmployeeAccess, } } diff --git a/internal/service/organization/data_source_organizations_test.go b/internal/service/organization/data_source_organizations_test.go index a867862db1..2dfec7cec3 100644 --- a/internal/service/organization/data_source_organizations_test.go +++ b/internal/service/organization/data_source_organizations_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -21,6 +22,9 @@ func TestAccConfigDSOrganizations_basic(t *testing.T) { resource.TestCheckResourceAttrSet(datasourceName, "results.#"), resource.TestCheckResourceAttrSet(datasourceName, "results.0.name"), resource.TestCheckResourceAttrSet(datasourceName, "results.0.id"), + resource.TestCheckResourceAttrSet(datasourceName, "results.0.restrict_employee_access"), + resource.TestCheckResourceAttrSet(datasourceName, "results.0.multi_factor_auth_required"), + resource.TestCheckResourceAttrSet(datasourceName, "results.0.api_access_list_required"), ), }, }, diff --git a/internal/service/organization/resource_organization.go b/internal/service/organization/resource_organization.go index d285f77dfd..24d0883c43 100644 --- a/internal/service/organization/resource_organization.go +++ b/internal/service/organization/resource_organization.go @@ -81,6 +81,10 @@ func Resource() *schema.Resource { } func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { + if !isAPIKeyOrgOwner(conversion.ExpandStringList(d.Get("role_names").(*schema.Set).List())) { + return diag.FromErr(fmt.Errorf("`role_names` for new API Key must have the ORG_OWNER role to use this resource")) + } + conn := meta.(*config.MongoDBClient).AtlasV2 organization, resp, err := conn.OrganizationsApi.CreateOrganization(ctx, newCreateOrganizationRequest(d)).Execute() if err != nil { @@ -89,12 +93,13 @@ func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.Resou return nil } - return diag.FromErr(fmt.Errorf("error create Organization: %s", err)) + return diag.FromErr(fmt.Errorf("error creating Organization: %s", err)) } orgID := *organization.Organization.Id - // update settings using new keys for this created org + // update settings using new keys for this created organization because + // the provider/requesting API keys are not applicable for performing updates/delete for this new organization cfg := config.Config{ PublicKey: *organization.ApiKey.PublicKey, PrivateKey: *organization.ApiKey.PrivateKey, @@ -108,10 +113,10 @@ func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.Resou if err != nil { if _, _, err := conn.OrganizationsApi.DeleteOrganization(ctx, orgID).Execute(); err != nil { d.SetId("") - return diag.FromErr(fmt.Errorf("unable to delete organization because of create failure. An error occurred when updating Organization settings: %s", err)) + return diag.FromErr(fmt.Errorf("an error occurred when updating Organization settings. Unable to delete organization, there may be dangling resources: %s", err)) } - - return diag.FromErr(fmt.Errorf("error create Organization: %s", err)) + d.SetId("") + return diag.FromErr(fmt.Errorf("error setting Organization setings: %s", err)) } if err := d.Set("private_key", organization.ApiKey.PrivateKey); err != nil { @@ -122,7 +127,7 @@ func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("error setting `public_key`: %s", err)) } - if err := d.Set("org_id", *organization.Organization.Id); err != nil { + if err := d.Set("org_id", orgID); err != nil { return diag.FromErr(fmt.Errorf("error setting `org_id`: %s", err)) } @@ -147,7 +152,6 @@ func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resourc ids := conversion.DecodeStateID(d.Id()) orgID := ids["org_id"] - // organization, resp, err := conn.Organizations.Get(ctx, orgID) organization, resp, err := conn.OrganizationsApi.GetOrganization(ctx, orgID).Execute() if err != nil { if resp != nil && resp.StatusCode == http.StatusNotFound { @@ -163,6 +167,9 @@ func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resourc } settings, _, err := conn.OrganizationsApi.GetOrganizationSettings(ctx, orgID).Execute() + if err != nil { + return diag.FromErr(fmt.Errorf("error reading organization settings: %s", err)) + } if err := d.Set("api_access_list_required", settings.ApiAccessListRequired); err != nil { return diag.Errorf("error setting `api_access_list_required` for organization (%s): %s", orgID, err) @@ -230,23 +237,6 @@ func resourceMongoDBAtlasOrganizationDelete(ctx context.Context, d *schema.Resou return nil } -// func newCreateOrganizationRequest(d *schema.ResourceData) *matlas.CreateOrganizationRequest { -// createRequest := &matlas.CreateOrganizationRequest{ -// Name: d.Get("name").(string), -// OrgOwnerID: pointy.String(d.Get("org_owner_id").(string)), -// APIKey: &matlas.APIKeyInput{ -// Roles: conversion.ExpandStringList(d.Get("role_names").(*schema.Set).List()), -// Desc: d.Get("description").(string), -// }, -// } - -// if federationSettingsID, ok := d.Get("federation_settings_id").(string); ok && federationSettingsID != "" { -// createRequest.FederationSettingsID = &federationSettingsID -// } - -// return createRequest -// } - func newCreateOrganizationRequest(d *schema.ResourceData) *admin.CreateOrganizationRequest { createRequest := &admin.CreateOrganizationRequest{ Name: d.Get("name").(string), @@ -272,3 +262,13 @@ func newOrganizationSettings(d *schema.ResourceData) *admin.OrganizationSettings RestrictEmployeeAccess: pointy.Bool(d.Get("restrict_employee_access").(bool)), } } + +func isAPIKeyOrgOwner(roles []string) bool { + for _, role := range roles { + if role == "ORG_OWNER" { + return true + } + } + + return false +} diff --git a/internal/service/organization/resource_organization_test.go b/internal/service/organization/resource_organization_test.go index 25398bfebe..b40b96f441 100644 --- a/internal/service/organization/resource_organization_test.go +++ b/internal/service/organization/resource_organization_test.go @@ -52,6 +52,56 @@ func TestAccConfigRSOrganization_Basic(t *testing.T) { }) } +func TestAccConfigRSOrganization_Settings(t *testing.T) { + acc.SkipTestForCI(t) + var ( + resourceName = "mongodbatlas_organization.test" + orgOwnerID = os.Getenv("MONGODB_ATLAS_ORG_OWNER_ID") + name = fmt.Sprintf("test-acc-organization-%s", acctest.RandString(5)) + description = "test Key for Acceptance tests" + roleName = "ORG_OWNER" + + settingsConfig = ` + api_access_list_required = false + restrict_employee_access = true` + settingsConfigUpdated = ` + api_access_list_required = false + multi_factor_auth_required = true + restrict_employee_access = false` + ) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.PreCheck(t) }, + ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, + CheckDestroy: testAccCheckMongoDBAtlasOrganizationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMongoDBAtlasOrganizationConfigWithSettings(orgOwnerID, name, description, roleName, settingsConfig), + Check: resource.ComposeTestCheckFunc( + testAccCheckMongoDBAtlasOrganizationExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "org_id"), + resource.TestCheckResourceAttrSet(resourceName, "description"), + resource.TestCheckResourceAttr(resourceName, "description", description), + resource.TestCheckResourceAttr(resourceName, "api_access_list_required", "false"), + resource.TestCheckResourceAttr(resourceName, "restrict_employee_access", "true"), + ), + }, + { + Config: testAccMongoDBAtlasOrganizationConfigWithSettings(orgOwnerID, "org-name-updated", description, roleName, settingsConfigUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckMongoDBAtlasOrganizationExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "org_id"), + resource.TestCheckResourceAttrSet(resourceName, "description"), + resource.TestCheckResourceAttr(resourceName, "description", description), + resource.TestCheckResourceAttr(resourceName, "api_access_list_required", "false"), + resource.TestCheckResourceAttr(resourceName, "multi_factor_auth_required", "true"), + resource.TestCheckResourceAttr(resourceName, "restrict_employee_access", "false"), + ), + }, + }, + }) +} + func testAccCheckMongoDBAtlasOrganizationExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] @@ -147,3 +197,16 @@ func testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, name, description, r } `, orgOwnerID, name, description, roleNames) } + +func testAccMongoDBAtlasOrganizationConfigWithSettings(orgOwnerID, name, description, roleNames, settingsConfig string) string { + return fmt.Sprintf(` + resource "mongodbatlas_organization" "test" { + org_owner_id = "%s" + name = "%s" + description = "%s" + role_names = ["%s"] + + %s + } + `, orgOwnerID, name, description, roleNames, settingsConfig) +} From a64c3c2129e4aa8bdb0455b54f289dc707dae548 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 12 Jan 2024 22:29:46 +0000 Subject: [PATCH 29/46] add new APIs and params --- internal/service/organization/data_source_organizations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/organization/data_source_organizations.go b/internal/service/organization/data_source_organizations.go index feab29ce6a..fe3dfdfe92 100644 --- a/internal/service/organization/data_source_organizations.go +++ b/internal/service/organization/data_source_organizations.go @@ -150,8 +150,8 @@ func flattenOrganizations(ctx context.Context, conn *admin.APIClient, organizati settings, _, err := conn.OrganizationsApi.GetOrganizationSettings(ctx, *organization.Id).Execute() if err != nil { log.Printf("[WARN] Error getting organization settings (organization ID: %s): %s", *organization.Id, err) - } + results[k] = map[string]any{ "id": organization.Id, "name": organization.Name, 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 30/46] 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 31/46] 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 32/46] 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 33/46] 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 34/46] 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 70c5afa82fcc3db86dd1769379d763210e9dbb02 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 15 Jan 2024 13:42:38 +0000 Subject: [PATCH 35/46] minor --- internal/service/organization/data_source_organization.go | 3 +-- internal/service/organization/data_source_organizations.go | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/service/organization/data_source_organization.go b/internal/service/organization/data_source_organization.go index e5f0b45ded..b1024f6516 100644 --- a/internal/service/organization/data_source_organization.go +++ b/internal/service/organization/data_source_organization.go @@ -7,7 +7,6 @@ import ( "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" ) @@ -66,7 +65,7 @@ func dataSourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("error setting `is_deleted`: %s", err)) } - if err := d.Set("links", flattenOrganizationLinks(conversion.SlicePtrToSlice(organization.Links))); err != nil { + if err := d.Set("links", flattenOrganizationLinks(organization.GetLinks())); err != nil { return diag.FromErr(fmt.Errorf("error setting `is_deleted`: %s", err)) } diff --git a/internal/service/organization/data_source_organizations.go b/internal/service/organization/data_source_organizations.go index 5d4efa0f6a..5737d86c5f 100644 --- a/internal/service/organization/data_source_organizations.go +++ b/internal/service/organization/data_source_organizations.go @@ -12,7 +12,6 @@ import ( "github.com/mwielbut/pointy" "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" ) @@ -97,11 +96,11 @@ func dataSourceMongoDBAtlasOrganizationsRead(ctx context.Context, d *schema.Reso return diag.FromErr(fmt.Errorf("error getting organization information: %s", err)) } - if err := d.Set("results", flattenOrganizations(conversion.SlicePtrToSlice(organizations.Results))); err != nil { + if err := d.Set("results", flattenOrganizations(organizations.GetResults())); err != nil { return diag.FromErr(fmt.Errorf("error setting `results`: %s", err)) } - if err := d.Set("total_count", organizations.TotalCount); err != nil { + if err := d.Set("total_count", organizations.GetTotalCount()); err != nil { return diag.FromErr(fmt.Errorf("error setting `total_count`: %s", err)) } @@ -138,7 +137,7 @@ func flattenOrganizations(organizations []admin.AtlasOrganization) []map[string] "id": organization.Id, "name": organization.Name, "is_deleted": organization.IsDeleted, - "links": flattenOrganizationLinks(conversion.SlicePtrToSlice(organization.Links)), + "links": flattenOrganizationLinks(organization.GetLinks()), } } From 2524effcfd7433ff890312ac9e0066c776dc3098 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 15 Jan 2024 14:33:44 +0000 Subject: [PATCH 36/46] update documentation --- website/docs/r/organization.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/docs/r/organization.html.markdown b/website/docs/r/organization.html.markdown index 42ee91cade..3b9885de73 100644 --- a/website/docs/r/organization.html.markdown +++ b/website/docs/r/organization.html.markdown @@ -10,7 +10,9 @@ description: |- `mongodbatlas_organization` provides programmatic management (including creation) of a MongoDB Atlas Organization resource. -~> **IMPORTANT NOTE:** When you establish an Atlas organization using this resource, it automatically generates a set of initial public and private Programmatic API Keys. These key values are vital to store because you'll need to use them to grant access to the newly created Atlas organization. +~> **IMPORTANT NOTE:** When you establish an Atlas organization using this resource, it automatically generates a set of initial public and private Programmatic API Keys. These key values are vital to store because you'll need to use them to grant access to the newly created Atlas organization. To use this resource, `role_names` for new API Key must have the ORG_OWNER role specified. + +~> **IMPORTANT NOTE:** To use this resource, the requesting API Key must have the Organization Owner role. The requesting API Key's organization must be a paying organization. To learn more, see Configure a Paying Organization in the MongoDB Atlas documentation. ~> **NOTE** Import command is currently not supported for this resource. From f5933ecd102d72f0b598b420e2504a05f4dc1d69 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Tue, 16 Jan 2024 12:51:45 +0000 Subject: [PATCH 37/46] minor --- internal/common/conversion/type_conversion_test.go | 3 +-- internal/config/client.go | 10 ++++------ .../data_source_alert_configuration.go | 6 ++---- .../alertconfiguration/model_alert_configuration.go | 6 ++---- .../model_alert_configuration_test.go | 4 +--- .../alertconfiguration/resource_alert_configuration.go | 6 ++---- .../service/atlasuser/data_source_atlas_users_test.go | 4 +--- internal/service/databaseuser/model_database_user.go | 4 +--- .../resource_federated_database_instance.go | 1 - .../resource_federated_settings_identity_provider.go | 3 +-- .../onlinearchive/data_source_online_archive.go | 1 - .../service/onlinearchive/resource_online_archive.go | 6 ++---- .../service/organization/data_source_organization.go | 1 - internal/service/project/model_project.go | 4 +--- internal/service/project/model_project_test.go | 4 +--- internal/service/project/resource_project.go | 1 - .../searchdeployment/model_search_deployment.go | 4 +--- internal/service/searchindex/resource_search_index.go | 4 +--- 18 files changed, 21 insertions(+), 51 deletions(-) diff --git a/internal/common/conversion/type_conversion_test.go b/internal/common/conversion/type_conversion_test.go index 43381d3435..d5da040ede 100644 --- a/internal/common/conversion/type_conversion_test.go +++ b/internal/common/conversion/type_conversion_test.go @@ -4,9 +4,8 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/stretchr/testify/assert" ) func TestTimeToStringWithoutNanos(t *testing.T) { diff --git a/internal/config/client.go b/internal/config/client.go index dbadb4a0bd..040a3ad858 100644 --- a/internal/config/client.go +++ b/internal/config/client.go @@ -8,17 +8,15 @@ import ( "net/url" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" + "github.com/mongodb-forks/digest" + "github.com/mongodb/terraform-provider-mongodbatlas/version" + "github.com/spf13/cast" 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" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" - "github.com/mongodb-forks/digest" - "github.com/spf13/cast" - - "github.com/mongodb/terraform-provider-mongodbatlas/version" ) const ( diff --git a/internal/service/alertconfiguration/data_source_alert_configuration.go b/internal/service/alertconfiguration/data_source_alert_configuration.go index 1e4c98907d..dafac342cc 100644 --- a/internal/service/alertconfiguration/data_source_alert_configuration.go +++ b/internal/service/alertconfiguration/data_source_alert_configuration.go @@ -5,18 +5,16 @@ import ( "fmt" "sort" - "go.mongodb.org/atlas-sdk/v20231115003/admin" - "github.com/hashicorp/hcl/v2/hclwrite" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/zclconf/go-cty/cty" - "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/v20231115003/admin" ) var _ datasource.DataSource = &alertConfigurationDS{} diff --git a/internal/service/alertconfiguration/model_alert_configuration.go b/internal/service/alertconfiguration/model_alert_configuration.go index 645f928830..01b3d7b04a 100644 --- a/internal/service/alertconfiguration/model_alert_configuration.go +++ b/internal/service/alertconfiguration/model_alert_configuration.go @@ -4,12 +4,10 @@ import ( "fmt" "strings" - "go.mongodb.org/atlas-sdk/v20231115003/admin" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/mwielbut/pointy" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mwielbut/pointy" + "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 901ad3848b..e8cd0ae4eb 100644 --- a/internal/service/alertconfiguration/model_alert_configuration_test.go +++ b/internal/service/alertconfiguration/model_alert_configuration_test.go @@ -4,12 +4,10 @@ import ( "reflect" "testing" - "go.mongodb.org/atlas-sdk/v20231115003/admin" - "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/v20231115003/admin" ) const ( diff --git a/internal/service/alertconfiguration/resource_alert_configuration.go b/internal/service/alertconfiguration/resource_alert_configuration.go index 5a5ff136fb..fae08ed5ac 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration.go +++ b/internal/service/alertconfiguration/resource_alert_configuration.go @@ -6,8 +6,6 @@ import ( "reflect" "strings" - "go.mongodb.org/atlas-sdk/v20231115003/admin" - "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" @@ -20,10 +18,10 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/mwielbut/pointy" - "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 ( diff --git a/internal/service/atlasuser/data_source_atlas_users_test.go b/internal/service/atlasuser/data_source_atlas_users_test.go index ce4f8726dc..dbd0aaf26a 100644 --- a/internal/service/atlasuser/data_source_atlas_users_test.go +++ b/internal/service/atlasuser/data_source_atlas_users_test.go @@ -7,15 +7,13 @@ import ( "regexp" "testing" - "go.mongodb.org/atlas-sdk/v20231115003/admin" - "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "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/v20231115003/admin" ) func TestAccConfigDSAtlasUsers_ByOrgID(t *testing.T) { diff --git a/internal/service/databaseuser/model_database_user.go b/internal/service/databaseuser/model_database_user.go index 0df9c3f65f..47cc14bb09 100644 --- a/internal/service/databaseuser/model_database_user.go +++ b/internal/service/databaseuser/model_database_user.go @@ -4,13 +4,11 @@ import ( "context" "fmt" - "go.mongodb.org/atlas-sdk/v20231115003/admin" - "github.com/hashicorp/terraform-plugin-framework/diag" "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/v20231115003/admin" ) func NewMongoDBDatabaseUser(ctx context.Context, dbUserModel *TfDatabaseUserModel) (*admin.CloudDatabaseUser, diag.Diagnostics) { diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index aebee130b8..1b26ea220d 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -11,7 +11,6 @@ import ( "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/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index 362d40208f..f566e7db02 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -12,10 +12,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/spf13/cast" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/spf13/cast" ) func Resource() *schema.Resource { diff --git a/internal/service/onlinearchive/data_source_online_archive.go b/internal/service/onlinearchive/data_source_online_archive.go index b8103b190f..1f074126f2 100644 --- a/internal/service/onlinearchive/data_source_online_archive.go +++ b/internal/service/onlinearchive/data_source_online_archive.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/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index b80a62d893..fc29255e45 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -9,16 +9,14 @@ import ( "strings" "time" - admin20231001002 "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/mwielbut/pointy" - "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 ( diff --git a/internal/service/organization/data_source_organization.go b/internal/service/organization/data_source_organization.go index b1024f6516..867fb3c8ac 100644 --- a/internal/service/organization/data_source_organization.go +++ b/internal/service/organization/data_source_organization.go @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) diff --git a/internal/service/project/model_project.go b/internal/service/project/model_project.go index 6aa2bed12c..f8e57e13ff 100644 --- a/internal/service/project/model_project.go +++ b/internal/service/project/model_project.go @@ -3,11 +3,9 @@ package project import ( "context" - "go.mongodb.org/atlas-sdk/v20231115003/admin" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "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 70ef78277b..d756ea00fe 100644 --- a/internal/service/project/model_project_test.go +++ b/internal/service/project/model_project_test.go @@ -5,12 +5,10 @@ import ( "reflect" "testing" - "go.mongodb.org/atlas-sdk/v20231115003/admin" - "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/v20231115003/admin" ) const ( diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index 4640aadffe..584699ddd4 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -24,7 +24,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" "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/config" ) diff --git a/internal/service/searchdeployment/model_search_deployment.go b/internal/service/searchdeployment/model_search_deployment.go index 382b8f3418..8d322ea977 100644 --- a/internal/service/searchdeployment/model_search_deployment.go +++ b/internal/service/searchdeployment/model_search_deployment.go @@ -3,13 +3,11 @@ package searchdeployment import ( "context" - "go.mongodb.org/atlas-sdk/v20231115003/admin" - "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" ) func NewSearchDeploymentReq(ctx context.Context, searchDeploymentPlan *TFSearchDeploymentRSModel) admin.ApiSearchDeploymentRequest { diff --git a/internal/service/searchindex/resource_search_index.go b/internal/service/searchindex/resource_search_index.go index fb576871c3..347970c5d3 100644 --- a/internal/service/searchindex/resource_search_index.go +++ b/internal/service/searchindex/resource_search_index.go @@ -9,15 +9,13 @@ import ( "strings" "time" - "go.mongodb.org/atlas-sdk/v20231115003/admin" - "github.com/go-test/deep" "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" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( From 866fff5bbad6ba6c4dd3fc86331039aba38b7a3f Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Tue, 16 Jan 2024 13:06:52 +0000 Subject: [PATCH 38/46] fix: undo sh file commit From 49a1d9c95b426a66b254b9abbf676ec59c830c6e Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Tue, 16 Jan 2024 13:16:07 +0000 Subject: [PATCH 39/46] fix: undo sh file commit --- scripts/schema-scaffold.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/schema-scaffold.sh diff --git a/scripts/schema-scaffold.sh b/scripts/schema-scaffold.sh old mode 100644 new mode 100755 From c3cfbd9459bb9eae7bfa6ec66d526a0e3e50ce3e Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Tue, 16 Jan 2024 14:48:36 +0000 Subject: [PATCH 40/46] add documentation and examples --- .../organization-step-1/main.tf | 3 ++ .../organization/resource_organization.go | 2 +- .../resource_organization_test.go | 38 +++++++++++++++---- website/docs/d/organization.html.markdown | 3 ++ website/docs/d/organizations.html.markdown | 3 ++ website/docs/r/organization.html.markdown | 3 ++ 6 files changed, 44 insertions(+), 8 deletions(-) diff --git a/examples/mongodbatlas_organization/organization-step-1/main.tf b/examples/mongodbatlas_organization/organization-step-1/main.tf index cec38de75d..7e833f0103 100644 --- a/examples/mongodbatlas_organization/organization-step-1/main.tf +++ b/examples/mongodbatlas_organization/organization-step-1/main.tf @@ -3,6 +3,9 @@ resource "mongodbatlas_organization" "test" { name = "testCreateORG" description = "test API key from Org Creation Test" role_names = ["ORG_OWNER"] + multi_factor_auth_required = true + restrict_employee_access = true + api_access_list_required = false } output "org_id" { diff --git a/internal/service/organization/resource_organization.go b/internal/service/organization/resource_organization.go index 24d0883c43..b23e93f818 100644 --- a/internal/service/organization/resource_organization.go +++ b/internal/service/organization/resource_organization.go @@ -232,7 +232,7 @@ func resourceMongoDBAtlasOrganizationDelete(ctx context.Context, d *schema.Resou orgID := ids["org_id"] if _, _, err := conn.OrganizationsApi.DeleteOrganization(ctx, orgID).Execute(); err != nil { - return diag.FromErr(fmt.Errorf("error Organization: %s", err)) + return diag.FromErr(fmt.Errorf("error deleting Organization: %s", err)) } return nil } diff --git a/internal/service/organization/resource_organization_test.go b/internal/service/organization/resource_organization_test.go index b40b96f441..0f04b0e29c 100644 --- a/internal/service/organization/resource_organization_test.go +++ b/internal/service/organization/resource_organization_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "regexp" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -21,6 +22,7 @@ func TestAccConfigRSOrganization_Basic(t *testing.T) { resourceName = "mongodbatlas_organization.test" orgOwnerID = os.Getenv("MONGODB_ATLAS_ORG_OWNER_ID") name = fmt.Sprintf("test-acc-organization-%s", acctest.RandString(5)) + updatedName = fmt.Sprintf("test-acc-organization-updated-%s", acctest.RandString(5)) description = "test Key for Acceptance tests" roleName = "ORG_OWNER" ) @@ -40,7 +42,7 @@ func TestAccConfigRSOrganization_Basic(t *testing.T) { ), }, { - Config: testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, "org-name-updated", description, roleName), + Config: testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, updatedName, description, roleName), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasOrganizationExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "org_id"), @@ -52,6 +54,28 @@ func TestAccConfigRSOrganization_Basic(t *testing.T) { }) } +func TestAccConfigRSOrganization_BasicAccess(t *testing.T) { + acc.SkipTestForCI(t) + var ( + orgOwnerID = os.Getenv("MONGODB_ATLAS_ORG_OWNER_ID") + name = fmt.Sprintf("test-acc-organization-%s", acctest.RandString(5)) + description = "test Key for Acceptance tests" + roleName = "ORG_BILLING_ADMIN" + ) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.PreCheck(t) }, + ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, + CheckDestroy: testAccCheckMongoDBAtlasOrganizationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, name, description, roleName), + ExpectError: regexp.MustCompile("API Key must have the ORG_OWNER role"), + }, + }, + }) +} + func TestAccConfigRSOrganization_Settings(t *testing.T) { acc.SkipTestForCI(t) var ( @@ -63,11 +87,11 @@ func TestAccConfigRSOrganization_Settings(t *testing.T) { settingsConfig = ` api_access_list_required = false - restrict_employee_access = true` + multi_factor_auth_required = true` settingsConfigUpdated = ` api_access_list_required = false multi_factor_auth_required = true - restrict_employee_access = false` + restrict_employee_access = true` ) resource.Test(t, resource.TestCase{ @@ -83,11 +107,12 @@ func TestAccConfigRSOrganization_Settings(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "description"), resource.TestCheckResourceAttr(resourceName, "description", description), resource.TestCheckResourceAttr(resourceName, "api_access_list_required", "false"), - resource.TestCheckResourceAttr(resourceName, "restrict_employee_access", "true"), + resource.TestCheckResourceAttr(resourceName, "restrict_employee_access", "false"), + resource.TestCheckResourceAttr(resourceName, "multi_factor_auth_required", "true"), ), }, { - Config: testAccMongoDBAtlasOrganizationConfigWithSettings(orgOwnerID, "org-name-updated", description, roleName, settingsConfigUpdated), + Config: testAccMongoDBAtlasOrganizationConfigWithSettings(orgOwnerID, name, description, roleName, settingsConfigUpdated), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasOrganizationExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "org_id"), @@ -95,7 +120,7 @@ func TestAccConfigRSOrganization_Settings(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "description", description), resource.TestCheckResourceAttr(resourceName, "api_access_list_required", "false"), resource.TestCheckResourceAttr(resourceName, "multi_factor_auth_required", "true"), - resource.TestCheckResourceAttr(resourceName, "restrict_employee_access", "false"), + resource.TestCheckResourceAttr(resourceName, "restrict_employee_access", "true"), ), }, }, @@ -205,7 +230,6 @@ func testAccMongoDBAtlasOrganizationConfigWithSettings(orgOwnerID, name, descrip name = "%s" description = "%s" role_names = ["%s"] - %s } `, orgOwnerID, name, description, roleNames, settingsConfig) diff --git a/website/docs/d/organization.html.markdown b/website/docs/d/organization.html.markdown index 5b7ce2e92c..207356c6f8 100644 --- a/website/docs/d/organization.html.markdown +++ b/website/docs/d/organization.html.markdown @@ -31,6 +31,9 @@ In addition to all arguments above, the following attributes are exported: * `name` - Human-readable label that identifies the organization. * `id` - Unique 24-hexadecimal digit string that identifies the organization. * `is_deleted` - Flag that indicates whether this organization has been deleted. +* `api_access_list_required` - (Optional) Flag that indicates whether to require API operations to originate from an IP Address added to the API access list for the specified organization. +* `multi_factor_auth_required` - (Optional) Flag that indicates whether to require users to set up Multi-Factor Authentication (MFA) before accessing the specified organization. To learn more, see: https://www.mongodb.com/docs/atlas/security-multi-factor-authentication/. +* `restrict_employee_access` - (Optional) Flag that indicates whether to block MongoDB Support from accessing Atlas infrastructure for any deployment in the specified organization without explicit permission. Once this setting is turned on, you can grant MongoDB Support a 24-hour bypass access to the Atlas deployment to resolve support issues. To learn more, see: https://www.mongodb.com/docs/atlas/security-restrict-support-access/. See [MongoDB Atlas API - Organization](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Organizations/operation/getOrganization) Documentation for more information. diff --git a/website/docs/d/organizations.html.markdown b/website/docs/d/organizations.html.markdown index 5aefb7086b..4e2e7c40c6 100644 --- a/website/docs/d/organizations.html.markdown +++ b/website/docs/d/organizations.html.markdown @@ -36,5 +36,8 @@ data "mongodbatlas_organizations" "test" { * `name` - Human-readable label that identifies the organization. * `id` - Unique 24-hexadecimal digit string that identifies the organization. * `is_deleted` - Flag that indicates whether this organization has been deleted. +* `api_access_list_required` - (Optional) Flag that indicates whether to require API operations to originate from an IP Address added to the API access list for the specified organization. +* `multi_factor_auth_required` - (Optional) Flag that indicates whether to require users to set up Multi-Factor Authentication (MFA) before accessing the specified organization. To learn more, see: https://www.mongodb.com/docs/atlas/security-multi-factor-authentication/. +* `restrict_employee_access` - (Optional) Flag that indicates whether to block MongoDB Support from accessing Atlas infrastructure for any deployment in the specified organization without explicit permission. Once this setting is turned on, you can grant MongoDB Support a 24-hour bypass access to the Atlas deployment to resolve support issues. To learn more, see: https://www.mongodb.com/docs/atlas/security-restrict-support-access/. See [MongoDB Atlas API - Organizations](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Organizations/operation/listOrganizations) Documentation for more information. diff --git a/website/docs/r/organization.html.markdown b/website/docs/r/organization.html.markdown index 3b9885de73..ca4c602031 100644 --- a/website/docs/r/organization.html.markdown +++ b/website/docs/r/organization.html.markdown @@ -37,6 +37,9 @@ resource "mongodbatlas_organization" "test" { * `role_names` - (Required) List of Organization roles that the Programmatic API key needs to have. Ensure that you provide at least one role and ensure all roles are valid for the Organization. You must specify an array even if you are only associating a single role with the Programmatic API key. The [MongoDB Documentation](https://www.mongodb.com/docs/atlas/reference/user-roles/#organization-roles) describes the roles that you can assign to a Programmatic API key. * `federation_settings_id` - (Optional) Unique 24-hexadecimal digit string that identifies the federation to link the newly created organization to. If specified, the proposed Organization Owner of the new organization must have the Organization Owner role in an organization associated with the federation. +* `api_access_list_required` - (Optional) Flag that indicates whether to require API operations to originate from an IP Address added to the API access list for the specified organization. +* `multi_factor_auth_required` - (Optional) Flag that indicates whether to require users to set up Multi-Factor Authentication (MFA) before accessing the specified organization. To learn more, see: https://www.mongodb.com/docs/atlas/security-multi-factor-authentication/. +* `restrict_employee_access` - (Optional) Flag that indicates whether to block MongoDB Support from accessing Atlas infrastructure for any deployment in the specified organization without explicit permission. Once this setting is turned on, you can grant MongoDB Support a 24-hour bypass access to the Atlas deployment to resolve support issues. To learn more, see: https://www.mongodb.com/docs/atlas/security-restrict-support-access/. ## Attributes Reference From 7c1ef2cba33e8c28841799c4734f3d446461bc0c Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Wed, 17 Jan 2024 09:59:33 +0000 Subject: [PATCH 41/46] address PR comments --- .../organization/data_source_organization.go | 7 +- .../organization/resource_organization.go | 10 +-- .../resource_organization_test.go | 75 +++++++++---------- 3 files changed, 45 insertions(+), 47 deletions(-) diff --git a/internal/service/organization/data_source_organization.go b/internal/service/organization/data_source_organization.go index 867fb3c8ac..2676ba0ac9 100644 --- a/internal/service/organization/data_source_organization.go +++ b/internal/service/organization/data_source_organization.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -56,11 +57,11 @@ func dataSourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("error getting organizations information: %s", err)) } - if err := d.Set("name", organization.Name); err != nil { + if err := d.Set("name", organization.GetName()); err != nil { return diag.FromErr(fmt.Errorf("error setting `name`: %s", err)) } - if err := d.Set("is_deleted", organization.IsDeleted); err != nil { + if err := d.Set("is_deleted", organization.GetIsDeleted()); err != nil { return diag.FromErr(fmt.Errorf("error setting `is_deleted`: %s", err)) } @@ -68,7 +69,7 @@ func dataSourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("error setting `is_deleted`: %s", err)) } - d.SetId(*organization.Id) + d.SetId(organization.GetId()) return nil } diff --git a/internal/service/organization/resource_organization.go b/internal/service/organization/resource_organization.go index 318cea3392..a507d627c0 100644 --- a/internal/service/organization/resource_organization.go +++ b/internal/service/organization/resource_organization.go @@ -77,20 +77,20 @@ func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("error create Organization: %s", err)) } - if err := d.Set("private_key", organization.ApiKey.PrivateKey); err != nil { + if err := d.Set("private_key", organization.ApiKey.GetPrivateKey()); err != nil { return diag.FromErr(fmt.Errorf("error setting `private_key`: %s", err)) } - if err := d.Set("public_key", organization.ApiKey.PublicKey); err != nil { + if err := d.Set("public_key", organization.ApiKey.GetPublicKey()); err != nil { return diag.FromErr(fmt.Errorf("error setting `public_key`: %s", err)) } - if err := d.Set("org_id", *organization.Organization.Id); err != nil { + if err := d.Set("org_id", organization.Organization.GetId()); err != nil { return diag.FromErr(fmt.Errorf("error setting `org_id`: %s", err)) } d.SetId(conversion.EncodeStateID(map[string]string{ - "org_id": *organization.Organization.Id, + "org_id": organization.Organization.GetId(), })) return resourceMongoDBAtlasOrganizationRead(ctx, d, meta) @@ -120,7 +120,7 @@ func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resourc return diag.FromErr(fmt.Errorf("error reading organization information: %s", err)) } d.SetId(conversion.EncodeStateID(map[string]string{ - "org_id": *organization.Id, + "org_id": organization.GetId(), })) return nil } diff --git a/internal/service/organization/resource_organization_test.go b/internal/service/organization/resource_organization_test.go index 25398bfebe..d0723c2277 100644 --- a/internal/service/organization/resource_organization_test.go +++ b/internal/service/organization/resource_organization_test.go @@ -6,6 +6,8 @@ import ( "os" "testing" + "go.mongodb.org/atlas-sdk/v20231115003/admin" + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -63,30 +65,16 @@ func testAccCheckMongoDBAtlasOrganizationExists(resourceName string) resource.Te return fmt.Errorf("no ID is set") } - if rs.Primary.Attributes["public_key"] == "" { - return fmt.Errorf("no public_key is set") - } - - if rs.Primary.Attributes["private_key"] == "" { - return fmt.Errorf("no private_key is set") - } - ids := conversion.DecodeStateID(rs.Primary.ID) - - cfg := config.Config{ - PublicKey: rs.Primary.Attributes["public_key"], - PrivateKey: rs.Primary.Attributes["private_key"], - BaseURL: acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Config.BaseURL, + conn, err := getTestClientWithNewOrgCreds(rs) + if err != nil { + return err } - ctx := context.Background() - clients, _ := cfg.NewClient(ctx) - conn := clients.(*config.MongoDBClient).AtlasV2 - - orgs, _, err := conn.OrganizationsApi.ListOrganizations(ctx).Execute() + orgs, _, err := conn.OrganizationsApi.ListOrganizations(context.Background()).Execute() if err == nil { - for _, val := range *orgs.Results { - if *val.Id == ids["org_id"] { + for _, val := range orgs.GetResults() { + if val.GetId() == ids["org_id"] { return nil } } @@ -103,30 +91,16 @@ func testAccCheckMongoDBAtlasOrganizationDestroy(s *terraform.State) error { continue } - if rs.Primary.Attributes["public_key"] == "" { - return fmt.Errorf("no public_key is set") - } - - if rs.Primary.Attributes["private_key"] == "" { - return fmt.Errorf("no private_key is set") - } - ids := conversion.DecodeStateID(rs.Primary.ID) - - cfg := config.Config{ - PublicKey: rs.Primary.Attributes["public_key"], - PrivateKey: rs.Primary.Attributes["private_key"], - BaseURL: acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Config.BaseURL, + conn, err := getTestClientWithNewOrgCreds(rs) + if err != nil { + return err } - ctx := context.Background() - clients, _ := cfg.NewClient(ctx) - conn := clients.(*config.MongoDBClient).AtlasV2 - orgs, _, err := conn.OrganizationsApi.ListOrganizations(context.Background()).Execute() if err == nil { - for _, val := range *orgs.Results { - if *val.Id == ids["org_id"] { + for _, val := range orgs.GetResults() { + if val.GetId() == ids["org_id"] { return fmt.Errorf("Organization (%s) still exists", ids["org_id"]) } } @@ -147,3 +121,26 @@ func testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, name, description, r } `, orgOwnerID, name, description, roleNames) } + +// getTestClientWithNewOrgCreds This method creates a new Atlas client with credentials for the newly created organization. +// This is required to call relevant API methods for the new organization, for example ListOrganizations requires that the requesting API +// key must have the Organization Member role. So we cannot invoke API methods on the new organization with credentials configured in the provider. +func getTestClientWithNewOrgCreds(rs *terraform.ResourceState) (*admin.APIClient, error) { + if rs.Primary.Attributes["public_key"] == "" { + return nil, fmt.Errorf("no public_key is set") + } + + if rs.Primary.Attributes["private_key"] == "" { + return nil, fmt.Errorf("no private_key is set") + } + + cfg := config.Config{ + PublicKey: rs.Primary.Attributes["public_key"], + PrivateKey: rs.Primary.Attributes["private_key"], + BaseURL: acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Config.BaseURL, + } + + ctx := context.Background() + clients, _ := cfg.NewClient(ctx) + return clients.(*config.MongoDBClient).AtlasV2, nil +} From a6cc69ef0753ee047008ccb5fe38e3cec1f851a4 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Wed, 17 Jan 2024 10:40:44 +0000 Subject: [PATCH 42/46] address PR comments --- .../organization-step-1/main.tf | 12 ++--- internal/common/constant/access_level.go | 5 +++ .../data_source_organization_test.go | 6 +-- .../organization/resource_organization.go | 21 ++++----- .../resource_organization_test.go | 44 +++++++++++++++++-- 5 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 internal/common/constant/access_level.go diff --git a/examples/mongodbatlas_organization/organization-step-1/main.tf b/examples/mongodbatlas_organization/organization-step-1/main.tf index 7e833f0103..7dd6d989c7 100644 --- a/examples/mongodbatlas_organization/organization-step-1/main.tf +++ b/examples/mongodbatlas_organization/organization-step-1/main.tf @@ -1,11 +1,11 @@ resource "mongodbatlas_organization" "test" { - org_owner_id = var.org_owner_id - name = "testCreateORG" - description = "test API key from Org Creation Test" - role_names = ["ORG_OWNER"] + org_owner_id = var.org_owner_id + name = "testCreateORG" + description = "test API key from Org Creation Test" + role_names = ["ORG_OWNER"] multi_factor_auth_required = true - restrict_employee_access = true - api_access_list_required = false + restrict_employee_access = true + api_access_list_required = false } output "org_id" { diff --git a/internal/common/constant/access_level.go b/internal/common/constant/access_level.go new file mode 100644 index 0000000000..b019e551fe --- /dev/null +++ b/internal/common/constant/access_level.go @@ -0,0 +1,5 @@ +package constant + +const ( + OrgOwner = "ORG_OWNER" +) diff --git a/internal/service/organization/data_source_organization_test.go b/internal/service/organization/data_source_organization_test.go index 1aebdaebfa..9ca3f07dca 100644 --- a/internal/service/organization/data_source_organization_test.go +++ b/internal/service/organization/data_source_organization_test.go @@ -23,9 +23,9 @@ func TestAccConfigDSOrganization_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(datasourceName, "name"), resource.TestCheckResourceAttrSet(datasourceName, "id"), - resource.TestCheckResourceAttrSet(datasourceName, "restrict_employee_access"), - resource.TestCheckResourceAttrSet(datasourceName, "multi_factor_auth_required"), - resource.TestCheckResourceAttrSet(datasourceName, "api_access_list_required"), + resource.TestCheckResourceAttr(datasourceName, "restrict_employee_access", "false"), + resource.TestCheckResourceAttr(datasourceName, "multi_factor_auth_required", "false"), + resource.TestCheckResourceAttr(datasourceName, "api_access_list_required", "false"), ), }, }, diff --git a/internal/service/organization/resource_organization.go b/internal/service/organization/resource_organization.go index 92b8dc55e7..4923bf951d 100644 --- a/internal/service/organization/resource_organization.go +++ b/internal/service/organization/resource_organization.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mwielbut/pointy" + "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" ) @@ -81,8 +82,8 @@ func Resource() *schema.Resource { } func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - if !isAPIKeyOrgOwner(conversion.ExpandStringList(d.Get("role_names").(*schema.Set).List())) { - return diag.FromErr(fmt.Errorf("`role_names` for new API Key must have the ORG_OWNER role to use this resource")) + if err := ValidateAPIKeyIsOrgOwner(conversion.ExpandStringList(d.Get("role_names").(*schema.Set).List())); err != nil { + return diag.FromErr(err) } conn := meta.(*config.MongoDBClient).AtlasV2 @@ -109,14 +110,14 @@ func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.Resou clients, _ := cfg.NewClient(ctx) conn = clients.(*config.MongoDBClient).AtlasV2 - _, _, err = conn.OrganizationsApi.UpdateOrganizationSettings(ctx, orgID, newOrganizationSettings(d)).Execute() - if err != nil { + _, _, errUpdate := conn.OrganizationsApi.UpdateOrganizationSettings(ctx, orgID, newOrganizationSettings(d)).Execute() + if errUpdate != nil { if _, _, err := conn.OrganizationsApi.DeleteOrganization(ctx, orgID).Execute(); err != nil { d.SetId("") - return diag.FromErr(fmt.Errorf("an error occurred when updating Organization settings. Unable to delete organization, there may be dangling resources: %s", err)) + return diag.FromErr(fmt.Errorf("an error occurred when updating Organization settings: %s.\n Unable to delete organization, there may be dangling resources: %s", errUpdate.Error(), err.Error())) } d.SetId("") - return diag.FromErr(fmt.Errorf("error setting Organization setings: %s", err)) + return diag.FromErr(fmt.Errorf("an error occurred when updating Organization settings: %s", err)) } if err := d.Set("private_key", organization.ApiKey.GetPrivateKey()); err != nil { @@ -263,12 +264,12 @@ func newOrganizationSettings(d *schema.ResourceData) *admin.OrganizationSettings } } -func isAPIKeyOrgOwner(roles []string) bool { +func ValidateAPIKeyIsOrgOwner(roles []string) error { for _, role := range roles { - if role == "ORG_OWNER" { - return true + if role == constant.OrgOwner { + return nil } } - return false + return fmt.Errorf("`role_names` for new API Key must have the ORG_OWNER role to use this resource") } diff --git a/internal/service/organization/resource_organization_test.go b/internal/service/organization/resource_organization_test.go index b09fc77473..5bbec535cd 100644 --- a/internal/service/organization/resource_organization_test.go +++ b/internal/service/organization/resource_organization_test.go @@ -15,6 +15,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/service/organization" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" ) @@ -39,8 +40,10 @@ func TestAccConfigRSOrganization_Basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasOrganizationExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "org_id"), - resource.TestCheckResourceAttrSet(resourceName, "description"), resource.TestCheckResourceAttr(resourceName, "description", description), + resource.TestCheckResourceAttr(resourceName, "api_access_list_required", "false"), + resource.TestCheckResourceAttr(resourceName, "restrict_employee_access", "false"), + resource.TestCheckResourceAttr(resourceName, "multi_factor_auth_required", "false"), ), }, { @@ -48,8 +51,10 @@ func TestAccConfigRSOrganization_Basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasOrganizationExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "org_id"), - resource.TestCheckResourceAttrSet(resourceName, "description"), resource.TestCheckResourceAttr(resourceName, "description", description), + resource.TestCheckResourceAttr(resourceName, "api_access_list_required", "false"), + resource.TestCheckResourceAttr(resourceName, "restrict_employee_access", "false"), + resource.TestCheckResourceAttr(resourceName, "multi_factor_auth_required", "false"), ), }, }, @@ -106,7 +111,6 @@ func TestAccConfigRSOrganization_Settings(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasOrganizationExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "org_id"), - resource.TestCheckResourceAttrSet(resourceName, "description"), resource.TestCheckResourceAttr(resourceName, "description", description), resource.TestCheckResourceAttr(resourceName, "api_access_list_required", "false"), resource.TestCheckResourceAttr(resourceName, "restrict_employee_access", "false"), @@ -118,7 +122,6 @@ func TestAccConfigRSOrganization_Settings(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasOrganizationExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "org_id"), - resource.TestCheckResourceAttrSet(resourceName, "description"), resource.TestCheckResourceAttr(resourceName, "description", description), resource.TestCheckResourceAttr(resourceName, "api_access_list_required", "false"), resource.TestCheckResourceAttr(resourceName, "multi_factor_auth_required", "true"), @@ -232,3 +235,36 @@ func getTestClientWithNewOrgCreds(rs *terraform.ResourceState) (*admin.APIClient clients, _ := cfg.NewClient(ctx) return clients.(*config.MongoDBClient).AtlasV2, nil } + +func TestValidateAPIKeyIsOrgOwner(t *testing.T) { + tests := []struct { + name string + roles []string + wantErr bool + }{ + { + name: "Contains OrgOwner", + roles: []string{"ORG_MEMBER", "ORG_OWNER", "ORG_READ_ONLY"}, + wantErr: false, + }, + { + name: "Does Not Contain OrgOwner", + roles: []string{"ORG_MEMBER", "READ_ONLY"}, + wantErr: true, + }, + { + name: "Empty Roles", + roles: []string{}, + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := organization.ValidateAPIKeyIsOrgOwner(tt.roles) + if (err != nil) != tt.wantErr { + t.Errorf("validateAPIKeyIsOrgOwner() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} From 5a08be66fcc3e95cfc1136c191db2dc6fd66de25 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Wed, 17 Jan 2024 10:47:18 +0000 Subject: [PATCH 43/46] minor --- internal/service/organization/resource_organization_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/organization/resource_organization_test.go b/internal/service/organization/resource_organization_test.go index 5bbec535cd..bb56a0af84 100644 --- a/internal/service/organization/resource_organization_test.go +++ b/internal/service/organization/resource_organization_test.go @@ -210,7 +210,6 @@ func testAccMongoDBAtlasOrganizationConfigWithSettings(orgOwnerID, name, descrip %s } `, orgOwnerID, name, description, roleNames, settingsConfig) - } // getTestClientWithNewOrgCreds This method creates a new Atlas client with credentials for the newly created organization. From 9ce01075cb0f4cec29cd71aebc58a4a39ede5c64 Mon Sep 17 00:00:00 2001 From: maastha <122359335+maastha@users.noreply.github.com> Date: Wed, 17 Jan 2024 10:49:29 +0000 Subject: [PATCH 44/46] Apply suggestions from code review Co-authored-by: Leo Antoli <430982+lantoli@users.noreply.github.com> --- internal/service/organization/resource_organization_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/organization/resource_organization_test.go b/internal/service/organization/resource_organization_test.go index d0723c2277..17f87bb2dd 100644 --- a/internal/service/organization/resource_organization_test.go +++ b/internal/service/organization/resource_organization_test.go @@ -122,8 +122,8 @@ func testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, name, description, r `, orgOwnerID, name, description, roleNames) } -// getTestClientWithNewOrgCreds This method creates a new Atlas client with credentials for the newly created organization. -// This is required to call relevant API methods for the new organization, for example ListOrganizations requires that the requesting API +// getTestClientWithNewOrgCreds creates a new Atlas client with credentials for the newly created organization. +// getTestClientWithNewOrgCreds is required to call relevant API methods for the new organization, for example ListOrganizations requires that the requesting API // key must have the Organization Member role. So we cannot invoke API methods on the new organization with credentials configured in the provider. func getTestClientWithNewOrgCreds(rs *terraform.ResourceState) (*admin.APIClient, error) { if rs.Primary.Attributes["public_key"] == "" { From 8e631e7f1e9fdb2ffe0e618c5e6950f36ff1072a Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Wed, 17 Jan 2024 13:30:51 +0000 Subject: [PATCH 45/46] minor --- .../service/organization/data_source_organization_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/organization/data_source_organization_test.go b/internal/service/organization/data_source_organization_test.go index 9ca3f07dca..1aebdaebfa 100644 --- a/internal/service/organization/data_source_organization_test.go +++ b/internal/service/organization/data_source_organization_test.go @@ -23,9 +23,9 @@ func TestAccConfigDSOrganization_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(datasourceName, "name"), resource.TestCheckResourceAttrSet(datasourceName, "id"), - resource.TestCheckResourceAttr(datasourceName, "restrict_employee_access", "false"), - resource.TestCheckResourceAttr(datasourceName, "multi_factor_auth_required", "false"), - resource.TestCheckResourceAttr(datasourceName, "api_access_list_required", "false"), + resource.TestCheckResourceAttrSet(datasourceName, "restrict_employee_access"), + resource.TestCheckResourceAttrSet(datasourceName, "multi_factor_auth_required"), + resource.TestCheckResourceAttrSet(datasourceName, "api_access_list_required"), ), }, }, From 0d2f77f920f4ed137815946a453b1337c2bbf6ea Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Thu, 18 Jan 2024 10:44:55 +0000 Subject: [PATCH 46/46] update include_deleted_orgs deprecation message --- internal/service/organization/data_source_organizations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/organization/data_source_organizations.go b/internal/service/organization/data_source_organizations.go index c411433679..5686c447b5 100644 --- a/internal/service/organization/data_source_organizations.go +++ b/internal/service/organization/data_source_organizations.go @@ -27,7 +27,7 @@ func PluralDataSource() *schema.Resource { "include_deleted_orgs": { Type: schema.TypeBool, Optional: true, - Deprecated: fmt.Sprintf(constant.DeprecationParamByDate, "January 2025"), + Deprecated: fmt.Sprintf(constant.DeprecationParamByVersion, "1.16.0"), }, "page_num": { Type: schema.TypeInt,