From 369c7976e87e39017a197cf1d89e75dc8b6cfdb2 Mon Sep 17 00:00:00 2001 From: Marco Suma Date: Mon, 22 Apr 2024 13:58:03 +0200 Subject: [PATCH] fix: Converts `replication_specs` to TypeList for the advanced_cluster 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 ec4f5951df550ebb2e799ac0631f1f5981cbb458. * 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 f480623042212456906ceb4f82be5f0b21893ece) * removes changelog file from cherry-picked PR. * updates changelog. --------- Co-authored-by: Alex Coomans --- .changelog/2145.txt | 4 +++ .../data_source_advanced_cluster.go | 7 +++--- .../data_source_advanced_clusters.go | 5 ++-- .../resource_advanced_cluster.go | 1 - .../resource_advanced_cluster_test.go | 25 +++++++++++++------ 5 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 .changelog/2145.txt diff --git a/.changelog/2145.txt b/.changelog/2145.txt new file mode 100644 index 0000000000..950f3fe644 --- /dev/null +++ b/.changelog/2145.txt @@ -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. +``` diff --git a/internal/service/advancedcluster/data_source_advanced_cluster.go b/internal/service/advancedcluster/data_source_advanced_cluster.go index f63f2f583e..34c0774ff4 100644 --- a/internal/service/advancedcluster/data_source_advanced_cluster.go +++ b/internal/service/advancedcluster/data_source_advanced_cluster.go @@ -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{ @@ -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{ @@ -208,7 +208,6 @@ func DataSource() *schema.Resource { }, }, }, - Set: replicationSpecsHashSet, }, "root_cert_type": { Type: schema.TypeString, @@ -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)) } diff --git a/internal/service/advancedcluster/data_source_advanced_clusters.go b/internal/service/advancedcluster/data_source_advanced_clusters.go index 2ed07062f7..26e838a11b 100644 --- a/internal/service/advancedcluster/data_source_advanced_clusters.go +++ b/internal/service/advancedcluster/data_source_advanced_clusters.go @@ -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{ @@ -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{ @@ -216,7 +216,6 @@ func PluralDataSource() *schema.Resource { }, }, }, - Set: replicationSpecsHashSet, }, "root_cert_type": { Type: schema.TypeString, diff --git a/internal/service/advancedcluster/resource_advanced_cluster.go b/internal/service/advancedcluster/resource_advanced_cluster.go index 0087c712b1..768c8c6294 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster.go +++ b/internal/service/advancedcluster/resource_advanced_cluster.go @@ -290,7 +290,6 @@ func Resource() *schema.Resource { }, }, }, - // Set: replicationSpecsHashSet, }, "root_cert_type": { Type: schema.TypeString, diff --git a/internal/service/advancedcluster/resource_advanced_cluster_test.go b/internal/service/advancedcluster/resource_advanced_cluster_test.go index 2429a654ef..f833192736 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster_test.go +++ b/internal/service/advancedcluster/resource_advanced_cluster_test.go @@ -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")), ), }, { @@ -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" } } }