From bda1b02c0374f87b7004891a0d2cd2579f2a4bf5 Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Fri, 24 May 2024 10:30:44 +0100 Subject: [PATCH 01/11] chore: Adds support for cloud-gov testing --- internal/testutil/acc/factory.go | 11 +++++++++++ internal/testutil/acc/pre_check.go | 17 +++++------------ internal/testutil/acc/provider.go | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/internal/testutil/acc/factory.go b/internal/testutil/acc/factory.go index 5b78bec254..c352b4998c 100644 --- a/internal/testutil/acc/factory.go +++ b/internal/testutil/acc/factory.go @@ -51,6 +51,17 @@ func ConnV2UsingProxy(proxyPort *int) *admin.APIClient { return client.(*config.MongoDBClient).AtlasV2 } +func ConnV2UsingGov() *admin.APIClient { + cfg := config.Config{ + PublicKey: os.Getenv("MONGODB_ATLAS_GOV_PUBLIC_KEY"), + PrivateKey: os.Getenv("MONGODB_ATLAS_GOV_PRIVATE_KEY"), + BaseURL: os.Getenv("MONGODB_ATLAS_GOV_BASE_URL"), + RealmBaseURL: os.Getenv("MONGODB_ATLAS_GOV_BASE_URL"), + } + client, _ := cfg.NewClient(context.Background()) + return client.(*config.MongoDBClient).AtlasV2 +} + func init() { TestAccProviderV6Factories = map[string]func() (tfprotov6.ProviderServer, error){ ProviderNameMongoDBAtlas: func() (tfprotov6.ProviderServer, error) { diff --git a/internal/testutil/acc/pre_check.go b/internal/testutil/acc/pre_check.go index 23e52636ce..49a6322379 100644 --- a/internal/testutil/acc/pre_check.go +++ b/internal/testutil/acc/pre_check.go @@ -97,19 +97,12 @@ func GetProjectTeamsIDsWithPos(pos int) string { func PreCheckGovBasic(tb testing.TB) { tb.Helper() - if os.Getenv("MONGODB_ATLAS_PUBLIC_KEY") == "" || - os.Getenv("MONGODB_ATLAS_PRIVATE_KEY") == "" || - os.Getenv("MONGODB_ATLAS_ORG_ID_GOV") == "" { - tb.Fatal("`MONGODB_ATLAS_PUBLIC_KEY`, `MONGODB_ATLAS_PRIVATE_KEY`and `MONGODB_ATLAS_ORG_ID_GOV` must be set for acceptance testing") - } -} - -func PreCheckGov(tb testing.TB) { - tb.Helper() - if os.Getenv("MONGODB_ATLAS_PROJECT_ID_GOV") == "" { - tb.Fatal("`MONGODB_ATLAS_PROJECT_ID_GOV` must be set for acceptance testing") + if os.Getenv("MONGODB_ATLAS_GOV_PUBLIC_KEY") == "" || + os.Getenv("MONGODB_ATLAS_GOV_PRIVATE_KEY") == "" || + os.Getenv("MONGODB_ATLAS_GOV_BASE_URL") == "" || + os.Getenv("MONGODB_ATLAS_GOV_ORG_ID") == "" { + tb.Fatal("`MONGODB_ATLAS_GOV_BASE_URL`, `MONGODB_ATLAS_GOV_PUBLIC_KEY`, `MONGODB_ATLAS_GOV_PRIVATE_KEY`and `MONGODB_ATLAS_GOV_ORG_ID` must be set for acceptance testing") } - PreCheckGovBasic(tb) } func PreCheckGPCEnv(tb testing.TB) { diff --git a/internal/testutil/acc/provider.go b/internal/testutil/acc/provider.go index 948b913e77..0867ce6aba 100644 --- a/internal/testutil/acc/provider.go +++ b/internal/testutil/acc/provider.go @@ -1,6 +1,9 @@ package acc import ( + "fmt" + "os" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -38,3 +41,23 @@ func providerAWS() *resource.ExternalProvider { Source: "hashicorp/aws", } } + +// ConfigProvider creates a new provider with credentials explicit in config. +// +// This can be used when you want credentials different from the default env-vars. +func ConfigProvider(publicKey, privateKey, baseURL string) string { + return fmt.Sprintf(` +provider %[1]q { + public_key = %[2]q + private_key = %[3]q + base_url = %[4]q +} +`, ProviderNameMongoDBAtlas, publicKey, privateKey, baseURL) +} + +// ConfigGovProvider creates provider using MONGODB_ATLAS_GOV_* env vars. +// +// Remember to use PreCheckGovBasic when using this. +func ConfigGovProvider() string { + return ConfigProvider(os.Getenv("MONGODB_ATLAS_GOV_PUBLIC_KEY"), os.Getenv("MONGODB_ATLAS_GOV_PRIVATE_KEY"), os.Getenv("MONGODB_ATLAS_GOV_BASE_URL")) +} From 7dfb513c319a2066bf295efaa5e30b7dd67d3c72 Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Fri, 24 May 2024 14:47:57 +0100 Subject: [PATCH 02/11] ci: update workflow files with new variables --- .github/workflows/acceptance-tests-runner.yml | 15 +++++++++++++++ .github/workflows/acceptance-tests.yml | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/.github/workflows/acceptance-tests-runner.yml b/.github/workflows/acceptance-tests-runner.yml index fd50f51b0a..0b1b2dc5fc 100644 --- a/.github/workflows/acceptance-tests-runner.yml +++ b/.github/workflows/acceptance-tests-runner.yml @@ -73,6 +73,12 @@ on: mongodb_atlas_federated_org_id: type: string required: true + mongodb_atlas_gov_org_id: + type: string + required: true + mongodb_atlas_gov_base_url: + type: string + required: true secrets: # all secrets are passed explicitly in this workflow mongodb_atlas_public_key: required: true @@ -104,6 +110,10 @@ on: required: true mongodb_atlas_private_endpoint_dns_name: required: true + mongodb_atlas_gov_private_key: + required: true + mongodb_atlas_gov_public_key: + required: true env: TF_ACC: 1 @@ -115,6 +125,11 @@ env: MONGODB_ATLAS_ORG_ID: ${{ inputs.mongodb_atlas_org_id }} MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.mongodb_atlas_public_key }} MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.mongodb_atlas_private_key }} + MONGODB_ATLAS_GOV_PUBLIC_KEY: ${{ secrets.mongodb_atlas_public_key }} + MONGODB_ATLAS_GOV_PRIVATE_KEY: ${{ secrets.mongodb_atlas_private_key }} + MONGODB_ATLAS_GOV_BASE_URL: ${{ inputs.mongodb_atlas_gov_base_url }} + MONGODB_ATLAS_GOV_ORG_ID: ${{ inputs.mongodb_atlas_gov_org_id }} + jobs: diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml index 28272bedf4..67f2bdf557 100644 --- a/.github/workflows/acceptance-tests.yml +++ b/.github/workflows/acceptance-tests.yml @@ -51,6 +51,8 @@ jobs: secrets: mongodb_atlas_public_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_QA || secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }} mongodb_atlas_private_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_QA || secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }} + mongodb_atlas_gov_public_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_GOV_PUBLIC_KEY_QA || secrets.MONGODB_ATLAS_GOV_PUBLIC_KEY_DEV }} + mongodb_atlas_gov_private_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_GOV_PRIVATE_KEY_QA || secrets.MONGODB_ATLAS_GOV_PRIVATE_KEY_DEV }} ca_cert: ${{ secrets.CA_CERT }} aws_account_id: ${{ secrets.AWS_ACCOUNT_ID }} aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} @@ -87,3 +89,5 @@ jobs: mongodb_atlas_federated_sso_url: ${{ vars.MONGODB_ATLAS_FEDERATED_SSO_URL }} mongodb_atlas_federated_issuer_uri: ${{ vars.MONGODB_ATLAS_FEDERATED_ISSUER_URI }} mongodb_atlas_federated_org_id: ${{ inputs.atlas_cloud_env == 'qa' && vars.MONGODB_ATLAS_FEDERATED_ORG_ID_QA || vars.MONGODB_ATLAS_FEDERATED_ORG_ID }} + mongodb_atlas_gov_base_url: ${{ inputs.atlas_cloud_env == 'qa' && vars.MONGODB_ATLAS_GOV_BASE_URL_QA || vars.MONGODB_ATLAS_GOV_BASE_URL_DEV }} + mongodb_atlas_gov_org_id: ${{ inputs.atlas_cloud_env == 'qa' && vars.MONGODB_ATLAS_GOV_ORG_ID_QA || vars.MONGODB_ATLAS_GOV_ORG_ID_DEV }} From c48ce6e4e429a5c1e4d8ed2b1042b45a743682a6 Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Fri, 24 May 2024 15:01:54 +0100 Subject: [PATCH 03/11] docs: Show how to write Cloud Gov tests --- contributing/testing-best-practices.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contributing/testing-best-practices.md b/contributing/testing-best-practices.md index fdd2140381..045fcf8693 100644 --- a/contributing/testing-best-practices.md +++ b/contributing/testing-best-practices.md @@ -32,6 +32,12 @@ - Data sources are tested in the same tests as the resources, e.g. [commonChecks](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/66c44e62c9afe04ffe8be0dbccaec682bab830e6/internal/service/searchindex/resource_search_index_test.go#L262-L263). - Helper functions such as `resource.TestCheckTypeSetElemNestedAttrs` or `resource.TestCheckTypeSetElemAttr` can be used to check resource and data source attributes more easily, e.g. [resource_serverless_instance_test.go](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/66c44e62c9afe04ffe8be0dbccaec682bab830e6/internal/service/serverlessinstance/resource_serverless_instance_test.go#L61). +### Cloud Gov tests + +1. Use [`PreCheck: PreCheckGovBasic`](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/CLOUDP-250271_cloud_gov/internal/testutil/acc/pre_check.go#L98) +2. Use the [`acc.ConfigGovProvider`](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/CLOUDP-250271_cloud_gov/internal/testutil/acc/provider.go#L61) together with your normal terraform config +3. Modify the `checkExist` and `CheckDestroy` to use `acc.ConnV2UsingGov` + ## Migration tests - There must be at least one `basic migration test` for each resource that leverages on the `basic acceptance tests` using helper test functions such as `CreateAndRunTest`, e.g. [TestMigServerlessInstance_basic](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/66c44e62c9afe04ffe8be0dbccaec682bab830e6/internal/service/serverlessinstance/resource_serverless_instance_migration_test.go#L10). From 9e01d6928230bc5c97a6f58951f7d6cc95da087b Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Fri, 24 May 2024 15:19:09 +0100 Subject: [PATCH 04/11] docs: add naming convention --- contributing/testing-best-practices.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contributing/testing-best-practices.md b/contributing/testing-best-practices.md index 045fcf8693..cdca2f2287 100644 --- a/contributing/testing-best-practices.md +++ b/contributing/testing-best-practices.md @@ -37,6 +37,9 @@ 1. Use [`PreCheck: PreCheckGovBasic`](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/CLOUDP-250271_cloud_gov/internal/testutil/acc/pre_check.go#L98) 2. Use the [`acc.ConfigGovProvider`](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/CLOUDP-250271_cloud_gov/internal/testutil/acc/provider.go#L61) together with your normal terraform config 3. Modify the `checkExist` and `CheckDestroy` to use `acc.ConnV2UsingGov` +4. Follow naming convention: + 1. `TestAccGovProject_withProjectOwner`, note prefix: `TestAccGov` + 2. `TestMigGovProject_regionUsageRestrictionsDefault`, note prefix: `TestMigGov` ## Migration tests From ee41811ef819d9255bf7f29db6c75f45e3014500 Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Fri, 24 May 2024 15:27:12 +0100 Subject: [PATCH 05/11] ci: fix, referencing the wrong gov private/public keys --- .github/workflows/acceptance-tests-runner.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/acceptance-tests-runner.yml b/.github/workflows/acceptance-tests-runner.yml index 0b1b2dc5fc..ec6eda42ef 100644 --- a/.github/workflows/acceptance-tests-runner.yml +++ b/.github/workflows/acceptance-tests-runner.yml @@ -125,8 +125,8 @@ env: MONGODB_ATLAS_ORG_ID: ${{ inputs.mongodb_atlas_org_id }} MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.mongodb_atlas_public_key }} MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.mongodb_atlas_private_key }} - MONGODB_ATLAS_GOV_PUBLIC_KEY: ${{ secrets.mongodb_atlas_public_key }} - MONGODB_ATLAS_GOV_PRIVATE_KEY: ${{ secrets.mongodb_atlas_private_key }} + MONGODB_ATLAS_GOV_PUBLIC_KEY: ${{ secrets.mongodb_atlas_gov_public_key }} + MONGODB_ATLAS_GOV_PRIVATE_KEY: ${{ secrets.mongodb_atlas_gov_private_key }} MONGODB_ATLAS_GOV_BASE_URL: ${{ inputs.mongodb_atlas_gov_base_url }} MONGODB_ATLAS_GOV_ORG_ID: ${{ inputs.mongodb_atlas_gov_org_id }} From 93b9afbbd76e7261846f932d83a104fd8e74693b Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Tue, 21 May 2024 11:06:15 +0100 Subject: [PATCH 06/11] fix: Marks region_usage_restrictions as OptionalComputed to avoid provider upgrade errors --- internal/service/project/resource_project.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index 69d5bd19f0..b2bae2dfce 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -216,6 +216,7 @@ func (r *projectRS) Schema(ctx context.Context, req resource.SchemaRequest, resp }, }, "region_usage_restrictions": schema.StringAttribute{ + Computed: true, Optional: true, }, "ip_addresses": schema.SingleNestedAttribute{ From 50e6a470be4f5a2eb2ba3dc35d16eb154dfd1a10 Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Tue, 21 May 2024 11:15:22 +0100 Subject: [PATCH 07/11] docs: add changelog --- .changelog/2291.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2291.txt diff --git a/.changelog/2291.txt b/.changelog/2291.txt new file mode 100644 index 0000000000..523e13cb7e --- /dev/null +++ b/.changelog/2291.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/mongodbatlas_project: Fixes inconsistent result after apply when region_usage_restrictions are not set in configuration but returned from server +``` From c5d72736beac255035b6c4c814ecc0c9d8ce9b9e Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Fri, 24 May 2024 15:13:07 +0100 Subject: [PATCH 08/11] test: add gov migration test and enable project gov test --- .github/workflows/acceptance-tests-runner.yml | 3 ++ .github/workflows/acceptance-tests.yml | 1 + .../resource_project_migration_test.go | 42 +++++++++++++++++++ .../service/project/resource_project_test.go | 26 ++++++++---- internal/testutil/acc/project.go | 13 ++++-- 5 files changed, 73 insertions(+), 12 deletions(-) diff --git a/.github/workflows/acceptance-tests-runner.yml b/.github/workflows/acceptance-tests-runner.yml index ec6eda42ef..5192d3010b 100644 --- a/.github/workflows/acceptance-tests-runner.yml +++ b/.github/workflows/acceptance-tests-runner.yml @@ -79,6 +79,9 @@ on: mongodb_atlas_gov_base_url: type: string required: true + mongodb_atlas_gov_project_owner_id: + type: string + required: true secrets: # all secrets are passed explicitly in this workflow mongodb_atlas_public_key: required: true diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml index 67f2bdf557..eb38dab71a 100644 --- a/.github/workflows/acceptance-tests.yml +++ b/.github/workflows/acceptance-tests.yml @@ -91,3 +91,4 @@ jobs: mongodb_atlas_federated_org_id: ${{ inputs.atlas_cloud_env == 'qa' && vars.MONGODB_ATLAS_FEDERATED_ORG_ID_QA || vars.MONGODB_ATLAS_FEDERATED_ORG_ID }} mongodb_atlas_gov_base_url: ${{ inputs.atlas_cloud_env == 'qa' && vars.MONGODB_ATLAS_GOV_BASE_URL_QA || vars.MONGODB_ATLAS_GOV_BASE_URL_DEV }} mongodb_atlas_gov_org_id: ${{ inputs.atlas_cloud_env == 'qa' && vars.MONGODB_ATLAS_GOV_ORG_ID_QA || vars.MONGODB_ATLAS_GOV_ORG_ID_DEV }} + mongodb_atlas_gov_project_owner_id: ${{ inputs.atlas_cloud_env == 'qa' && vars.MONGODB_ATLAS_GOV_PROJECT_OWNER_ID_QA || vars.MONGODB_ATLAS_GOV_PROJECT_OWNER_ID_DEV }} diff --git a/internal/service/project/resource_project_migration_test.go b/internal/service/project/resource_project_migration_test.go index 5c1f76f602..bc87950ac4 100644 --- a/internal/service/project/resource_project_migration_test.go +++ b/internal/service/project/resource_project_migration_test.go @@ -1,7 +1,9 @@ package project_test import ( + "fmt" "os" + "regexp" "strings" "testing" @@ -139,3 +141,43 @@ func TestMigProject_withLimits(t *testing.T) { }, }) } + +// based on bug report: https://github.com/mongodb/terraform-provider-mongodbatlas/issues/2263 +func TestMigGovProject_region_usage_restrictions(t *testing.T) { + var ( + orgID = os.Getenv("MONGODB_ATLAS_GOV_ORG_ID") + projectName = acc.RandomProjectName() + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acc.PreCheckGovBasic(t) }, + CheckDestroy: acc.CheckDestroyProjectGov, + Steps: []resource.TestStep{ + { + ExternalProviders: acc.ExternalProviders("1.15.3"), + Config: configGovSimple(orgID, projectName), + Check: resource.ComposeTestCheckFunc( + checkExistsGov(resourceName), + ), + }, + { + ExternalProviders: acc.ExternalProviders("1.16.0"), + Config: configGovSimple(orgID, projectName), + Check: resource.ComposeTestCheckFunc( + checkExistsGov(resourceName), + ), + ExpectError: regexp.MustCompile("Provider produced inconsistent result after apply"), + }, + mig.TestStepCheckEmptyPlan(configGovSimple(orgID, projectName)), + }, + }) +} + +func configGovSimple(orgID, projectName string) string { + return acc.ConfigGovProvider() + fmt.Sprintf(` + resource "mongodbatlas_project" "test" { + org_id = %[1]q + name = %[2]q + } + `, orgID, projectName) +} diff --git a/internal/service/project/resource_project_test.go b/internal/service/project/resource_project_test.go index 26755a7d08..a82426f97c 100644 --- a/internal/service/project/resource_project_test.go +++ b/internal/service/project/resource_project_test.go @@ -611,32 +611,32 @@ func TestAccProject_basic(t *testing.T) { }) } -func TestAccProjectGov_withProjectOwner(t *testing.T) { - acc.SkipTestForCI(t) // Gov test config not set - +func TestAccGovProject_withProjectOwner(t *testing.T) { var ( - orgID = os.Getenv("MONGODB_ATLAS_ORG_ID_GOV") - projectOwnerID = os.Getenv("MONGODB_ATLAS_PROJECT_OWNER_ID_GOV") + orgID = os.Getenv("MONGODB_ATLAS_GOV_ORG_ID") + projectOwnerID = os.Getenv("MONGODB_ATLAS_GOV_PROJECT_OWNER_ID") projectName = acc.RandomProjectName() ) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckGovBasic(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - CheckDestroy: acc.CheckDestroyProject, + CheckDestroy: acc.CheckDestroyProjectGov, Steps: []resource.TestStep{ { Config: configGovWithOwner(orgID, projectName, projectOwnerID), Check: resource.ComposeTestCheckFunc( - checkExists(resourceName), + checkExistsGov(resourceName), resource.TestCheckResourceAttr(resourceName, "name", projectName), resource.TestCheckResourceAttr(resourceName, "org_id", orgID), + resource.TestCheckResourceAttr(resourceName, "project_owner_id", projectOwnerID), resource.TestCheckResourceAttr(resourceName, "region_usage_restrictions", "GOV_REGIONS_ONLY"), ), }, }, }) } + func TestAccProject_withFalseDefaultSettings(t *testing.T) { var ( orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") @@ -1076,6 +1076,14 @@ func tagChecks(tags map[string]string, notFoundKeys ...string) resource.TestChec } func checkExists(resourceName string) resource.TestCheckFunc { + return checkExistsWithConn(resourceName, acc.ConnV2()) +} + +func checkExistsGov(resourceName string) resource.TestCheckFunc { + return checkExistsWithConn(resourceName, acc.ConnV2UsingGov()) +} + +func checkExistsWithConn(resourceName string, conn *admin.APIClient) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -1084,7 +1092,7 @@ func checkExists(resourceName string) resource.TestCheckFunc { if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } - if _, _, err := acc.ConnV2().ProjectsApi.GetProjectByName(context.Background(), rs.Primary.Attributes["name"]).Execute(); err == nil { + if _, _, err := conn.ProjectsApi.GetProjectByName(context.Background(), rs.Primary.Attributes["name"]).Execute(); err == nil { return nil } return fmt.Errorf("project (%s) does not exist", rs.Primary.ID) @@ -1135,7 +1143,7 @@ func configBasic(orgID, projectName, projectOwnerID string, includeDataSource bo } func configGovWithOwner(orgID, projectName, projectOwnerID string) string { - return fmt.Sprintf(` + return acc.ConfigGovProvider() + fmt.Sprintf(` resource "mongodbatlas_project" "test" { org_id = %[1]q name = %[2]q diff --git a/internal/testutil/acc/project.go b/internal/testutil/acc/project.go index bb18de3fe8..1d1250f7e6 100644 --- a/internal/testutil/acc/project.go +++ b/internal/testutil/acc/project.go @@ -6,20 +6,27 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "go.mongodb.org/atlas-sdk/v20231115013/admin" ) func CheckDestroyProject(s *terraform.State) error { + return checkDestroyProject(ConnV2(), s) +} + +func CheckDestroyProjectGov(s *terraform.State) error { + return checkDestroyProject(ConnV2UsingGov(), s) +} + +func checkDestroyProject(conn *admin.APIClient, s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_project" { continue } - - projectRes, _, _ := Conn().Projects.GetOneProjectByName(context.Background(), rs.Primary.ID) + projectRes, _, _ := conn.ProjectsApi.GetProjectByName(context.Background(), rs.Primary.ID).Execute() if projectRes != nil { return fmt.Errorf("project (%s) still exists", rs.Primary.ID) } } - return nil } From 2ba7f475658c2301effd410152a67cbaa4afff26 Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Fri, 24 May 2024 15:28:53 +0100 Subject: [PATCH 09/11] test: add gov migration test and enable project gov test --- internal/service/project/resource_project_migration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/project/resource_project_migration_test.go b/internal/service/project/resource_project_migration_test.go index bc87950ac4..d55651ae7a 100644 --- a/internal/service/project/resource_project_migration_test.go +++ b/internal/service/project/resource_project_migration_test.go @@ -143,7 +143,7 @@ func TestMigProject_withLimits(t *testing.T) { } // based on bug report: https://github.com/mongodb/terraform-provider-mongodbatlas/issues/2263 -func TestMigGovProject_region_usage_restrictions(t *testing.T) { +func TestMigGovProject_regionUsageRestrictionsDefault(t *testing.T) { var ( orgID = os.Getenv("MONGODB_ATLAS_GOV_ORG_ID") projectName = acc.RandomProjectName() From 16249256cf9299c89b8c5c63438793f5e8cdd8a3 Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Fri, 24 May 2024 16:10:03 +0100 Subject: [PATCH 10/11] fix: region_usage_restrictions must be null not empty --- internal/service/project/resource_project.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index b2bae2dfce..4a9f0790b1 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -312,7 +312,7 @@ func (r *projectRS) Create(ctx context.Context, req resource.CreateRequest, resp OrgId: projectPlan.OrgID.ValueString(), Name: projectPlan.Name.ValueString(), WithDefaultAlertsSettings: projectPlan.WithDefaultAlertsSettings.ValueBoolPointer(), - RegionUsageRestrictions: projectPlan.RegionUsageRestrictions.ValueStringPointer(), + RegionUsageRestrictions: conversion.StringNullIfEmpty(projectPlan.RegionUsageRestrictions.ValueString()).ValueStringPointer(), Tags: &tags, } From b39b41d967f5f52d6a5ba5b7caf758a8e9c51eae Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Mon, 27 May 2024 09:39:06 +0100 Subject: [PATCH 11/11] chore: fix merge accident & use MONGODB_ATLAS_GOV_PROJECT_OWNER_ID --- .github/workflows/acceptance-tests-runner.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/acceptance-tests-runner.yml b/.github/workflows/acceptance-tests-runner.yml index 8434dcb0ce..409fc23f07 100644 --- a/.github/workflows/acceptance-tests-runner.yml +++ b/.github/workflows/acceptance-tests-runner.yml @@ -353,7 +353,7 @@ jobs: terraform_wrapper: false - name: Acceptance Tests env: - MONGODB_ATLAS_f: ${{ inputs.mongodb_atlas_project_owner_id }} + MONGODB_ATLAS_PROJECT_OWNER_ID: ${{ inputs.mongodb_atlas_project_owner_id }} MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }} AWS_REGION: ${{ vars.AWS_REGION_LOWERCASE }} AWS_SECRET_ACCESS_KEY: ${{ secrets.aws_secret_access_key }} @@ -682,6 +682,7 @@ jobs: - name: Acceptance Tests env: MONGODB_ATLAS_PROJECT_OWNER_ID: ${{ inputs.mongodb_atlas_project_owner_id }} + MONGODB_ATLAS_GOV_PROJECT_OWNER_ID: ${{ inputs.mongodb_atlas_gov_project_owner_id }} MONGODB_ATLAS_TEAMS_IDS: ${{ inputs.mongodb_atlas_teams_ids }} AWS_ACCOUNT_ID: ${{ secrets.aws_account_id }} AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key_id }}