Skip to content

Commit

Permalink
fix: Converts replication_specs to TypeList for the advanced_cluste…
Browse files Browse the repository at this point in the history
…r data_source (#2145)

* Change tests in TDD fashion.

* fixes one missing bracket.

* updates from TypeSet to TypeList.

* fixes test expectations.

* inverts region order.

* adds remaining changes.

* adds changelog file.

* Revert "updates from TypeSet to TypeList."

This reverts commit ec4f595.

* fix: Missing replication_specs on mongodbatlas_advanced_cluster(s) data sources

I couldn't quite understand what triggered the `Set: replicationSpecsHashSet`
line in the resource to be commented out but making the data source match
fixes the issue. Possibly because the `region_configs` set would also need
a custom `Set` function?, but either way there aren't any tests that caught
this and I don't have an Atlas organization I can run the tests against to
add one. I did install the provider locally and ran a plan to confirm this
fixes the issue in my Terraformm .One likely reason is that none of the
examples seem to have similar configs across multiple regions (like two
with two electable nodes each).

(cherry picked from commit f480623)

* removes changelog file from cherry-picked PR.

* updates changelog.

---------

Co-authored-by: Alex Coomans <[email protected]>
  • Loading branch information
marcosuma and drcapulet authored Apr 22, 2024
1 parent 3f33dab commit 369c797
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .changelog/2145.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
data-source/mongodbatlas_advanced_cluster: Converts `replication_specs` from TypeSet to TypeList. This fixes an issue where some items were not returned in the results.
data-source/mongodbatlas_advanced_clusters: Converts `replication_specs` from TypeSet to TypeList. This fixes an issue where some items were not returned in the results.
```
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func DataSource() *schema.Resource {
Computed: true,
},
"replication_specs": {
Type: schema.TypeSet,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -113,7 +113,7 @@ func DataSource() *schema.Resource {
Computed: true,
},
"region_configs": {
Type: schema.TypeSet,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -208,7 +208,6 @@ func DataSource() *schema.Resource {
},
},
},
Set: replicationSpecsHashSet,
},
"root_cert_type": {
Type: schema.TypeString,
Expand Down Expand Up @@ -299,7 +298,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "pit_enabled", clusterName, err))
}

replicationSpecs, err := flattenAdvancedReplicationSpecs(ctx, cluster.GetReplicationSpecs(), d.Get("replication_specs").(*schema.Set).List(), d, connV2)
replicationSpecs, err := flattenAdvancedReplicationSpecs(ctx, cluster.GetReplicationSpecs(), d.Get("replication_specs").([]any), d, connV2)
if err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "replication_specs", clusterName, err))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func PluralDataSource() *schema.Resource {
Computed: true,
},
"replication_specs": {
Type: schema.TypeSet,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -121,7 +121,7 @@ func PluralDataSource() *schema.Resource {
Computed: true,
},
"region_configs": {
Type: schema.TypeSet,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -216,7 +216,6 @@ func PluralDataSource() *schema.Resource {
},
},
},
Set: replicationSpecsHashSet,
},
"root_cert_type": {
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func Resource() *schema.Resource {
},
},
},
// Set: replicationSpecsHashSet,
},
"root_cert_type": {
Type: schema.TypeString,
Expand Down
25 changes: 18 additions & 7 deletions internal/service/advancedcluster/resource_advanced_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ func TestAccClusterAdvancedCluster_multicloud(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"),
resource.TestCheckResourceAttrSet(dataSourcePluralName, "results.#"),
resource.TestCheckResourceAttrSet(dataSourcePluralName, "results.0.replication_specs.#"),
resource.TestCheckResourceAttrWith(dataSourcePluralName, "results.0.replication_specs.0.region_configs.#", acc.JSONEquals("3")),
resource.TestCheckResourceAttrSet(dataSourcePluralName, "results.0.name"),
resource.TestCheckResourceAttr(dataSourceName, "name", clusterName),
resource.TestCheckResourceAttrWith(dataSourceName, "replication_specs.0.region_configs.#", acc.JSONEquals("3")),
),
},
{
Expand Down Expand Up @@ -813,14 +815,23 @@ func configMultiCloud(orgID, projectName, name string) string {
priority = 7
region_name = "EU_WEST_1"
}
region_configs {
electable_specs {
instance_size = "M10"
node_count = 2
dynamic "region_configs" {
for_each = [
"US_EAST_4",
"NORTH_AMERICA_NORTHEAST_1"
]
content {
provider_name = "GCP"
priority = 0
region_name = region_configs.value
read_only_specs {
instance_size = "M10"
node_count = 2
}
}
provider_name = "GCP"
priority = 6
region_name = "NORTH_AMERICA_NORTHEAST_1"
}
}
}
Expand Down

0 comments on commit 369c797

Please sign in to comment.