|
5 | 5 | "fmt"
|
6 | 6 | "log"
|
7 | 7 | "os"
|
| 8 | + "regexp" |
8 | 9 | "testing"
|
9 | 10 | "time"
|
10 | 11 |
|
@@ -165,6 +166,55 @@ func TestAccBackupRSOnlineArchiveBasic(t *testing.T) {
|
165 | 166 | })
|
166 | 167 | }
|
167 | 168 |
|
| 169 | +func TestAccBackupRSOnlineArchiveWithProcessRegion(t *testing.T) { |
| 170 | + var ( |
| 171 | + cluster matlas.Cluster |
| 172 | + resourceName = "mongodbatlas_cluster.online_archive_test" |
| 173 | + onlineArchiveResourceName = "mongodbatlas_online_archive.users_archive" |
| 174 | + onlineArchiveDataSourceName = "data.mongodbatlas_online_archive.read_archive" |
| 175 | + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") |
| 176 | + projectName = acctest.RandomWithPrefix("test-acc") |
| 177 | + name = fmt.Sprintf("test-acc-%s", acctest.RandString(10)) |
| 178 | + cloudProvider = "AWS" |
| 179 | + ) |
| 180 | + |
| 181 | + resource.ParallelTest(t, resource.TestCase{ |
| 182 | + PreCheck: func() { testAccPreCheckBasic(t) }, |
| 183 | + ProtoV6ProviderFactories: testAccProviderV6Factories, |
| 184 | + CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy, |
| 185 | + Steps: []resource.TestStep{ |
| 186 | + { |
| 187 | + // We need this step to pupulate the cluster with Sample Data |
| 188 | + // The online archive won't work if the cluster does not have data |
| 189 | + Config: testAccBackupRSOnlineArchiveConfigFirstStep(orgID, projectName, name), |
| 190 | + Check: resource.ComposeTestCheckFunc( |
| 191 | + populateWithSampleData(resourceName, &cluster), |
| 192 | + ), |
| 193 | + }, |
| 194 | + { |
| 195 | + Config: testAccBackupRSOnlineArchiveConfigWithProcessRegion(orgID, projectName, name, cloudProvider, "SA_EAST_1"), |
| 196 | + Check: resource.ComposeTestCheckFunc( |
| 197 | + resource.TestCheckResourceAttr(onlineArchiveResourceName, "data_process_region.0.cloud_provider", "AWS"), |
| 198 | + resource.TestCheckResourceAttr(onlineArchiveResourceName, "data_process_region.0.region", "SA_EAST_1"), |
| 199 | + resource.TestCheckResourceAttr(onlineArchiveDataSourceName, "data_process_region.0.cloud_provider", "AWS"), |
| 200 | + resource.TestCheckResourceAttr(onlineArchiveDataSourceName, "data_process_region.0.region", "SA_EAST_1"), |
| 201 | + ), |
| 202 | + }, |
| 203 | + { |
| 204 | + Config: testAccBackupRSOnlineArchiveConfigWithProcessRegion(orgID, projectName, name, cloudProvider, "AP_SOUTH_1"), |
| 205 | + ExpectError: regexp.MustCompile("ONLINE_ARCHIVE_CANNOT_MODIFY_FIELD"), |
| 206 | + }, |
| 207 | + { |
| 208 | + Config: testAccBackupRSOnlineArchiveConfigWithoutSchedule(orgID, projectName, name), |
| 209 | + Check: resource.ComposeTestCheckFunc( |
| 210 | + resource.TestCheckResourceAttr(onlineArchiveResourceName, "data_process_region.0.cloud_provider", "AWS"), |
| 211 | + resource.TestCheckResourceAttr(onlineArchiveResourceName, "data_process_region.0.region", "SA_EAST_1"), |
| 212 | + ), |
| 213 | + }, |
| 214 | + }, |
| 215 | + }) |
| 216 | +} |
| 217 | + |
168 | 218 | func populateWithSampleData(resourceName string, cluster *matlas.Cluster) resource.TestCheckFunc {
|
169 | 219 | return func(s *terraform.State) error {
|
170 | 220 | conn := testMongoDBClient.(*MongoDBClient).Atlas
|
@@ -331,6 +381,59 @@ func testAccBackupRSOnlineArchiveConfigWithoutSchedule(orgID, projectName, clust
|
331 | 381 | `, testAccBackupRSOnlineArchiveConfigFirstStep(orgID, projectName, clusterName))
|
332 | 382 | }
|
333 | 383 |
|
| 384 | +func testAccBackupRSOnlineArchiveConfigWithProcessRegion(orgID, projectName, clusterName, cloudProvider, region string) string { |
| 385 | + return fmt.Sprintf(` |
| 386 | + %s |
| 387 | + resource "mongodbatlas_online_archive" "users_archive" { |
| 388 | + project_id = mongodbatlas_cluster.online_archive_test.project_id |
| 389 | + cluster_name = mongodbatlas_cluster.online_archive_test.name |
| 390 | + coll_name = "listingsAndReviews" |
| 391 | + collection_type = "STANDARD" |
| 392 | + db_name = "sample_airbnb" |
| 393 | +
|
| 394 | + criteria { |
| 395 | + type = "DATE" |
| 396 | + date_field = "last_review" |
| 397 | + date_format = "ISODATE" |
| 398 | + expire_after_days = 2 |
| 399 | + } |
| 400 | +
|
| 401 | + partition_fields { |
| 402 | + field_name = "last_review" |
| 403 | + order = 0 |
| 404 | + } |
| 405 | +
|
| 406 | + partition_fields { |
| 407 | + field_name = "maximum_nights" |
| 408 | + order = 1 |
| 409 | + } |
| 410 | +
|
| 411 | + partition_fields { |
| 412 | + field_name = "name" |
| 413 | + order = 2 |
| 414 | + } |
| 415 | +
|
| 416 | + data_process_region { |
| 417 | + cloud_provider = %[2]q |
| 418 | + region = %[3]q |
| 419 | + } |
| 420 | +
|
| 421 | + sync_creation = true |
| 422 | + } |
| 423 | +
|
| 424 | + data "mongodbatlas_online_archive" "read_archive" { |
| 425 | + project_id = mongodbatlas_online_archive.users_archive.project_id |
| 426 | + cluster_name = mongodbatlas_online_archive.users_archive.cluster_name |
| 427 | + archive_id = mongodbatlas_online_archive.users_archive.archive_id |
| 428 | + } |
| 429 | +
|
| 430 | + data "mongodbatlas_online_archives" "all" { |
| 431 | + project_id = mongodbatlas_online_archive.users_archive.project_id |
| 432 | + cluster_name = mongodbatlas_online_archive.users_archive.cluster_name |
| 433 | + } |
| 434 | + `, testAccBackupRSOnlineArchiveConfigFirstStep(orgID, projectName, clusterName), cloudProvider, region) |
| 435 | +} |
| 436 | + |
334 | 437 | func testAccBackupRSOnlineArchiveConfigFirstStep(orgID, projectName, clusterName string) string {
|
335 | 438 | return fmt.Sprintf(`
|
336 | 439 | resource "mongodbatlas_project" "cluster_project" {
|
|
0 commit comments