Skip to content

Commit c9e761e

Browse files
authored
fix: Skips date_format validation to allow all different formats (#3865)
* fix: Skips validation to add support for date_format values in `mongodbatlas_online_archive` * add release notes * fix: Update changelog to include resource prefix for date_format validation skip in mongodbatlas_online_archive * chore: Corrects changelog message * refactor: Rename test for invalid process region and add error message validation for date format * fix: Add check to skip cluster destruction if an existing cluster is used
1 parent edcb73d commit c9e761e

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

.changelog/3865.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/mongodbatlas_online_archive: Removing incorrect validation for valid value `OBJECT_ID` in `date_format` field
3+
```

internal/service/onlinearchive/resource.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ func resourceSchema() map[string]*schema.Schema {
8787
Optional: true,
8888
},
8989
"date_format": {
90-
Type: schema.TypeString,
91-
Optional: true,
92-
Computed: true, // api will set the default
93-
ValidateFunc: validation.StringInSlice([]string{"ISODATE", "EPOCH_SECONDS", "EPOCH_MILLIS", "EPOCH_NANOSECONDS"}, false),
90+
Type: schema.TypeString,
91+
Optional: true,
92+
Computed: true, // api will set the default
9493
},
9594
"expire_after_days": {
9695
Type: schema.TypeInt,

internal/service/onlinearchive/resource_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func TestAccBackupRSOnlineArchiveWithProcessRegion(t *testing.T) {
208208
})
209209
}
210210

211-
func TestAccBackupRSOnlineArchiveInvalidProcessRegion(t *testing.T) {
211+
func TestAccBackupRSOnlineArchive_ErrorMessages(t *testing.T) {
212212
var (
213213
clusterInfo = acc.GetClusterInfo(t, clusterRequest())
214214
clusterTerraformStr = clusterInfo.TerraformStr
@@ -221,6 +221,10 @@ func TestAccBackupRSOnlineArchiveInvalidProcessRegion(t *testing.T) {
221221
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
222222
CheckDestroy: acc.CheckDestroyCluster,
223223
Steps: []resource.TestStep{
224+
{
225+
Config: configWithInvalidDateFormat(clusterTerraformStr, clusterResourceName),
226+
ExpectError: regexp.MustCompile("An invalid enumeration value INVALID_FORMAT was specified"),
227+
},
224228
{
225229
Config: configWithDataProcessRegion(clusterTerraformStr, clusterResourceName, cloudProvider, "UNKNOWN"),
226230
ExpectError: regexp.MustCompile("INVALID_ATTRIBUTE"),
@@ -545,3 +549,28 @@ func TestAccOnlineArchive_deleteOnCreateTimeout(t *testing.T) {
545549
},
546550
})
547551
}
552+
553+
func configWithInvalidDateFormat(clusterTerraformStr, clusterResourceName string) string {
554+
return fmt.Sprintf(`
555+
%[1]s
556+
resource "mongodbatlas_online_archive" "users_archive" {
557+
project_id = %[2]s.project_id
558+
cluster_name = %[2]s.name
559+
coll_name = "listingsAndReviews"
560+
collection_type = "STANDARD"
561+
db_name = "sample_airbnb"
562+
563+
criteria {
564+
type = "DATE"
565+
date_field = "last_review"
566+
date_format = "INVALID_FORMAT"
567+
expire_after_days = 2
568+
}
569+
570+
partition_fields {
571+
field_name = "last_review"
572+
order = 0
573+
}
574+
}
575+
`, clusterTerraformStr, clusterResourceName)
576+
}

internal/testutil/acc/advanced_cluster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func TestStepImportCluster(resourceName string, ignorePrefixFields ...string) re
7171
}
7272

7373
func CheckDestroyCluster(s *terraform.State) error {
74+
if ExistingClusterUsed() {
75+
return nil
76+
}
7477
for _, rs := range s.RootModule().Resources {
7578
if rs.Type != "mongodbatlas_cluster" && rs.Type != "mongodbatlas_advanced_cluster" {
7679
continue

0 commit comments

Comments
 (0)