|
7 | 7 |
|
8 | 8 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
|
9 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
| 10 | + "github.com/mwielbut/pointy" |
10 | 11 | matlas "go.mongodb.org/atlas/mongodbatlas"
|
11 | 12 | )
|
12 | 13 |
|
@@ -57,6 +58,52 @@ func TestAccDataSourceMongoDBAtlasCluster_basic(t *testing.T) {
|
57 | 58 | })
|
58 | 59 | }
|
59 | 60 |
|
| 61 | +func TestAccDataSourceMongoDBAtlasCluster_advancedConf(t *testing.T) { |
| 62 | + var ( |
| 63 | + cluster matlas.Cluster |
| 64 | + resourceName = "mongodbatlas_cluster.test" |
| 65 | + dataSourceName = "data.mongodbatlas_cluster.test" |
| 66 | + projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") |
| 67 | + name = acctest.RandomWithPrefix("test-acc") |
| 68 | + ) |
| 69 | + |
| 70 | + resource.ParallelTest(t, resource.TestCase{ |
| 71 | + PreCheck: func() { testAccPreCheck(t) }, |
| 72 | + ProviderFactories: testAccProviderFactories, |
| 73 | + CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy, |
| 74 | + Steps: []resource.TestStep{ |
| 75 | + { |
| 76 | + Config: testAccDataSourceMongoDBAtlasClusterConfigAdvancedConf(projectID, name, false, &matlas.ProcessArgs{ |
| 77 | + FailIndexKeyTooLong: pointy.Bool(true), |
| 78 | + JavascriptEnabled: pointy.Bool(true), |
| 79 | + MinimumEnabledTLSProtocol: "TLS1_1", |
| 80 | + NoTableScan: pointy.Bool(false), |
| 81 | + OplogSizeMB: pointy.Int64(1000), |
| 82 | + SampleRefreshIntervalBIConnector: pointy.Int64(310), |
| 83 | + SampleSizeBIConnector: pointy.Int64(110), |
| 84 | + }), |
| 85 | + Check: resource.ComposeTestCheckFunc( |
| 86 | + testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster), |
| 87 | + testAccCheckMongoDBAtlasClusterAttributes(&cluster, name), |
| 88 | + resource.TestCheckResourceAttrSet(resourceName, "project_id"), |
| 89 | + resource.TestCheckResourceAttr(resourceName, "name", name), |
| 90 | + resource.TestCheckResourceAttr(resourceName, "disk_size_gb", "10"), |
| 91 | + resource.TestCheckResourceAttrSet(resourceName, "mongo_uri"), |
| 92 | + resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"), |
| 93 | + resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"), |
| 94 | + resource.TestCheckResourceAttrSet(resourceName, "project_id"), |
| 95 | + resource.TestCheckResourceAttr(dataSourceName, "name", name), |
| 96 | + resource.TestCheckResourceAttr(dataSourceName, "disk_size_gb", "10"), |
| 97 | + resource.TestCheckResourceAttr(dataSourceName, "pit_enabled", "false"), |
| 98 | + resource.TestCheckResourceAttrSet(dataSourceName, "mongo_uri"), |
| 99 | + resource.TestCheckResourceAttrSet(dataSourceName, "replication_specs.#"), |
| 100 | + resource.TestCheckResourceAttr(dataSourceName, "version_release_system", "LTS"), |
| 101 | + ), |
| 102 | + }, |
| 103 | + }, |
| 104 | + }) |
| 105 | +} |
| 106 | + |
60 | 107 | func testAccDataSourceMongoDBAtlasClusterConfig(projectID, name, backupEnabled, autoScalingEnabled, scaleDownEnabled, minSizeName, maxSizeName string) string {
|
61 | 108 | return fmt.Sprintf(`
|
62 | 109 | resource "mongodbatlas_cluster" "basic_ds" {
|
@@ -102,3 +149,48 @@ func testAccDataSourceMongoDBAtlasClusterConfig(projectID, name, backupEnabled,
|
102 | 149 | }
|
103 | 150 | `, projectID, name, backupEnabled, autoScalingEnabled, scaleDownEnabled, minSizeName, maxSizeName)
|
104 | 151 | }
|
| 152 | + |
| 153 | +func testAccDataSourceMongoDBAtlasClusterConfigAdvancedConf(projectID, name string, autoscalingEnabled bool, p *matlas.ProcessArgs) string { |
| 154 | + return fmt.Sprintf(` |
| 155 | +resource "mongodbatlas_cluster" "test" { |
| 156 | + project_id = %[1]q |
| 157 | + name = %[2]q |
| 158 | + disk_size_gb = 10 |
| 159 | +
|
| 160 | + cluster_type = "REPLICASET" |
| 161 | + replication_specs { |
| 162 | + num_shards = 1 |
| 163 | + regions_config { |
| 164 | + region_name = "US_EAST_2" |
| 165 | + electable_nodes = 3 |
| 166 | + priority = 7 |
| 167 | + read_only_nodes = 0 |
| 168 | + } |
| 169 | + } |
| 170 | +
|
| 171 | + provider_name = "AWS" |
| 172 | + provider_instance_size_name = "M10" |
| 173 | +
|
| 174 | + backup_enabled = false |
| 175 | + auto_scaling_disk_gb_enabled = %[3]t |
| 176 | + mongo_db_major_version = "4.0" |
| 177 | +
|
| 178 | + advanced_configuration { |
| 179 | + fail_index_key_too_long = %[4]t |
| 180 | + javascript_enabled = %[5]t |
| 181 | + minimum_enabled_tls_protocol = %[6]q |
| 182 | + no_table_scan = %[7]t |
| 183 | + oplog_size_mb = %[8]d |
| 184 | + sample_size_bi_connector = %[9]d |
| 185 | + sample_refresh_interval_bi_connector = %[10]d |
| 186 | + } |
| 187 | +} |
| 188 | +
|
| 189 | +data "mongodbatlas_cluster" "test" { |
| 190 | + project_id = mongodbatlas_cluster.test.project_id |
| 191 | + name = mongodbatlas_cluster.test.name |
| 192 | +} |
| 193 | + `, projectID, name, autoscalingEnabled, |
| 194 | + *p.FailIndexKeyTooLong, *p.JavascriptEnabled, p.MinimumEnabledTLSProtocol, *p.NoTableScan, |
| 195 | + *p.OplogSizeMB, *p.SampleSizeBIConnector, *p.SampleRefreshIntervalBIConnector) |
| 196 | +} |
0 commit comments