From ba0705cd3aef7e3b280359b7a6361d7333c93a28 Mon Sep 17 00:00:00 2001 From: zach-carr <54542042+zach-carr@users.noreply.github.com> Date: Tue, 26 Mar 2024 14:25:50 -0400 Subject: [PATCH 01/11] doc: Fixes import command in third_party_integration doc (#2083) * (DOCSP-36813) Fix import command in third_party_integration doc --- website/docs/r/third_party_integration.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/r/third_party_integration.markdown b/website/docs/r/third_party_integration.markdown index 54154bf2e6..29fa672bbd 100644 --- a/website/docs/r/third_party_integration.markdown +++ b/website/docs/r/third_party_integration.markdown @@ -24,10 +24,10 @@ description: |- ```terraform resource "mongodbatlas_third_party_integration" "test_datadog" { - project_id = "" + project_id = "" type = "DATADOG" - api_key = "" - region = "" + api_key = "" + region = "" } ``` @@ -78,7 +78,7 @@ resource "mongodbatlas_third_party_integration" "test_datadog" { Third-Party Integration Settings can be imported using project ID and the integration type, in the format `project_id`-`type`, e.g. ``` -$ terraform import mongodbatlas_database_user.my_user 1112222b3bf99403840e8934-OPS_GENIE +$ terraform import mongodbatlas_third_party_integration.test_datadog 1112222b3bf99403840e8934-DATADOG ``` See [MongoDB Atlas API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Third-Party-Integrations/operation/createThirdPartyIntegration) Documentation for more information. From 09dc5c6d556999a59f6b7cd8a94dae54fd56dfef Mon Sep 17 00:00:00 2001 From: Oriol Date: Wed, 27 Mar 2024 09:44:13 +0100 Subject: [PATCH 02/11] doc: Specifies that upgrades From Replica Sets to Multi-Sharded Instances of cluster and advanced cluster might lead to error (#2080) * add upgrade from replica set to sharded info * update cluster documentation for replication spec * align num_shard description with API --- website/docs/r/advanced_cluster.html.markdown | 1 + website/docs/r/cluster.html.markdown | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/website/docs/r/advanced_cluster.html.markdown b/website/docs/r/advanced_cluster.html.markdown index c0b4f63ee9..c6d1cb2cc9 100644 --- a/website/docs/r/advanced_cluster.html.markdown +++ b/website/docs/r/advanced_cluster.html.markdown @@ -539,6 +539,7 @@ replication_specs { ``` * `num_shards` - (Required) Provide this value if you set a `cluster_type` of SHARDED or GEOSHARDED. Omit this value if you selected a `cluster_type` of REPLICASET. This API resource accepts 1 through 50, inclusive. This parameter defaults to 1. If you specify a `num_shards` value of 1 and a `cluster_type` of SHARDED, Atlas deploys a single-shard [sharded cluster](https://docs.atlas.mongodb.com/reference/glossary/#std-term-sharded-cluster). Don't create a sharded cluster with a single shard for production environments. Single-shard sharded clusters don't provide the same benefits as multi-shard configurations. +If you are upgrading a replica set to a sharded cluster, you cannot increase the number of shards in the same update request. You should wait until after the cluster has completed upgrading to sharded and you have reconnected all application clients to the MongoDB router before adding additional shards. Otherwise, your data might become inconsistent once MongoDB Cloud begins distributing data across shards. To learn more, see [Convert a replica set to a sharded cluster documentation](https://www.mongodb.com/docs/atlas/scale-cluster/#convert-a-replica-set-to-a-sharded-cluster) and [Convert a replica set to a sharded cluster tutorial](https://www.mongodb.com/docs/upcoming/tutorial/convert-replica-set-to-replicated-shard-cluster). * `region_configs` - (Optional) Configuration for the hardware specifications for nodes set for a given regionEach `region_configs` object describes the region's priority in elections and the number and type of MongoDB nodes that Atlas deploys to the region. Each `region_configs` object must have either an `analytics_specs` object, `electable_specs` object, or `read_only_specs` object. See [below](#region_configs) * `zone_name` - (Optional) Name for the zone in a Global Cluster. diff --git a/website/docs/r/cluster.html.markdown b/website/docs/r/cluster.html.markdown index 1f456d359e..60f3d2237d 100644 --- a/website/docs/r/cluster.html.markdown +++ b/website/docs/r/cluster.html.markdown @@ -424,7 +424,8 @@ replication_specs { **Replication Spec** - Configuration block for multi-region cluster. -* `num_shards` - (Required) Number of shards to deploy in the specified zone, minimum 1. +* `num_shards` - (Required) Number of shards up to 50 to deploy for a sharded cluster. The resource returns 1 to indicate a replica set and values of 2 and higher to indicate a sharded cluster. The returned value equals the number of shards in the cluster. +If you are upgrading a replica set to a sharded cluster, you cannot increase the number of shards in the same update request. You should wait until after the cluster has completed upgrading to sharded and you have reconnected all application clients to the MongoDB router before adding additional shards. Otherwise, your data might become inconsistent once MongoDB Cloud begins distributing data across shards. To learn more, see [Convert a replica set to a sharded cluster documentation](https://www.mongodb.com/docs/atlas/scale-cluster/#convert-a-replica-set-to-a-sharded-cluster) and [Convert a replica set to a sharded cluster tutorial](https://www.mongodb.com/docs/upcoming/tutorial/convert-replica-set-to-replicated-shard-cluster). * `id` - (Optional) Unique identifer of the replication document for a zone in a Global Cluster. * `regions_config` - (Optional) Physical location of the region. Each regionsConfig document describes the region’s priority in elections and the number and type of MongoDB nodes Atlas deploys to the region. You must order each regionsConfigs document by regionsConfig.priority, descending. See [Region Config](#region-config) below for more details. * `zone_name` - (Optional) Name for the zone in a Global Cluster. From 81f01b46eaf305256d2b515a97640570f9a97dcf Mon Sep 17 00:00:00 2001 From: Oriol Date: Wed, 27 Mar 2024 10:04:40 +0100 Subject: [PATCH 03/11] chore: Fixes Slack notification button to GH action run text (#2093) --- .github/workflows/test-suite.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index bcbff404d8..5a3a3d56b5 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -112,7 +112,7 @@ jobs: "type": "button", "text": { "type": "plain_text", - "text": ":github: $action_text" + "text": ":github: Failed action" }, "url": "${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}" } From e8215b2839d3ad69126d8684194443d08d02ffaa Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Wed, 27 Mar 2024 09:14:52 +0000 Subject: [PATCH 04/11] test: Converting a test case to a migration test (#2081) --- .../resource_search_index_migration_test.go | 60 +-------- .../searchindex/resource_search_index_test.go | 74 +++++++----- internal/testutil/acc/provider.go | 4 +- internal/testutil/mig/test_case.go | 71 +++++++++++ internal/testutil/mig/test_case_test.go | 114 ++++++++++++++++++ 5 files changed, 233 insertions(+), 90 deletions(-) create mode 100644 internal/testutil/mig/test_case.go create mode 100644 internal/testutil/mig/test_case_test.go diff --git a/internal/service/searchindex/resource_search_index_migration_test.go b/internal/service/searchindex/resource_search_index_migration_test.go index 789962cf41..0cc1138662 100644 --- a/internal/service/searchindex/resource_search_index_migration_test.go +++ b/internal/service/searchindex/resource_search_index_migration_test.go @@ -3,69 +3,13 @@ package searchindex_test import ( "testing" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig" ) func TestMigSearchIndex_basic(t *testing.T) { - var ( - clusterInfo = acc.GetClusterInfo(t, nil) - indexName = acc.RandomName() - databaseName = acc.RandomName() - config = configBasic(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, false) - ) - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { mig.PreCheckBasic(t) }, - CheckDestroy: acc.CheckDestroySearchIndex, - Steps: []resource.TestStep{ - { - Config: config, - ExternalProviders: mig.ExternalProviders(), - Check: resource.ComposeTestCheckFunc( - checkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", indexName), - resource.TestCheckResourceAttrSet(resourceName, "project_id"), - resource.TestCheckResourceAttr(resourceName, "cluster_name", clusterInfo.ClusterName), - resource.TestCheckResourceAttr(resourceName, "database", databaseName), - resource.TestCheckResourceAttr(resourceName, "collection_name", collectionName), - resource.TestCheckResourceAttr(resourceName, "search_analyzer", searchAnalyzer), - resource.TestCheckResourceAttr(resourceName, "type", ""), - ), - }, - mig.TestStepCheckEmptyPlan(config), - }, - }) + mig.CreateAndRunTest(t, basicTestCase(t)) } func TestMigSearchIndex_withVector(t *testing.T) { - var ( - clusterInfo = acc.GetClusterInfo(t, nil) - indexName = acc.RandomName() - databaseName = acc.RandomName() - config = configVector(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr) - ) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { mig.PreCheckBasic(t) }, - CheckDestroy: acc.CheckDestroySearchIndex, - Steps: []resource.TestStep{ - { - Config: config, - ExternalProviders: mig.ExternalProviders(), - Check: resource.ComposeTestCheckFunc( - checkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", indexName), - resource.TestCheckResourceAttrSet(resourceName, "project_id"), - resource.TestCheckResourceAttr(resourceName, "cluster_name", clusterInfo.ClusterName), - resource.TestCheckResourceAttr(resourceName, "database", databaseName), - resource.TestCheckResourceAttr(resourceName, "collection_name", collectionName), - resource.TestCheckResourceAttr(resourceName, "type", "vectorSearch"), - resource.TestCheckResourceAttrSet(resourceName, "fields"), - resource.TestCheckResourceAttrWith(resourceName, "fields", acc.JSONEquals(fieldsJSON)), - ), - }, - mig.TestStepCheckEmptyPlan(config), - }, - }) + mig.CreateAndRunTest(t, basicVectorTestCase(t)) } diff --git a/internal/service/searchindex/resource_search_index_test.go b/internal/service/searchindex/resource_search_index_test.go index c4e41ed532..230c059075 100644 --- a/internal/service/searchindex/resource_search_index_test.go +++ b/internal/service/searchindex/resource_search_index_test.go @@ -12,33 +12,7 @@ import ( ) func TestAccSearchIndex_basic(t *testing.T) { - var ( - clusterInfo = acc.GetClusterInfo(t, nil) - indexName = acc.RandomName() - databaseName = acc.RandomName() - indexType = "" - mappingsDynamic = "true" - ) - checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterInfo) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheckBasic(t) }, - ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - CheckDestroy: acc.CheckDestroySearchIndex, - Steps: []resource.TestStep{ - { - Config: configBasic(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, false), - Check: resource.ComposeTestCheckFunc(checks...), - }, - { - Config: configBasic(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, false), - ResourceName: resourceName, - ImportStateIdFunc: importStateIDFunc(resourceName), - ImportState: true, - ImportStateVerify: true, - }, - }, - }) + resource.ParallelTest(t, *basicTestCase(t)) } func TestAccSearchIndex_withSearchType(t *testing.T) { @@ -208,8 +182,44 @@ func TestAccSearchIndex_updatedToEmptyMappingsFields(t *testing.T) { } func TestAccSearchIndex_withVector(t *testing.T) { + resource.ParallelTest(t, *basicVectorTestCase(t)) +} + +func basicTestCase(tb testing.TB) *resource.TestCase { + tb.Helper() var ( - clusterInfo = acc.GetClusterInfo(t, nil) + clusterInfo = acc.GetClusterInfo(tb, nil) + indexName = acc.RandomName() + databaseName = acc.RandomName() + indexType = "" + mappingsDynamic = "true" + ) + checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterInfo) + + return &resource.TestCase{ + PreCheck: func() { acc.PreCheckBasic(tb) }, + ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, + CheckDestroy: acc.CheckDestroySearchIndex, + Steps: []resource.TestStep{ + { + Config: configBasic(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, false), + Check: resource.ComposeTestCheckFunc(checks...), + }, + { + Config: configBasic(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, false), + ResourceName: resourceName, + ImportStateIdFunc: importStateIDFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + }, + }, + } +} + +func basicVectorTestCase(tb testing.TB) *resource.TestCase { + tb.Helper() + var ( + clusterInfo = acc.GetClusterInfo(tb, nil) indexName = acc.RandomName() indexType = "vectorSearch" databaseName = acc.RandomName() @@ -225,8 +235,9 @@ func TestAccSearchIndex_withVector(t *testing.T) { checks = acc.AddAttrSetChecks(resourceName, checks, "project_id") checks = acc.AddAttrSetChecks(datasourceName, checks, "project_id", "index_id") checks = append(checks, resource.TestCheckResourceAttrWith(datasourceName, "fields", acc.JSONEquals(fieldsJSON))) - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acc.PreCheckBasic(t) }, + + return &resource.TestCase{ + PreCheck: func() { acc.PreCheckBasic(tb) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, CheckDestroy: acc.CheckDestroySearchIndex, Steps: []resource.TestStep{ @@ -235,8 +246,9 @@ func TestAccSearchIndex_withVector(t *testing.T) { Check: resource.ComposeTestCheckFunc(checks...), }, }, - }) + } } + func commonChecks(indexName, indexType, mappingsDynamic, databaseName string, clusterInfo acc.ClusterInfo) []resource.TestCheckFunc { attributes := map[string]string{ "name": indexName, diff --git a/internal/testutil/acc/provider.go b/internal/testutil/acc/provider.go index 2abd09551d..948b913e77 100644 --- a/internal/testutil/acc/provider.go +++ b/internal/testutil/acc/provider.go @@ -4,6 +4,8 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) +const AwsProviderVersion = "5.1.0" + func ExternalProviders(versionAtlasProvider string) map[string]resource.ExternalProvider { return map[string]resource.ExternalProvider{ "mongodbatlas": *providerAtlas(versionAtlasProvider), @@ -32,7 +34,7 @@ func providerAtlas(versionAtlasProvider string) *resource.ExternalProvider { func providerAWS() *resource.ExternalProvider { return &resource.ExternalProvider{ - VersionConstraint: "5.1.0", + VersionConstraint: AwsProviderVersion, Source: "hashicorp/aws", } } diff --git a/internal/testutil/mig/test_case.go b/internal/testutil/mig/test_case.go new file mode 100644 index 0000000000..6d63dcb688 --- /dev/null +++ b/internal/testutil/mig/test_case.go @@ -0,0 +1,71 @@ +package mig + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/require" +) + +func CreateAndRunTest(t *testing.T, test *resource.TestCase) { + t.Helper() + resource.ParallelTest(t, CreateTest(t, test)) +} + +func CreateTestAndRunUseExternalProvider(t *testing.T, test *resource.TestCase, externalProviders, additionalProviders map[string]resource.ExternalProvider) { + t.Helper() + resource.ParallelTest(t, CreateTestUseExternalProvider(t, test, externalProviders, additionalProviders)) +} + +// CreateTest returns a new TestCase that reuses step 1 and adds a TestStepCheckEmptyPlan. +// Requires: `MONGODB_ATLAS_LAST_VERSION` to be present. +func CreateTest(t *testing.T, test *resource.TestCase) resource.TestCase { + t.Helper() + validateReusableCase(t, test) + firstStep := test.Steps[0] + steps := []resource.TestStep{ + useExternalProvider(&firstStep, ExternalProviders()), + TestStepCheckEmptyPlan(firstStep.Config), + } + newTest := reuseCase(test, steps) + return newTest +} + +// CreateTestUseExternalProvider returns a new TestCase that reuses step 1 and adds a TestStepCheckEmptyPlan with the additionalProviders. +// Requires: `MONGODB_ATLAS_LAST_VERSION` to be present. +// externalProviders: e.g., ExternalProvidersWithAWS() or ExternalProviders("specific_sem_ver"). +// additionalProviders: e.g., acc.ExternalProvidersOnlyAWS(), can also be nil. +func CreateTestUseExternalProvider(t *testing.T, test *resource.TestCase, externalProviders, additionalProviders map[string]resource.ExternalProvider) resource.TestCase { + t.Helper() + validateReusableCase(t, test) + firstStep := test.Steps[0] + require.NotContains(t, additionalProviders, "mongodbatlas", "Will use the local provider, cannot specify mongodbatlas provider") + emptyPlanStep := TestStepCheckEmptyPlan(firstStep.Config) + steps := []resource.TestStep{ + useExternalProvider(&firstStep, externalProviders), + useExternalProvider(&emptyPlanStep, additionalProviders), + } + return reuseCase(test, steps) +} + +func validateReusableCase(tb testing.TB, test *resource.TestCase) { + tb.Helper() + checkLastVersion(tb) + require.GreaterOrEqual(tb, len(test.Steps), 1, "Must have at least 1 test step.") + require.NotEmpty(tb, test.Steps[0].Config, "First step of migration test must use Config") +} + +func useExternalProvider(step *resource.TestStep, provider map[string]resource.ExternalProvider) resource.TestStep { + step.ExternalProviders = provider + return *step +} + +// Note how we don't set ProtoV6ProviderFactories and instead specify providers on each step. +func reuseCase(test *resource.TestCase, steps []resource.TestStep) resource.TestCase { + return resource.TestCase{ + PreCheck: test.PreCheck, + CheckDestroy: test.CheckDestroy, + ErrorCheck: test.ErrorCheck, + Steps: steps, + } +} diff --git a/internal/testutil/mig/test_case_test.go b/internal/testutil/mig/test_case_test.go new file mode 100644 index 0000000000..1e30407bed --- /dev/null +++ b/internal/testutil/mig/test_case_test.go @@ -0,0 +1,114 @@ +package mig_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig" + "github.com/stretchr/testify/assert" +) + +func TestConvertToMigration(t *testing.T) { + t.Setenv("MONGODB_ATLAS_LAST_VERSION", "1.2.3") + var ( + preCheckCalled = false + checkDestroyCalled = false + config = "someTerraformConfig" + ) + preCheck := func() { + preCheckCalled = true + } + firstStep := resource.TestStep{ + Config: config, + Check: resource.TestCheckResourceAttrSet("someTarget", "someAttribute"), + } + + asserter := assert.New(t) + + convertAndCall := func(test resource.TestCase) resource.TestCase { + newTest := mig.CreateTest(t, &test) + newTest.PreCheck() + if newTest.CheckDestroy != nil { + asserter.NoError(newTest.CheckDestroy(nil)) + } + return newTest + } + defaultAssertions := func(test resource.TestCase) { + t.Helper() + asserter.Len(test.Steps, 2, "Expected 2 steps (one extra test step)") + newFirstStep := test.Steps[0] + asserter.Equal(config, newFirstStep.Config) + + planStep := test.Steps[1] + asserter.Equal(mig.TestStepCheckEmptyPlan(config), planStep) + } + + t.Run("normal call with check and destroy", func(t *testing.T) { + checkDestroy := func(*terraform.State) error { + checkDestroyCalled = true + return nil + } + test := convertAndCall(resource.TestCase{ + PreCheck: preCheck, + CheckDestroy: checkDestroy, + Steps: []resource.TestStep{ + firstStep, + }, + }) + asserter.True(preCheckCalled) + asserter.True(checkDestroyCalled) + defaultAssertions(test) + }) + + t.Run("checkDestroy=nil has no panic", func(t *testing.T) { + test := convertAndCall(resource.TestCase{ + PreCheck: preCheck, + Steps: []resource.TestStep{ + firstStep, + }, + }) + defaultAssertions(test) + }) + + t.Run("more than 1 step uses only 1 step", func(t *testing.T) { + test := convertAndCall(resource.TestCase{ + PreCheck: preCheck, + Steps: []resource.TestStep{ + firstStep, + { + Config: "differentConfig", + Check: resource.TestCheckResourceAttrSet("target", "attribute"), + }, + }, + }) + defaultAssertions(test) + }) + // ConvertToMigrationTestUseExternalProvider + + t.Run("explicit ExternalProvider version an no additional providers", func(t *testing.T) { + test := mig.CreateTestUseExternalProvider(t, &resource.TestCase{ + PreCheck: preCheck, + Steps: []resource.TestStep{firstStep}, + }, acc.ExternalProviders("1.2.3"), nil) + asserter.Len(test.Steps, 2, "Expected 2 steps (one extra test step)") + newFirstStep := test.Steps[0] + asserter.Equal(config, newFirstStep.Config) + asserter.Equal("1.2.3", test.Steps[0].ExternalProviders["mongodbatlas"].VersionConstraint) + }) + + t.Run("explicit ExternalProviders and additional providers", func(t *testing.T) { + test := mig.CreateTestUseExternalProvider(t, &resource.TestCase{ + PreCheck: preCheck, + Steps: []resource.TestStep{firstStep}, + }, acc.ExternalProvidersWithAWS("1.2.3"), acc.ExternalProvidersOnlyAWS()) + asserter.Len(test.Steps, 2, "Expected 2 steps (one extra test step)") + newFirstStep := test.Steps[0] + asserter.Equal(config, newFirstStep.Config) + + asserter.Equal("1.2.3", test.Steps[0].ExternalProviders["mongodbatlas"].VersionConstraint) + asserter.Equal(acc.AwsProviderVersion, test.Steps[0].ExternalProviders["aws"].VersionConstraint) + asserter.Equal(acc.AwsProviderVersion, test.Steps[1].ExternalProviders["aws"].VersionConstraint) + }) +} From 880f327cc7926ab776b664aeb2ca48fe16b07160 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:07:35 +0000 Subject: [PATCH 05/11] chore: Bump github.com/aws/aws-sdk-go from 1.51.3 to 1.51.8 (#2088) --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2892149d22..94362ed135 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/mongodb/terraform-provider-mongodbatlas go 1.22 require ( - github.com/aws/aws-sdk-go v1.51.3 + github.com/aws/aws-sdk-go v1.51.8 github.com/go-test/deep v1.1.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-version v1.6.0 diff --git a/go.sum b/go.sum index 53edecb3b1..c94878b2fe 100644 --- a/go.sum +++ b/go.sum @@ -236,8 +236,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM= github.com/aws/aws-sdk-go v1.37.0/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= -github.com/aws/aws-sdk-go v1.51.3 h1:OqSyEXcJwf/XhZNVpMRgKlLA9nmbo5X8dwbll4RWxq8= -github.com/aws/aws-sdk-go v1.51.3/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go v1.51.8 h1:tD7gQq5XKuKdhA6UMEH26ZNQH0s+HbL95rzv/ACz5TQ= +github.com/aws/aws-sdk-go v1.51.8/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= From de2a4e8bf104e59ba2f3a745f20575249f3f6d9f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:07:59 +0000 Subject: [PATCH 06/11] chore: Bump tj-actions/verify-changed-files (#2092) --- .github/workflows/update-sdk.yml | 2 +- .github/workflows/update_tf_compatibility_matrix.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-sdk.yml b/.github/workflows/update-sdk.yml index 65249b2845..bda829c32b 100644 --- a/.github/workflows/update-sdk.yml +++ b/.github/workflows/update-sdk.yml @@ -18,7 +18,7 @@ jobs: - name: Update files run: make tools update-atlas-sdk - name: Verify Changed files - uses: tj-actions/verify-changed-files@843c0b95f87cd81a2efe729380c6d1f11fb3ea12 + uses: tj-actions/verify-changed-files@1e517a7f5663673148ceb7c09c1900e5af48e7a1 id: verify-changed-files - name: Create PR uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e diff --git a/.github/workflows/update_tf_compatibility_matrix.yml b/.github/workflows/update_tf_compatibility_matrix.yml index b62e796df0..caadb08377 100644 --- a/.github/workflows/update_tf_compatibility_matrix.yml +++ b/.github/workflows/update_tf_compatibility_matrix.yml @@ -17,7 +17,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: make update-tf-compatibility-matrix - name: Verify Changed files - uses: tj-actions/verify-changed-files@843c0b95f87cd81a2efe729380c6d1f11fb3ea12 + uses: tj-actions/verify-changed-files@1e517a7f5663673148ceb7c09c1900e5af48e7a1 id: verify-changed-files - name: Create PR uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e From b6e05c4596594855a960d5c139113f77581bc1ff Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:08:31 +0000 Subject: [PATCH 07/11] chore: Bump github.com/hashicorp/hcl/v2 from 2.20.0 to 2.20.1 (#2091) --- go.mod | 3 ++- go.sum | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 94362ed135..cb73022b49 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/go-test/deep v1.1.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-version v1.6.0 - github.com/hashicorp/hcl/v2 v2.20.0 + github.com/hashicorp/hcl/v2 v2.20.1 github.com/hashicorp/terraform-plugin-framework v1.6.1 github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 @@ -122,6 +122,7 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect google.golang.org/grpc v1.62.1 // indirect google.golang.org/protobuf v1.33.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c94878b2fe..64aab428e8 100644 --- a/go.sum +++ b/go.sum @@ -470,8 +470,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90= github.com/hashicorp/hcl/v2 v2.8.2/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY= -github.com/hashicorp/hcl/v2 v2.20.0 h1:l++cRs/5jQOiKVvqXZm/P1ZEfVXJmvLS9WSVxkaeTb4= -github.com/hashicorp/hcl/v2 v2.20.0/go.mod h1:WmcD/Ym72MDOOx5F62Ly+leloeu6H7m0pG7VBiU6pQk= +github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc= +github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 h1:Pc5TCv9mbxFN6UVX0LH6CpQrdTM5YjbVI2w15237Pjk= @@ -552,7 +552,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= -github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= From e2d190b871891b936949393efd41d9d0fd15a99c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:09:21 +0000 Subject: [PATCH 08/11] chore: Bump github.com/mongodb-forks/digest from 1.0.5 to 1.1.0 (#2087) --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cb73022b49..d786448718 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/hashicorp/terraform-plugin-sdk v1.17.2 github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 github.com/hashicorp/terraform-plugin-testing v1.7.0 - github.com/mongodb-forks/digest v1.0.5 + github.com/mongodb-forks/digest v1.1.0 github.com/spf13/cast v1.6.0 github.com/stretchr/testify v1.9.0 github.com/zclconf/go-cty v1.14.3 diff --git a/go.sum b/go.sum index 64aab428e8..0698ff3816 100644 --- a/go.sum +++ b/go.sum @@ -594,8 +594,8 @@ github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/mongodb-forks/digest v1.0.5 h1:EJu3wtLZcA0HCvsZpX5yuD193/sW9tHiNvrEM5apXMk= -github.com/mongodb-forks/digest v1.0.5/go.mod h1:rb+EX8zotClD5Dj4NdgxnJXG9nwrlx3NWKJ8xttz1Dg= +github.com/mongodb-forks/digest v1.1.0 h1:7eUdsR1BtqLv0mdNm4OXs6ddWvR4X2/OsLwdKksrOoc= +github.com/mongodb-forks/digest v1.1.0/go.mod h1:rb+EX8zotClD5Dj4NdgxnJXG9nwrlx3NWKJ8xttz1Dg= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= From fdb4770ce06bc4742127482abca3ce2d6ae59e3b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:17:25 +0000 Subject: [PATCH 09/11] chore: Bump github.com/zclconf/go-cty from 1.14.3 to 1.14.4 (#2089) --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d786448718..ef5b851e69 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/mongodb-forks/digest v1.1.0 github.com/spf13/cast v1.6.0 github.com/stretchr/testify v1.9.0 - github.com/zclconf/go-cty v1.14.3 + github.com/zclconf/go-cty v1.14.4 go.mongodb.org/atlas v0.36.0 go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0 go.mongodb.org/atlas-sdk/v20231115008 v20231115008.1.0 diff --git a/go.sum b/go.sum index 0698ff3816..d8a883a8d9 100644 --- a/go.sum +++ b/go.sum @@ -681,8 +681,8 @@ github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLE github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.8.2/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= -github.com/zclconf/go-cty v1.14.3 h1:1JXy1XroaGrzZuG6X9dt7HL6s9AwbY+l4UNL8o5B6ho= -github.com/zclconf/go-cty v1.14.3/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= +github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= github.com/zclconf/go-cty-yaml v1.0.2 h1:dNyg4QLTrv2IfJpm7Wtxi55ed5gLGOlPrZ6kMd51hY0= From 03b0efdb7e674d12b9a305bffe7fe6b5a54949a9 Mon Sep 17 00:00:00 2001 From: Oriol Date: Wed, 27 Mar 2024 15:03:33 +0100 Subject: [PATCH 10/11] doc: Generates v1.15.3 (#2095) * changelog * Update CHANGELOG.md Co-authored-by: Agustin Bettati * move to internal improvement --------- Co-authored-by: Agustin Bettati --- .github_changelog_generator | 4 +-- CHANGELOG.md | 62 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/.github_changelog_generator b/.github_changelog_generator index 5b1a6739a7..c2bf9afcc5 100644 --- a/.github_changelog_generator +++ b/.github_changelog_generator @@ -1,4 +1,4 @@ -future-release=v1.15.2 -since-tag=v1.15.1 +future-release=v1.15.3 +since-tag=v1.15.2 date-format=%Y-%m-%d base=CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index d844ed2bd1..4e175223f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,67 @@ # Changelog +## [v1.15.3](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v1.15.3) (2024-03-27) + +[Full Changelog](https://github.com/mongodb/terraform-provider-mongodbatlas/compare/v1.15.2...v1.15.3) + +**Bug Fixes** + +- fix: Fixes `network_container` resource update [\#2055](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2055) ([lantoli](https://github.com/lantoli)) +- fix: Uses `overwriteBackupPolicies` in `mongodbatlas_backup_compliance_policy` to avoid overwriting non complying backup policies in updates [\#2054](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2054) ([maastha](https://github.com/maastha)) + +**Internal Improvements** + +- chore: Allows user to specify to use an existing tag for release [\#2053](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2053) ([maastha](https://github.com/maastha)) +- chore: Fixes Slack notification button to GH action run text [\#2093](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2093) ([oarbusi](https://github.com/oarbusi)) +- doc: Fixes import command in `mongodbatlas_third_party_integration` doc [\#2083](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2083) ([zach-carr](https://github.com/zach-carr)) +- chore: Reuses project in tests - `mongodbatlas_auditing` [\#2082](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2082) ([lantoli](https://github.com/lantoli)) +- test: Converting a test case to a migration test [\#2081](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2081) ([EspenAlbert](https://github.com/EspenAlbert)) +- doc: Specifies that upgrades From Replica Sets to Multi-Sharded Instances of `mongodbatlas_cluster` and `mongodbatlas_advanced_cluster` might lead to error [\#2080](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2080) ([oarbusi](https://github.com/oarbusi)) +- chore: Reuses project in tests - `mongodbatlas_project` [\#2078](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2078) ([lantoli](https://github.com/lantoli)) +- doc: Adds an example using `ignore_changes` when `autoscaling` is enabled [\#2077](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2077) ([zach-carr](https://github.com/zach-carr)) +- chore: Uses mocks for unit tests in Atlas Go SDK [\#2075](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2075) ([lantoli](https://github.com/lantoli)) +- chore: Updates Atlas Go SDK [\#2074](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2074) ([github-actions[bot]](https://github.com/apps/github-actions)) +- doc: Improve Readme Requirements to point to section in HashiCorp Registry Docs [\#2073](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2073) ([Zuhairahmed](https://github.com/Zuhairahmed)) +- doc: Updates bug report to include Terraform version support guidance [\#2072](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2072) ([maastha](https://github.com/maastha)) +- chore: Fixes send notification when test suite fails [\#2071](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2071) ([oarbusi](https://github.com/oarbusi)) +- chore: Fixes federated test [\#2070](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2070) ([lantoli](https://github.com/lantoli)) +- chore: Follow up to use global mig project in tests [\#2068](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2068) ([lantoli](https://github.com/lantoli)) +- chore: Reuses project in tests - `mongodbatlas_project_ip_access_list` [\#2067](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2067) ([lantoli](https://github.com/lantoli)) +- chore: Adds mig tests and refactor - `mongodbatlas_search_index` [\#2065](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2065) ([lantoli](https://github.com/lantoli)) +- chore: Corrects order of checks in `data_source_federated_settings_identity_providers_test` [\#2064](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2064) ([oarbusi](https://github.com/oarbusi)) +- chore: Removes old service from mockery [\#2063](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2063) ([EspenAlbert](https://github.com/EspenAlbert)) +- chore: Enables Github action linter and removes set terminal in release action [\#2062](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2062) ([lantoli](https://github.com/lantoli)) +- chore: Allows `MONGODB_ATLAS_PROJECT_ID` for local executions [\#2060](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2060) ([lantoli](https://github.com/lantoli)) +- doc: Clarifies private endpoint resource docs [\#2059](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2059) ([zach-carr](https://github.com/zach-carr)) +- chore: Automates changing Terraform supported versions in provider documentation [\#2058](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2058) ([maastha](https://github.com/maastha)) +- test: Enables simulation of cloud-dev using hoverfly in alert configuration acceptance tests [\#2057](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2057) ([AgustinBettati](https://github.com/AgustinBettati)) +- refactor: Uses mocks on `admin.APIClient` instead of custom `ClusterService` [\#2056](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2056) ([EspenAlbert](https://github.com/EspenAlbert)) +- chore: Send Slack message for Terraform Compatibility Matrix is executed [\#2052](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2052) ([oarbusi](https://github.com/oarbusi)) +- chore: Follow-up to Atlas SDK upgrade [\#2051](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2051) ([lantoli](https://github.com/lantoli)) +- chore: Fixes test names for `mongodbatlas_network_container` resource [\#2046](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2046) ([lantoli](https://github.com/lantoli)) +- refactor: Uses mocks on admin.APIClient for Project+Teams+ClustersAPIs instead of custom service [\#2045](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2045) ([EspenAlbert](https://github.com/EspenAlbert)) +- chore: Updates Atlas Go SDK [\#2044](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2044) ([github-actions[bot]](https://github.com/apps/github-actions)) +- test: Mocks the EncryptionAtRestUsingCustomerKeyManagementApi instead of using custom service [\#2043](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2043) ([EspenAlbert](https://github.com/EspenAlbert)) +- chore: Reuses project in tests for `mongodbatlas_advanced_cluster` resource [\#2042](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2042) ([lantoli](https://github.com/lantoli)) +- doc: Updates online archive resource docs [\#2041](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2041) ([zach-carr](https://github.com/zach-carr)) +- chore: Reuses project in tests for `mongodbatlas_cluster_outage_simulation` resource [\#2040](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2040) ([lantoli](https://github.com/lantoli)) +- chore: Reuses project in tests for `mongodbatlas_network_container` resource [\#2039](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2039) ([lantoli](https://github.com/lantoli)) +- chore: Reuses project in tests for `mongodbatlas_x509_authentication_database_user` resource [\#2038](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2038) ([lantoli](https://github.com/lantoli)) +- chore: Reuses project in tests for `mongodbatlas_project_api_key` resource [\#2037](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2037) ([lantoli](https://github.com/lantoli)) +- chore: Reuses project in tests for `mongodbatlas_cluster` resource [\#2036](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2036) ([lantoli](https://github.com/lantoli)) +- chore: Bump tj-actions/verify-changed-files from 843c0b95f87cd81a2efe729380c6d1f11fb3ea12 to 1e517a7f5663673148ceb7c09c1900e5af48e7a1 [\#2092](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2092) ([dependabot[bot]](https://github.com/apps/dependabot)) +- chore: Bump github.com/hashicorp/hcl/v2 from 2.20.0 to 2.20.1 [\#2091](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2091) ([dependabot[bot]](https://github.com/apps/dependabot)) +- chore: Bump github.com/zclconf/go-cty from 1.14.3 to 1.14.4 [\#2089](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2089) ([dependabot[bot]](https://github.com/apps/dependabot)) +- chore: Bump github.com/aws/aws-sdk-go from 1.51.3 to 1.51.8 [\#2088](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2088) ([dependabot[bot]](https://github.com/apps/dependabot)) +- chore: Bump github.com/mongodb-forks/digest from 1.0.5 to 1.1.0 [\#2087](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2087) ([dependabot[bot]](https://github.com/apps/dependabot)) +- chore: Bump github.com/aws/aws-sdk-go from 1.50.32 to 1.51.3 [\#2049](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2049) ([dependabot[bot]](https://github.com/apps/dependabot)) +- chore: Bump github.com/stretchr/testify from 1.8.4 to 1.9.0 [\#2048](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2048) ([dependabot[bot]](https://github.com/apps/dependabot)) +- chore: Bump actions/checkout from 4.1.1 to 4.1.2 [\#2047](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2047) ([dependabot[bot]](https://github.com/apps/dependabot)) + +**Closed Issues** + +- \[Bug\]: Removing `mongodbatlas_cloud_backup_schedule` resource is resulting in error `Continuous Cloud Backup cannot be on without an hourly policy item` [\#2029](https://github.com/mongodb/terraform-provider-mongodbatlas/issues/2029) + ## [v1.15.2](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v1.15.2) (2024-03-15) [Full Changelog](https://github.com/mongodb/terraform-provider-mongodbatlas/compare/v1.15.1...v1.15.2) From 01f585c98078c0f81feddd03428d8457ecd6ec6b Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Wed, 27 Mar 2024 17:06:58 +0100 Subject: [PATCH 11/11] test: Introduces shared cluster resource for running search index tests (#2086) * test: Introduces shared cluster resource for running search index tests * adjust logic of check destroy for search index as this check is now called instantly after delete is called * extract constants --- internal/common/constant/cloud_region.go | 5 + internal/common/constant/instance_size.go | 5 + .../resource_advanced_cluster.go | 42 ++-- .../searchindex/resource_search_index_test.go | 180 +++++++++--------- internal/testutil/acc/atlas.go | 64 +++++++ internal/testutil/acc/search_index.go | 2 +- internal/testutil/acc/shared_resource.go | 38 ++++ 7 files changed, 227 insertions(+), 109 deletions(-) create mode 100644 internal/common/constant/cloud_region.go create mode 100644 internal/common/constant/instance_size.go diff --git a/internal/common/constant/cloud_region.go b/internal/common/constant/cloud_region.go new file mode 100644 index 0000000000..08b0756869 --- /dev/null +++ b/internal/common/constant/cloud_region.go @@ -0,0 +1,5 @@ +package constant + +const ( + UsWest2 = "US_WEST_2" +) diff --git a/internal/common/constant/instance_size.go b/internal/common/constant/instance_size.go new file mode 100644 index 0000000000..e24415386b --- /dev/null +++ b/internal/common/constant/instance_size.go @@ -0,0 +1,5 @@ +package constant + +const ( + M10 = "M10" +) diff --git a/internal/service/advancedcluster/resource_advanced_cluster.go b/internal/service/advancedcluster/resource_advanced_cluster.go index 5d18a609f5..0087c712b1 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster.go +++ b/internal/service/advancedcluster/resource_advanced_cluster.go @@ -424,15 +424,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. } timeout := d.Timeout(schema.TimeoutCreate) - stateConf := &retry.StateChangeConf{ - Pending: []string{"CREATING", "UPDATING", "REPAIRING", "REPEATING", "PENDING"}, - Target: []string{"IDLE"}, - Refresh: resourceRefreshFunc(ctx, d.Get("name").(string), projectID, connV2), - Timeout: timeout, - MinTimeout: 1 * time.Minute, - Delay: 3 * time.Minute, - } - + stateConf := CreateStateChangeConfig(ctx, connV2, projectID, d.Get("name").(string), timeout) _, err = stateConf.WaitForStateContext(ctx) if err != nil { return diag.FromErr(fmt.Errorf(errorCreate, err)) @@ -467,6 +459,17 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. return resourceRead(ctx, d, meta) } +func CreateStateChangeConfig(ctx context.Context, connV2 *admin.APIClient, projectID, name string, timeout time.Duration) retry.StateChangeConf { + return retry.StateChangeConf{ + Pending: []string{"CREATING", "UPDATING", "REPAIRING", "REPEATING", "PENDING"}, + Target: []string{"IDLE"}, + Refresh: resourceRefreshFunc(ctx, name, projectID, connV2), + Timeout: timeout, + MinTimeout: 1 * time.Minute, + Delay: 3 * time.Minute, + } +} + func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { connV2 := meta.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) @@ -763,15 +766,7 @@ func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag. log.Println("[INFO] Waiting for MongoDB ClusterAdvanced to be destroyed") - stateConf := &retry.StateChangeConf{ - Pending: []string{"IDLE", "CREATING", "UPDATING", "REPAIRING", "DELETING"}, - Target: []string{"DELETED"}, - Refresh: resourceRefreshFunc(ctx, clusterName, projectID, connV2), - Timeout: d.Timeout(schema.TimeoutDelete), - MinTimeout: 30 * time.Second, - Delay: 1 * time.Minute, // Wait 30 secs before starting - } - + stateConf := DeleteStateChangeConfig(ctx, connV2, projectID, clusterName, d.Timeout(schema.TimeoutDelete)) // Wait, catching any errors _, err = stateConf.WaitForStateContext(ctx) if err != nil { @@ -781,6 +776,17 @@ func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag. return nil } +func DeleteStateChangeConfig(ctx context.Context, connV2 *admin.APIClient, projectID, name string, timeout time.Duration) retry.StateChangeConf { + return retry.StateChangeConf{ + Pending: []string{"IDLE", "CREATING", "UPDATING", "REPAIRING", "DELETING"}, + Target: []string{"DELETED"}, + Refresh: resourceRefreshFunc(ctx, name, projectID, connV2), + Timeout: timeout, + MinTimeout: 30 * time.Second, + Delay: 1 * time.Minute, + } +} + func resourceImport(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { connV2 := meta.(*config.MongoDBClient).AtlasV2 diff --git a/internal/service/searchindex/resource_search_index_test.go b/internal/service/searchindex/resource_search_index_test.go index 230c059075..3de5f30d99 100644 --- a/internal/service/searchindex/resource_search_index_test.go +++ b/internal/service/searchindex/resource_search_index_test.go @@ -17,20 +17,20 @@ func TestAccSearchIndex_basic(t *testing.T) { func TestAccSearchIndex_withSearchType(t *testing.T) { var ( - clusterInfo = acc.GetClusterInfo(t, nil) - indexName = acc.RandomName() - databaseName = acc.RandomName() - indexType = "search" - mappingsDynamic = "true" + projectID, clusterName = acc.ClusterNameExecution(t) + indexName = acc.RandomName() + databaseName = acc.RandomName() + indexType = "search" + mappingsDynamic = "true" ) - checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterInfo) + checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, CheckDestroy: acc.CheckDestroySearchIndex, Steps: []resource.TestStep{ { - Config: configBasic(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, true), + Config: configBasic(projectID, indexName, databaseName, clusterName, true), Check: resource.ComposeTestCheckFunc(checks...), }, }, @@ -39,13 +39,13 @@ func TestAccSearchIndex_withSearchType(t *testing.T) { func TestAccSearchIndex_withMapping(t *testing.T) { var ( - clusterInfo = acc.GetClusterInfo(t, nil) - indexName = acc.RandomName() - databaseName = acc.RandomName() - indexType = "" - mappingsDynamic = "false" + projectID, clusterName = acc.ClusterNameExecution(t) + indexName = acc.RandomName() + databaseName = acc.RandomName() + indexType = "" + mappingsDynamic = "false" ) - checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterInfo) + checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterName) checks = addAttrSetChecks(checks, "mappings_fields", "analyzers") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, @@ -53,7 +53,7 @@ func TestAccSearchIndex_withMapping(t *testing.T) { CheckDestroy: acc.CheckDestroySearchIndex, Steps: []resource.TestStep{ { - Config: configWithMapping(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr), + Config: configWithMapping(projectID, indexName, databaseName, clusterName), Check: resource.ComposeTestCheckFunc(checks...), }, }, @@ -62,19 +62,19 @@ func TestAccSearchIndex_withMapping(t *testing.T) { func TestAccSearchIndex_withSynonyms(t *testing.T) { var ( - clusterInfo = acc.GetClusterInfo(t, nil) - indexName = acc.RandomName() - databaseName = acc.RandomName() - indexType = "" - mappingsDynamic = "true" - mapChecks = map[string]string{ + projectID, clusterName = acc.ClusterNameExecution(t) + indexName = acc.RandomName() + databaseName = acc.RandomName() + indexType = "" + mappingsDynamic = "true" + mapChecks = map[string]string{ "synonyms.#": "1", "synonyms.0.analyzer": "lucene.simple", "synonyms.0.name": "synonym_test", "synonyms.0.source_collection": collectionName, } ) - checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterInfo) + checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterName) checks = addAttrChecks(checks, mapChecks) resource.ParallelTest(t, resource.TestCase{ @@ -83,7 +83,7 @@ func TestAccSearchIndex_withSynonyms(t *testing.T) { CheckDestroy: acc.CheckDestroySearchIndex, Steps: []resource.TestStep{ { - Config: configWithSynonyms(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, with), + Config: configWithSynonyms(projectID, indexName, databaseName, clusterName, with), Check: resource.ComposeTestCheckFunc(checks...), }, }, @@ -92,13 +92,13 @@ func TestAccSearchIndex_withSynonyms(t *testing.T) { func TestAccSearchIndex_updatedToEmptySynonyms(t *testing.T) { var ( - clusterInfo = acc.GetClusterInfo(t, nil) - indexName = acc.RandomName() - databaseName = acc.RandomName() - indexType = "" - mappingsDynamic = "true" + projectID, clusterName = acc.ClusterNameExecution(t) + indexName = acc.RandomName() + databaseName = acc.RandomName() + indexType = "" + mappingsDynamic = "true" ) - checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterInfo) + checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterName) checks1 := addAttrChecks(checks, map[string]string{ "synonyms.#": "1", "synonyms.0.analyzer": "lucene.simple", @@ -112,11 +112,11 @@ func TestAccSearchIndex_updatedToEmptySynonyms(t *testing.T) { CheckDestroy: acc.CheckDestroySearchIndex, Steps: []resource.TestStep{ { - Config: configWithSynonyms(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, with), + Config: configWithSynonyms(projectID, indexName, databaseName, clusterName, with), Check: resource.ComposeTestCheckFunc(checks1...), }, { - Config: configWithSynonyms(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, without), + Config: configWithSynonyms(projectID, indexName, databaseName, clusterName, without), Check: resource.ComposeTestCheckFunc(checks2...), }, }, @@ -125,9 +125,9 @@ func TestAccSearchIndex_updatedToEmptySynonyms(t *testing.T) { func TestAccSearchIndex_updatedToEmptyAnalyzers(t *testing.T) { var ( - clusterInfo = acc.GetClusterInfo(t, nil) - indexName = acc.RandomName() - databaseName = acc.RandomName() + projectID, clusterName = acc.ClusterNameExecution(t) + indexName = acc.RandomName() + databaseName = acc.RandomName() ) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, @@ -135,14 +135,14 @@ func TestAccSearchIndex_updatedToEmptyAnalyzers(t *testing.T) { CheckDestroy: acc.CheckDestroySearchIndex, Steps: []resource.TestStep{ { - Config: configAdditional(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, analyzersTF), + Config: configAdditional(projectID, indexName, databaseName, clusterName, analyzersTF), Check: resource.ComposeTestCheckFunc( checkExists(resourceName), resource.TestCheckResourceAttrWith(resourceName, "analyzers", acc.JSONEquals(analyzersJSON)), ), }, { - Config: configAdditional(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, ""), + Config: configAdditional(projectID, indexName, databaseName, clusterName, ""), Check: resource.ComposeTestCheckFunc( checkExists(resourceName), resource.TestCheckResourceAttr(resourceName, "analyzers", ""), @@ -154,9 +154,9 @@ func TestAccSearchIndex_updatedToEmptyAnalyzers(t *testing.T) { func TestAccSearchIndex_updatedToEmptyMappingsFields(t *testing.T) { var ( - clusterInfo = acc.GetClusterInfo(t, nil) - indexName = acc.RandomName() - databaseName = acc.RandomName() + projectID, clusterName = acc.ClusterNameExecution(t) + indexName = acc.RandomName() + databaseName = acc.RandomName() ) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, @@ -164,14 +164,14 @@ func TestAccSearchIndex_updatedToEmptyMappingsFields(t *testing.T) { CheckDestroy: acc.CheckDestroySearchIndex, Steps: []resource.TestStep{ { - Config: configAdditional(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, mappingsFieldsTF), + Config: configAdditional(projectID, indexName, databaseName, clusterName, mappingsFieldsTF), Check: resource.ComposeTestCheckFunc( checkExists(resourceName), resource.TestCheckResourceAttrWith(resourceName, "mappings_fields", acc.JSONEquals(mappingsFieldsJSON)), ), }, { - Config: configAdditional(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, ""), + Config: configAdditional(projectID, indexName, databaseName, clusterName, ""), Check: resource.ComposeTestCheckFunc( checkExists(resourceName), resource.TestCheckResourceAttr(resourceName, "mappings_fields", ""), @@ -188,13 +188,13 @@ func TestAccSearchIndex_withVector(t *testing.T) { func basicTestCase(tb testing.TB) *resource.TestCase { tb.Helper() var ( - clusterInfo = acc.GetClusterInfo(tb, nil) - indexName = acc.RandomName() - databaseName = acc.RandomName() - indexType = "" - mappingsDynamic = "true" + projectID, clusterName = acc.ClusterNameExecution(tb) + indexName = acc.RandomName() + databaseName = acc.RandomName() + indexType = "" + mappingsDynamic = "true" ) - checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterInfo) + checks := commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterName) return &resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(tb) }, @@ -202,11 +202,11 @@ func basicTestCase(tb testing.TB) *resource.TestCase { CheckDestroy: acc.CheckDestroySearchIndex, Steps: []resource.TestStep{ { - Config: configBasic(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, false), + Config: configBasic(projectID, indexName, databaseName, clusterName, false), Check: resource.ComposeTestCheckFunc(checks...), }, { - Config: configBasic(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, false), + Config: configBasic(projectID, indexName, databaseName, clusterName, false), ResourceName: resourceName, ImportStateIdFunc: importStateIDFunc(resourceName), ImportState: true, @@ -219,13 +219,13 @@ func basicTestCase(tb testing.TB) *resource.TestCase { func basicVectorTestCase(tb testing.TB) *resource.TestCase { tb.Helper() var ( - clusterInfo = acc.GetClusterInfo(tb, nil) - indexName = acc.RandomName() - indexType = "vectorSearch" - databaseName = acc.RandomName() - attributes = map[string]string{ + projectID, clusterName = acc.ClusterNameExecution(tb) + indexName = acc.RandomName() + indexType = "vectorSearch" + databaseName = acc.RandomName() + attributes = map[string]string{ "name": indexName, - "cluster_name": clusterInfo.ClusterName, + "cluster_name": clusterName, "database": databaseName, "collection_name": collectionName, "type": indexType, @@ -242,17 +242,17 @@ func basicVectorTestCase(tb testing.TB) *resource.TestCase { CheckDestroy: acc.CheckDestroySearchIndex, Steps: []resource.TestStep{ { - Config: configVector(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr), + Config: configVector(projectID, indexName, databaseName, clusterName), Check: resource.ComposeTestCheckFunc(checks...), }, }, } } -func commonChecks(indexName, indexType, mappingsDynamic, databaseName string, clusterInfo acc.ClusterInfo) []resource.TestCheckFunc { +func commonChecks(indexName, indexType, mappingsDynamic, databaseName, clusterName string) []resource.TestCheckFunc { attributes := map[string]string{ "name": indexName, - "cluster_name": clusterInfo.ClusterName, + "cluster_name": clusterName, "database": databaseName, "collection_name": collectionName, "type": indexType, @@ -291,15 +291,15 @@ func checkExists(resourceName string) resource.TestCheckFunc { } } -func configBasic(projectIDStr, indexName, databaseName, clusterNameStr, clusterTerraformStr string, explicitType bool) string { +func configBasic(projectID, indexName, databaseName, clusterName string, explicitType bool) string { var indexType string if explicitType { indexType = `type="search"` } - return clusterTerraformStr + fmt.Sprintf(` + return fmt.Sprintf(` resource "mongodbatlas_search_index" "test" { - cluster_name = %[1]s - project_id = %[2]s + cluster_name = %[1]q + project_id = %[2]q name = %[3]q database = %[4]q collection_name = %[5]q @@ -309,18 +309,18 @@ func configBasic(projectIDStr, indexName, databaseName, clusterNameStr, clusterT } data "mongodbatlas_search_index" "data_index" { - cluster_name = %[1]s - project_id = %[2]s + cluster_name = %[1]q + project_id = %[2]q index_id = mongodbatlas_search_index.test.index_id } - `, clusterNameStr, projectIDStr, indexName, databaseName, collectionName, searchAnalyzer, indexType) + `, clusterName, projectID, indexName, databaseName, collectionName, searchAnalyzer, indexType) } -func configWithMapping(projectIDStr, indexName, databaseName, clusterNameStr, clusterTerraformStr string) string { - return clusterTerraformStr + fmt.Sprintf(` +func configWithMapping(projectID, indexName, databaseName, clusterName string) string { + return fmt.Sprintf(` resource "mongodbatlas_search_index" "test" { - cluster_name = %[1]s - project_id = %[2]s + cluster_name = %[1]q + project_id = %[2]q name = %[3]q database = %[4]q collection_name = %[5]q @@ -331,14 +331,14 @@ func configWithMapping(projectIDStr, indexName, databaseName, clusterNameStr, cl } data "mongodbatlas_search_index" "data_index" { - cluster_name = %[1]s - project_id = %[2]s + cluster_name = %[1]q + project_id = %[2]q index_id = mongodbatlas_search_index.test.index_id } - `, clusterNameStr, projectIDStr, indexName, databaseName, collectionName, searchAnalyzer, analyzersTF, mappingsFieldsTF) + `, clusterName, projectID, indexName, databaseName, collectionName, searchAnalyzer, analyzersTF, mappingsFieldsTF) } -func configWithSynonyms(projectIDStr, indexName, databaseName, clusterNameStr, clusterTerraformStr string, has bool) string { +func configWithSynonyms(projectID, indexName, databaseName, clusterName string, has bool) string { var synonymsStr string if has { synonymsStr = fmt.Sprintf(` @@ -350,10 +350,10 @@ func configWithSynonyms(projectIDStr, indexName, databaseName, clusterNameStr, c `, collectionName) } - return clusterTerraformStr + fmt.Sprintf(` + return fmt.Sprintf(` resource "mongodbatlas_search_index" "test" { - cluster_name = %[1]s - project_id = %[2]s + cluster_name = %[1]q + project_id = %[2]q name = %[3]q database = %[4]q collection_name = %[5]q @@ -363,18 +363,18 @@ func configWithSynonyms(projectIDStr, indexName, databaseName, clusterNameStr, c } data "mongodbatlas_search_index" "data_index" { - cluster_name = %[1]s - project_id = %[2]s + cluster_name = %[1]q + project_id = %[2]q index_id = mongodbatlas_search_index.test.index_id } - `, clusterNameStr, projectIDStr, indexName, databaseName, collectionName, searchAnalyzer, synonymsStr) + `, clusterName, projectID, indexName, databaseName, collectionName, searchAnalyzer, synonymsStr) } -func configAdditional(projectIDStr, indexName, databaseName, clusterNameStr, clusterTerraformStr, additional string) string { - return clusterTerraformStr + fmt.Sprintf(` +func configAdditional(projectID, indexName, databaseName, clusterName, additional string) string { + return fmt.Sprintf(` resource "mongodbatlas_search_index" "test" { - cluster_name = %[1]s - project_id = %[2]s + cluster_name = %[1]q + project_id = %[2]q name = %[3]q database = %[4]q collection_name = %[5]q @@ -382,14 +382,14 @@ func configAdditional(projectIDStr, indexName, databaseName, clusterNameStr, clu mappings_dynamic = true %[7]s } - `, clusterNameStr, projectIDStr, indexName, databaseName, collectionName, searchAnalyzer, additional) + `, clusterName, projectID, indexName, databaseName, collectionName, searchAnalyzer, additional) } -func configVector(projectIDStr, indexName, databaseName, clusterNameStr, clusterTerraformStr string) string { - return clusterTerraformStr + fmt.Sprintf(` +func configVector(projectID, indexName, databaseName, clusterName string) string { + return fmt.Sprintf(` resource "mongodbatlas_search_index" "test" { - cluster_name = %[1]s - project_id = %[2]s + cluster_name = %[1]q + project_id = %[2]q name = %[3]q database = %[4]q collection_name = %[5]q @@ -402,11 +402,11 @@ func configVector(projectIDStr, indexName, databaseName, clusterNameStr, cluster } data "mongodbatlas_search_index" "data_index" { - cluster_name = %[1]s - project_id = %[2]s + cluster_name = %[1]q + project_id = %[2]q index_id = mongodbatlas_search_index.test.index_id } - `, clusterNameStr, projectIDStr, indexName, databaseName, collectionName, fieldsJSON) + `, clusterName, projectID, indexName, databaseName, collectionName, fieldsJSON) } func importStateIDFunc(resourceName string) resource.ImportStateIdFunc { diff --git a/internal/testutil/acc/atlas.go b/internal/testutil/acc/atlas.go index 6fc2976c89..5cca362bae 100644 --- a/internal/testutil/acc/atlas.go +++ b/internal/testutil/acc/atlas.go @@ -5,7 +5,10 @@ import ( "fmt" "os" "testing" + "time" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster" "github.com/stretchr/testify/require" "go.mongodb.org/atlas-sdk/v20231115008/admin" ) @@ -29,6 +32,54 @@ func deleteProject(id string) { } } +func createCluster(tb testing.TB, projectID, name string) string { + tb.Helper() + req := clusterReq(name, projectID) + _, _, err := ConnV2().ClustersApi.CreateCluster(context.Background(), projectID, &req).Execute() + require.NoError(tb, err, "Cluster creation failed: %s, err: %s", name, err) + + stateConf := advancedcluster.CreateStateChangeConfig(context.Background(), ConnV2(), projectID, name, 1*time.Hour) + _, err = stateConf.WaitForStateContext(context.Background()) + require.NoError(tb, err, "Cluster creation failed: %s, err: %s", name, err) + + return name +} + +func deleteCluster(projectID, name string) { + _, err := ConnV2().ClustersApi.DeleteCluster(context.Background(), projectID, name).Execute() + if err != nil { + fmt.Printf("Cluster deletion failed: %s %s, error: %s", projectID, name, err) + } + stateConf := advancedcluster.DeleteStateChangeConfig(context.Background(), ConnV2(), projectID, name, 1*time.Hour) + _, err = stateConf.WaitForStateContext(context.Background()) + if err != nil { + fmt.Printf("Cluster deletion failed: %s %s, error: %s", projectID, name, err) + } +} + +func clusterReq(name, projectID string) admin.AdvancedClusterDescription { + return admin.AdvancedClusterDescription{ + Name: admin.PtrString(name), + GroupId: admin.PtrString(projectID), + ClusterType: admin.PtrString("REPLICASET"), + ReplicationSpecs: &[]admin.ReplicationSpec{ + { + RegionConfigs: &[]admin.CloudRegionConfig{ + { + ProviderName: admin.PtrString(constant.AWS), + RegionName: admin.PtrString(constant.UsWest2), + Priority: admin.PtrInt(7), + ElectableSpecs: &admin.HardwareSpec{ + InstanceSize: admin.PtrString(constant.M10), + NodeCount: admin.PtrInt(3), + }, + }, + }, + }, + }, + } +} + // ProjectID returns the id for a project name. // When `MONGODB_ATLAS_PROJECT_ID` is defined, it is used instead of creating a project. This is useful for local execution but not intended for CI executions. func ProjectID(tb testing.TB, name string) string { @@ -57,3 +108,16 @@ func projectIDLocal(tb testing.TB) string { tb.Logf("Using MONGODB_ATLAS_PROJECT_ID: %s", id) return id } + +func clusterNameLocal(tb testing.TB) string { + tb.Helper() + name := os.Getenv("MONGODB_ATLAS_CLUSTER_NAME") + if name == "" { + return "" + } + if InCI() { + tb.Fatal("MONGODB_ATLAS_CLUSTER_NAME can't be used in CI") + } + tb.Logf("Using MONGODB_ATLAS_CLUSTER_NAME: %s", name) + return name +} diff --git a/internal/testutil/acc/search_index.go b/internal/testutil/acc/search_index.go index 04023b5928..da8bc06d3f 100644 --- a/internal/testutil/acc/search_index.go +++ b/internal/testutil/acc/search_index.go @@ -18,7 +18,7 @@ func CheckDestroySearchIndex(state *terraform.State) error { } ids := conversion.DecodeStateID(rs.Primary.ID) searchIndex, _, err := Conn().Search.GetIndex(context.Background(), ids["project_id"], ids["cluster_name"], ids["index_id"]) - if err == nil && searchIndex != nil { + if err == nil && searchIndex != nil && searchIndex.Status != "IN_PROGRESS" { // index can be in progess for some seconds after delete is called return fmt.Errorf("index id (%s) still exists", ids["index_id"]) } } diff --git a/internal/testutil/acc/shared_resource.go b/internal/testutil/acc/shared_resource.go index ee772fbcf2..f50ddba133 100644 --- a/internal/testutil/acc/shared_resource.go +++ b/internal/testutil/acc/shared_resource.go @@ -16,6 +16,11 @@ func SetupSharedResources() func() { } func cleanupSharedResources() { + if sharedInfo.projectID != "" && sharedInfo.clusterName != "" { + fmt.Printf("Deleting execution cluster: %s, project id: %s\n", sharedInfo.clusterName, sharedInfo.projectID) + deleteCluster(sharedInfo.projectID, sharedInfo.clusterName) + } + if sharedInfo.projectID != "" { fmt.Printf("Deleting execution project: %s, id: %s\n", sharedInfo.projectName, sharedInfo.projectID) deleteProject(sharedInfo.projectID) @@ -47,9 +52,42 @@ func ProjectIDExecution(tb testing.TB) string { return sharedInfo.projectID } +// ClusterNameExecution returns the name of a created cluster for the execution of the tests in the resource package. +// This function relies on using an execution project and returns its id. +// When `MONGODB_ATLAS_CLUSTER_NAME` and `MONGODB_ATLAS_PROJECT_ID` are defined it will be used instead of creating resources. This is useful for local execution but not intended for CI executions. +func ClusterNameExecution(tb testing.TB) (projectID, clusterName string) { + tb.Helper() + SkipInUnitTest(tb) + require.True(tb, sharedInfo.init, "SetupSharedResources must called from TestMain test package") + + localProjectID := projectIDLocal(tb) + localClusterName := clusterNameLocal(tb) + if localProjectID != "" && localClusterName != "" { + return localProjectID, localClusterName + } + + // before locking for cluster creation we need to ensure we have an execution project created + if sharedInfo.projectID == "" { + _ = ProjectIDExecution(tb) + } + + sharedInfo.mu.Lock() + defer sharedInfo.mu.Unlock() + + // lazy creation so it's only done if really needed + if sharedInfo.clusterName == "" { + name := RandomClusterName() + tb.Logf("Creating execution cluster: %s\n", name) + sharedInfo.clusterName = createCluster(tb, sharedInfo.projectID, name) + } + + return sharedInfo.projectID, sharedInfo.clusterName +} + var sharedInfo = struct { projectID string projectName string + clusterName string mu sync.Mutex init bool }{}