Skip to content

Commit d3a25a5

Browse files
coderGo93Edgar López
andauthored
INTMDB-155: Fixes a bug related to bi_connector cluster by deprecating (#423)
* refactor: deprecated bi_connector and added parameter bi_connector_config because of issues typemap related in tf 14 * test: added to test to validate if it works or not * docs: updated docs for deprecated and added parameter bi_connector_config * fix: fixes linter code Co-authored-by: Edgar López <[email protected]>
1 parent 9319bbf commit d3a25a5

7 files changed

+202
-18
lines changed

mongodbatlas/data_source_mongodbatlas_cluster.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ func dataSourceMongoDBAtlasCluster() *schema.Resource {
3939
Computed: true,
4040
},
4141
"bi_connector": {
42-
Type: schema.TypeMap,
43-
Computed: true,
42+
Type: schema.TypeMap,
43+
Computed: true,
44+
Deprecated: "use bi_connector_config instead",
4445
Elem: &schema.Resource{
4546
Schema: map[string]*schema.Schema{
4647
"enabled": {
@@ -54,6 +55,23 @@ func dataSourceMongoDBAtlasCluster() *schema.Resource {
5455
},
5556
},
5657
},
58+
"bi_connector_config": {
59+
Type: schema.TypeList,
60+
Computed: true,
61+
MaxItems: 1,
62+
Elem: &schema.Resource{
63+
Schema: map[string]*schema.Schema{
64+
"enabled": {
65+
Type: schema.TypeBool,
66+
Computed: true,
67+
},
68+
"read_preference": {
69+
Type: schema.TypeString,
70+
Computed: true,
71+
},
72+
},
73+
},
74+
},
5775
"cluster_type": {
5876
Type: schema.TypeString,
5977
Computed: true,
@@ -391,6 +409,10 @@ func dataSourceMongoDBAtlasClusterRead(d *schema.ResourceData, meta interface{})
391409
return fmt.Errorf(errorClusterSetting, "bi_connector", clusterName, err)
392410
}
393411

412+
if err := d.Set("bi_connector_config", flattenBiConnectorConfig(cluster.BiConnector)); err != nil {
413+
return fmt.Errorf(errorClusterSetting, "bi_connector_config", clusterName, err)
414+
}
415+
394416
if cluster.ProviderSettings != nil {
395417
flattenProviderSettings(d, cluster.ProviderSettings, clusterName)
396418
}

mongodbatlas/data_source_mongodbatlas_clusters.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ func dataSourceMongoDBAtlasClusters() *schema.Resource {
4646
Computed: true,
4747
},
4848
"bi_connector": {
49-
Type: schema.TypeMap,
50-
Computed: true,
49+
Type: schema.TypeMap,
50+
Computed: true,
51+
Deprecated: "use bi_connector_config instead",
5152
Elem: &schema.Resource{
5253
Schema: map[string]*schema.Schema{
5354
"enabled": {
@@ -61,6 +62,23 @@ func dataSourceMongoDBAtlasClusters() *schema.Resource {
6162
},
6263
},
6364
},
65+
"bi_connector_config": {
66+
Type: schema.TypeList,
67+
Computed: true,
68+
MaxItems: 1,
69+
Elem: &schema.Resource{
70+
Schema: map[string]*schema.Schema{
71+
"enabled": {
72+
Type: schema.TypeBool,
73+
Computed: true,
74+
},
75+
"read_preference": {
76+
Type: schema.TypeString,
77+
Computed: true,
78+
},
79+
},
80+
},
81+
},
6482
"cluster_type": {
6583
Type: schema.TypeString,
6684
Computed: true,
@@ -370,6 +388,7 @@ func flattenClusters(d *schema.ResourceData, conn *matlas.Client, clusters []mat
370388
"provider_name": clusters[i].ProviderSettings.ProviderName,
371389
"provider_region_name": clusters[i].ProviderSettings.RegionName,
372390
"bi_connector": flattenBiConnector(clusters[i].BiConnector),
391+
"bi_connector_config": flattenBiConnectorConfig(clusters[i].BiConnector),
373392
"replication_specs": flattenReplicationSpecs(clusters[i].ReplicationSpecs),
374393
"labels": flattenLabels(clusters[i].Labels),
375394
"snapshot_backup_policy": snapshotBackupPolicy,

mongodbatlas/resource_mongodbatlas_cluster.go

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,34 @@ func resourceMongoDBAtlasCluster() *schema.Resource {
8484
Default: false,
8585
},
8686
"bi_connector": {
87-
Type: schema.TypeMap,
88-
Optional: true,
89-
Computed: true,
87+
Type: schema.TypeMap,
88+
Optional: true,
89+
Deprecated: "use bi_connector_config instead",
90+
ConflictsWith: []string{"bi_connector_config"},
9091
Elem: &schema.Resource{
9192
Schema: map[string]*schema.Schema{
9293
"enabled": {
9394
Type: schema.TypeString,
9495
Optional: true,
96+
},
97+
"read_preference": {
98+
Type: schema.TypeString,
99+
Optional: true,
100+
},
101+
},
102+
},
103+
},
104+
"bi_connector_config": {
105+
Type: schema.TypeList,
106+
Optional: true,
107+
Computed: true,
108+
MaxItems: 1,
109+
ConflictsWith: []string{"bi_connector"},
110+
Elem: &schema.Resource{
111+
Schema: map[string]*schema.Schema{
112+
"enabled": {
113+
Type: schema.TypeBool,
114+
Optional: true,
95115
Computed: true,
96116
},
97117
"read_preference": {
@@ -467,11 +487,6 @@ func resourceMongoDBAtlasClusterCreate(d *schema.ResourceData, meta interface{})
467487
}
468488
}
469489

470-
biConnector, err := expandBiConnector(d)
471-
if err != nil {
472-
return fmt.Errorf(errorClusterCreate, err)
473-
}
474-
475490
providerSettings, err := expandProviderSetting(d)
476491
if err != nil {
477492
return fmt.Errorf(errorClusterCreate, err)
@@ -490,11 +505,26 @@ func resourceMongoDBAtlasClusterCreate(d *schema.ResourceData, meta interface{})
490505
ProviderBackupEnabled: pointy.Bool(d.Get("provider_backup_enabled").(bool)),
491506
PitEnabled: pointy.Bool(d.Get("pit_enabled").(bool)),
492507
AutoScaling: autoScaling,
493-
BiConnector: biConnector,
494508
ProviderSettings: providerSettings,
495509
ReplicationSpecs: replicationSpecs,
496510
}
497511

512+
if _, ok := d.GetOk("bi_connector"); ok {
513+
biConnector, err := expandBiConnector(d)
514+
if err != nil {
515+
return fmt.Errorf(errorClusterCreate, err)
516+
}
517+
clusterRequest.BiConnector = biConnector
518+
}
519+
520+
if _, ok := d.GetOk("bi_connector_config"); ok {
521+
biConnector, err := expandBiConnector(d)
522+
if err != nil {
523+
return fmt.Errorf(errorClusterCreate, err)
524+
}
525+
clusterRequest.BiConnector = biConnector
526+
}
527+
498528
if containsLabelOrKey(expandLabelSliceFromSetSchema(d), defaultLabel) {
499529
return fmt.Errorf("you should not set `Infrastructure Tool` label, it is used for internal purposes")
500530
}
@@ -676,8 +706,14 @@ func resourceMongoDBAtlasClusterRead(d *schema.ResourceData, meta interface{}) e
676706
return fmt.Errorf(errorClusterSetting, "state_name", clusterName, err)
677707
}
678708

679-
if err := d.Set("bi_connector", flattenBiConnector(cluster.BiConnector)); err != nil {
680-
return fmt.Errorf(errorClusterSetting, "bi_connector", clusterName, err)
709+
if _, ok := d.GetOk("bi_connector"); ok {
710+
if err = d.Set("bi_connector", flattenBiConnector(cluster.BiConnector)); err != nil {
711+
return fmt.Errorf(errorClusterSetting, "bi_connector", clusterName, err)
712+
}
713+
}
714+
715+
if err := d.Set("bi_connector_config", flattenBiConnectorConfig(cluster.BiConnector)); err != nil {
716+
return fmt.Errorf(errorClusterSetting, "bi_connector_config", clusterName, err)
681717
}
682718

683719
if cluster.ProviderSettings != nil {
@@ -746,6 +782,10 @@ func resourceMongoDBAtlasClusterUpdate(d *schema.ResourceData, meta interface{})
746782
cluster.BiConnector, _ = expandBiConnector(d)
747783
}
748784

785+
if d.HasChange("bi_connector_config") {
786+
cluster.BiConnector, _ = expandBiConnectorConfig(d)
787+
}
788+
749789
// If at least one of the provider settings argument has changed, expand all provider settings
750790
if d.HasChange("provider_disk_iops") ||
751791
d.HasChange("backing_provider_name") ||
@@ -956,6 +996,7 @@ func splitSClusterImportID(id string) (projectID, clusterName *string, err error
956996
return
957997
}
958998

999+
// Deprecated: will be deleted later
9591000
func expandBiConnector(d *schema.ResourceData) (*matlas.BiConnector, error) {
9601001
var biConnector matlas.BiConnector
9611002

@@ -973,6 +1014,27 @@ func expandBiConnector(d *schema.ResourceData) (*matlas.BiConnector, error) {
9731014
return &biConnector, nil
9741015
}
9751016

1017+
func expandBiConnectorConfig(d *schema.ResourceData) (*matlas.BiConnector, error) {
1018+
var biConnector matlas.BiConnector
1019+
1020+
if v, ok := d.GetOk("bi_connector_config"); ok {
1021+
biConn := v.([]interface{})
1022+
if len(biConn) > 0 {
1023+
biConnMap := biConn[0].(map[string]interface{})
1024+
1025+
enabled := cast.ToBool(biConnMap["enabled"])
1026+
1027+
biConnector = matlas.BiConnector{
1028+
Enabled: &enabled,
1029+
ReadPreference: cast.ToString(biConnMap["read_preference"]),
1030+
}
1031+
}
1032+
}
1033+
1034+
return &biConnector, nil
1035+
}
1036+
1037+
// Deprecated: will be deleted later
9761038
func flattenBiConnector(biConnector *matlas.BiConnector) map[string]interface{} {
9771039
biConnectorMap := make(map[string]interface{})
9781040

@@ -987,6 +1049,15 @@ func flattenBiConnector(biConnector *matlas.BiConnector) map[string]interface{}
9871049
return biConnectorMap
9881050
}
9891051

1052+
func flattenBiConnectorConfig(biConnector *matlas.BiConnector) []interface{} {
1053+
return []interface{}{
1054+
map[string]interface{}{
1055+
"enabled": *biConnector.Enabled,
1056+
"read_preference": biConnector.ReadPreference,
1057+
},
1058+
}
1059+
}
1060+
9901061
func getInstanceSizeToInt(instanceSize string) int {
9911062
regex := regexp.MustCompile(`\d+`)
9921063
num := regex.FindString(instanceSize)

mongodbatlas/resource_mongodbatlas_cluster_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,51 @@ func TestAccResourceMongoDBAtlasCluster_basicGCP(t *testing.T) {
348348
})
349349
}
350350

351+
func TestAccResourceMongoDBAtlasCluster_WithBiConnectorGCP(t *testing.T) {
352+
var (
353+
cluster matlas.Cluster
354+
resourceName = "mongodbatlas_cluster.basic_gcp"
355+
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
356+
name = fmt.Sprintf("test-acc-%s", acctest.RandString(10))
357+
)
358+
359+
resource.ParallelTest(t, resource.TestCase{
360+
PreCheck: func() { testAccPreCheck(t) },
361+
Providers: testAccProviders,
362+
CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy,
363+
Steps: []resource.TestStep{
364+
{
365+
Config: testAccMongoDBAtlasClusterConfigGCPWithBiConnector(projectID, name, "true", false),
366+
Check: resource.ComposeTestCheckFunc(
367+
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
368+
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
369+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
370+
resource.TestCheckResourceAttr(resourceName, "name", name),
371+
resource.TestCheckResourceAttr(resourceName, "disk_size_gb", "40"),
372+
resource.TestCheckResourceAttrSet(resourceName, "mongo_uri"),
373+
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
374+
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"),
375+
resource.TestCheckResourceAttr(resourceName, "bi_connector_config.0.enabled", "false"),
376+
),
377+
},
378+
{
379+
Config: testAccMongoDBAtlasClusterConfigGCPWithBiConnector(projectID, name, "false", true),
380+
Check: resource.ComposeTestCheckFunc(
381+
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
382+
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
383+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
384+
resource.TestCheckResourceAttr(resourceName, "name", name),
385+
resource.TestCheckResourceAttr(resourceName, "disk_size_gb", "40"),
386+
resource.TestCheckResourceAttrSet(resourceName, "mongo_uri"),
387+
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
388+
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"),
389+
resource.TestCheckResourceAttr(resourceName, "bi_connector_config.0.enabled", "true"),
390+
),
391+
},
392+
},
393+
})
394+
}
395+
351396
func TestAccResourceMongoDBAtlasCluster_MultiRegion(t *testing.T) {
352397
var (
353398
cluster matlas.Cluster
@@ -1065,6 +1110,30 @@ func testAccMongoDBAtlasClusterConfigGCP(projectID, name, backupEnabled string)
10651110
`, projectID, name, backupEnabled)
10661111
}
10671112

1113+
func testAccMongoDBAtlasClusterConfigGCPWithBiConnector(projectID, name, backupEnabled string, biConnectorEnabled bool) string {
1114+
return fmt.Sprintf(`
1115+
resource "mongodbatlas_cluster" "basic_gcp" {
1116+
project_id = "%s"
1117+
name = "%s"
1118+
disk_size_gb = 40
1119+
num_shards = 1
1120+
1121+
replication_factor = 3
1122+
provider_backup_enabled = %s
1123+
auto_scaling_disk_gb_enabled = true
1124+
mongo_db_major_version = "4.0"
1125+
1126+
// Provider Settings "block"
1127+
provider_name = "GCP"
1128+
provider_instance_size_name = "M30"
1129+
provider_region_name = "US_EAST_4"
1130+
bi_connector_config {
1131+
enabled = %t
1132+
}
1133+
}
1134+
`, projectID, name, backupEnabled, biConnectorEnabled)
1135+
}
1136+
10681137
func testAccMongoDBAtlasClusterConfigMultiRegion(projectID, name, backupEnabled string) string {
10691138
return fmt.Sprintf(`
10701139
resource "mongodbatlas_cluster" "multi_region" {

website/docs/d/cluster.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ In addition to all arguments above, the following attributes are exported:
8282
* `auto_scaling_compute_scale_down_enabled` - (Optional) Set to `true` to enable the cluster tier to scale down.
8383

8484
* `backup_enabled` - Legacy Option, Indicates whether Atlas continuous backups are enabled for the cluster.
85-
* `bi_connector` - Indicates BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details.
85+
* `bi_connector` - Indicates BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details. **DEPRECATED** Use `bi_connector_config` instead.
86+
* `bi_connector_config` - Indicates BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details.
8687
* `cluster_type` - Indicates the type of the cluster that you want to modify. You cannot convert a sharded cluster deployment to a replica set deployment.
8788
* `connection_strings` - Set of connection strings that your applications use to connect to this cluster. More info in [Connection-strings](https://docs.mongodb.com/manual/reference/connection-string/). Use the parameters in this object to connect your applications to this cluster. To learn more about the formats of connection strings, see [Connection String Options](https://docs.atlas.mongodb.com/reference/faq/connection-changes/). NOTE: Atlas returns the contents of this object after the cluster is operational, not while it builds the cluster.
8889
- `connection_strings.standard` - Public mongodb:// connection string for this cluster.

website/docs/d/clusters.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ In addition to all arguments above, the following attributes are exported:
8484
* `auto_scaling_compute_enabled` - (Optional) Specifies whether cluster tier auto-scaling is enabled. The default is false.
8585
* `auto_scaling_compute_scale_down_enabled` - (Optional) Set to `true` to enable the cluster tier to scale down.
8686
* `backup_enabled` - Legacy Option, Indicates whether Atlas continuous backups are enabled for the cluster.
87-
* `bi_connector` - Indicates BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details.
87+
* `bi_connector` - Indicates BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details. **DEPRECATED** Use `bi_connector_config` instead.
88+
* `bi_connector_config` - Indicates BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details.
8889
* `cluster_type` - Indicates the type of the cluster that you want to modify. You cannot convert a sharded cluster deployment to a replica set deployment.
8990
* `connection_strings` - Set of connection strings that your applications use to connect to this cluster. More info in [Connection-strings](https://docs.mongodb.com/manual/reference/connection-string/). Use the parameters in this object to connect your applications to this cluster. To learn more about the formats of connection strings, see [Connection String Options](https://docs.atlas.mongodb.com/reference/faq/connection-changes/). NOTE: Atlas returns the contents of this object after the cluster is operational, not while it builds the cluster.
9091
- `connection_strings.standard` - Public mongodb:// connection string for this cluster.

website/docs/r/cluster.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ But in order to explicitly change `provider_instance_size_name` comment the `lif
264264
```
265265
* The default value is false. M10 and above only.
266266

267-
* `bi_connector` - (Optional) Specifies BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details.
267+
* `bi_connector` - (Optional) Specifies BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details. **DEPRECATED** Use `bi_connector_config` instead.
268+
* `bi_connector_config` - (Optional) Specifies BI Connector for Atlas configuration on this cluster. BI Connector for Atlas is only available for M10+ clusters. See [BI Connector](#bi-connector) below for more details.
268269
* `cluster_type` - (Required) Specifies the type of the cluster that you want to modify. You cannot convert a sharded cluster deployment to a replica set deployment.
269270

270271
-> **WHEN SHOULD YOU USE CLUSTERTYPE?**

0 commit comments

Comments
 (0)