Skip to content

Commit c2e1d51

Browse files
authored
Setting deterministic encoding id output, just sorting the keys (#303)
* order to generate the same sequence for encodedID * remove skipImportTest
1 parent cefa101 commit c2e1d51

17 files changed

+11
-26
lines changed

mongodbatlas/provider.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"reflect"
8+
"sort"
89
"strings"
910

1011
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
@@ -102,8 +103,16 @@ func encodeStateID(values map[string]string) string {
102103
encode := func(e string) string { return base64.StdEncoding.EncodeToString([]byte(e)) }
103104
encodedValues := make([]string, 0)
104105

105-
for key, value := range values {
106-
encodedValues = append(encodedValues, fmt.Sprintf("%s:%s", encode(key), encode(value)))
106+
// sort to make sure the same encoding is returned in case of same input
107+
keys := make([]string, 0, len(values))
108+
for key := range values {
109+
keys = append(keys, key)
110+
}
111+
112+
sort.Strings(keys)
113+
114+
for _, key := range keys {
115+
encodedValues = append(encodedValues, fmt.Sprintf("%s:%s", encode(key), encode(values[key])))
107116
}
108117

109118
return strings.Join(encodedValues, "-")

mongodbatlas/provider_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,3 @@ func checkTeamsIds(t *testing.T) {
161161
t.Fatal("`MONGODB_ATLAS_TEAMS_IDS` must be set for Projects acceptance testing")
162162
}
163163
}
164-
165-
// SkipTestImport temporary solution to avoid error about failed verification, will solve later
166-
func SkipTestImport(t *testing.T) {
167-
if strings.EqualFold(os.Getenv("SKIP_TEST_IMPORT"), "true") {
168-
t.Skip()
169-
}
170-
}

mongodbatlas/resource_mongodbatlas_alert_configuration_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ func TestAccResourceMongoDBAtlasAlertConfiguration_whitoutRoles(t *testing.T) {
212212
}
213213

214214
func TestAccResourceMongoDBAtlasAlertConfiguration_importBasic(t *testing.T) {
215-
SkipTestImport(t)
216215
var (
217216
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
218217
resourceName = "mongodbatlas_alert_configuration.test"
@@ -238,7 +237,6 @@ func TestAccResourceMongoDBAtlasAlertConfiguration_importBasic(t *testing.T) {
238237
}
239238

240239
func TestAccResourceMongoDBAtlasAlertConfiguration_importConfigNotifications(t *testing.T) {
241-
SkipTestImport(t)
242240
var (
243241
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
244242
resourceName = "mongodbatlas_alert_configuration.test"

mongodbatlas/resource_mongodbatlas_auditing_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ func TestAccResourceMongoDBAtlasAuditing_basic(t *testing.T) {
6464
}
6565

6666
func TestAccResourceMongoDBAtlasAuditing_importBasic(t *testing.T) {
67-
SkipTestImport(t)
6867
var (
6968
auditing = &matlas.Auditing{}
7069
resourceName = "mongodbatlas_auditing.test"

mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_backup_policy_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ func TestAccResourceMongoDBAtlasCloudProviderSnapshotBackupPolicy_withoutRestore
103103
}
104104

105105
func TestAccResourceMongoDBAtlasCloudProviderSnapshotBackupPolicy_importBasic(t *testing.T) {
106-
SkipTestImport(t)
107106
var (
108107
resourceName = "mongodbatlas_cloud_provider_snapshot_backup_policy.test"
109108
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")

mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_restore_job_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func TestAccResourceMongoDBAtlasCloudProviderSnapshotRestoreJob_basic(t *testing
5252
}
5353

5454
func TestAccResourceMongoDBAtlasCloudProviderSnapshotRestoreJob_importBasic(t *testing.T) {
55-
SkipTestImport(t)
5655
var (
5756
resourceName = "mongodbatlas_cloud_provider_snapshot_restore_job.test"
5857
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")

mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func TestAccResourceMongoDBAtlasCloudProviderSnapshot_basic(t *testing.T) {
4545
}
4646

4747
func TestAccResourceMongoDBAtlasCloudProviderSnapshot_importBasic(t *testing.T) {
48-
SkipTestImport(t)
4948
var (
5049
resourceName = "mongodbatlas_cloud_provider_snapshot.test"
5150
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")

mongodbatlas/resource_mongodbatlas_cluster_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,6 @@ func TestAccResourceMongoDBAtlasCluster_withAutoScalingAWS(t *testing.T) {
765765
}
766766

767767
func TestAccResourceMongoDBAtlasCluster_importBasic(t *testing.T) {
768-
SkipTestImport(t)
769768
var (
770769
resourceName = "mongodbatlas_cluster.test"
771770
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")

mongodbatlas/resource_mongodbatlas_custom_db_role_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ func TestAccResourceMongoDBAtlasCustomDBRoles_MultipleResources(t *testing.T) {
450450
}
451451

452452
func TestAccResourceMongoDBAtlasCustomDBRoles_importBasic(t *testing.T) {
453-
SkipTestImport(t)
454453
var (
455454
resourceName = "mongodbatlas_custom_db_role.test"
456455
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")

mongodbatlas/resource_mongodbatlas_database_user_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ func TestAccResourceMongoDBAtlasDatabaseUser_withRoles(t *testing.T) {
292292
}
293293

294294
func TestAccResourceMongoDBAtlasDatabaseUser_importBasic(t *testing.T) {
295-
SkipTestImport(t)
296295
var (
297296
username = fmt.Sprintf("test-username-%s", acctest.RandString(5))
298297
resourceName = "mongodbatlas_database_user.basic_ds"
@@ -327,7 +326,6 @@ func TestAccResourceMongoDBAtlasDatabaseUser_importBasic(t *testing.T) {
327326
}
328327

329328
func TestAccResourceMongoDBAtlasDatabaseUser_importX509TypeCustomer(t *testing.T) {
330-
SkipTestImport(t)
331329
var (
332330
dbUser matlas.DatabaseUser
333331
resourceName = "mongodbatlas_database_user.test"

0 commit comments

Comments
 (0)