Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Upgrades global_cluster_config resource to auto-generated SDK #1938

Merged
merged 15 commits into from
Feb 14, 2024
29 changes: 29 additions & 0 deletions .github/workflows/migration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
serverless: ${{ steps.filter.outputs.serverless == 'true' || env.mustTrigger == 'true' }}
data_lake: ${{ steps.filter.outputs.data_lake == 'true' || env.mustTrigger == 'true' }}
cluster_outage_simulation: ${{ steps.filter.outputs.cluster_outage_simulation == 'true' || env.mustTrigger == 'true' }}
cluster: ${{ steps.filter.outputs.cluster == 'true' || env.mustTrigger == 'true' }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd
Expand Down Expand Up @@ -135,6 +136,9 @@ jobs:
- 'internal/service/datalakepipeline/*.go'
cluster_outage_simulation:
- 'internal/service/clusteroutagesimulation/*.go'
cluster:
- 'internal/service/cluster/*.go'
- 'internal/service/globalclusterconfig/*.go'

project:
needs: [ change-detection, get-provider-version ]
Expand Down Expand Up @@ -488,3 +492,28 @@ jobs:
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
TEST_REGEX: "^TestAccMigrationOutageSimulationCluster"
run: make testacc
cluster:
needs: [ change-detection, get-provider-version ]
if: ${{ needs.change-detection.outputs.cluster == 'true' || inputs.test_group == 'cluster' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
- name: Migration Tests
env:
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }}
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }}
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
TEST_REGEX: "^TestAccMigrationClusterRS"
run: make testacc

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (

func TestAccMigrationBackupRSCloudBackupSnapshot_basic(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
clusterInfo = acc.GetClusterInfo(orgID, true)
clusterInfo = acc.GetClusterInfo(&acc.ClusterRequest{CloudBackup: true})
description = "My description in my cluster"
retentionInDays = "4"
config = configBasic(&clusterInfo, description, retentionInDays)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func TestAccBackupRSCloudBackupSnapshot_basic(t *testing.T) {
var (
dataSourcePluralSimpleName = "data.mongodbatlas_cloud_backup_snapshots.test"
dataSourcePluralPaginationName = "data.mongodbatlas_cloud_backup_snapshots.pagination"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
clusterInfo = acc.GetClusterInfo(orgID, true)
clusterInfo = acc.GetClusterInfo(&acc.ClusterRequest{CloudBackup: true})
description = "My description in my cluster"
retentionInDays = "4"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func DataSource() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceMongoDBAtlasGlobalClusterRead,
ReadContext: dataSourceRead,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -61,13 +61,12 @@ func DataSource() *schema.Resource {
}
}

func dataSourceMongoDBAtlasGlobalClusterRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
// Get client connection.
conn := meta.(*config.MongoDBClient).Atlas
func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
connV2 := meta.(*config.MongoDBClient).AtlasV2
projectID := d.Get("project_id").(string)
clusterName := d.Get("cluster_name").(string)

globalCluster, resp, err := conn.GlobalClusters.Get(ctx, projectID, clusterName)
globalCluster, resp, err := connV2.GlobalClustersApi.GetManagedNamespace(ctx, projectID, clusterName).Execute()
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil
Expand All @@ -76,11 +75,11 @@ func dataSourceMongoDBAtlasGlobalClusterRead(ctx context.Context, d *schema.Reso
return diag.FromErr(fmt.Errorf(errorGlobalClusterRead, clusterName, err))
}

if err := d.Set("managed_namespaces", flattenManagedNamespaces(globalCluster.ManagedNamespaces)); err != nil {
if err := d.Set("managed_namespaces", flattenManagedNamespaces(globalCluster.GetManagedNamespaces())); err != nil {
return diag.FromErr(fmt.Errorf(errorGlobalClusterRead, clusterName, err))
}

if err := d.Set("custom_zone_mapping", globalCluster.CustomZoneMapping); err != nil {
if err := d.Set("custom_zone_mapping", globalCluster.GetCustomZoneMapping()); err != nil {
return diag.FromErr(fmt.Errorf(errorGlobalClusterRead, clusterName, err))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
package globalclusterconfig_test

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
)

func TestAccClusterRSGlobalClusterDS_basic(t *testing.T) {
acc.SkipTestForCI(t) // needs to be fixed: 404 (request "GROUP_NOT_FOUND") No group with ID
var (
dataSourceName = "data.mongodbatlas_global_cluster_config.config"
name = fmt.Sprintf("test-acc-global-%s", acctest.RandString(10))
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
clusterInfo = acc.GetClusterInfo(&acc.ClusterRequest{Geosharded: true})
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: testAccCheckMongoDBAtlasGlobalClusterDestroy,
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: testAccDSMongoDBAtlasGlobalClusterConfig(orgID, projectName, name),
Config: configBasic(&clusterInfo, false, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
resource.TestCheckResourceAttrSet(dataSourceName, "cluster_name"),
Expand All @@ -34,68 +27,3 @@ func TestAccClusterRSGlobalClusterDS_basic(t *testing.T) {
},
})
}

func testAccDSMongoDBAtlasGlobalClusterConfig(orgID, projectName, name string) string {
return fmt.Sprintf(`

resource "mongodbatlas_project" "project" {
org_id = %[1]q
name = %[2]q
}

resource "mongodbatlas_cluster" "test" {
project_id = mongodbatlas_project.project.id
name = %[3]q
disk_size_gb = 80
cloud_backup = false
cluster_type = "GEOSHARDED"

// Provider Settings "block"
provider_name = "AWS"
provider_instance_size_name = "M30"

replication_specs {
zone_name = "Zone 1"
num_shards = 2
regions_config {
region_name = "US_EAST_1"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
}

replication_specs {
zone_name = "Zone 2"
num_shards = 2
regions_config {
region_name = "US_EAST_2"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
}
}

resource "mongodbatlas_global_cluster_config" "config" {
project_id = mongodbatlas_cluster.test.project_id
cluster_name = mongodbatlas_cluster.test.name

managed_namespaces {
db = "mydata"
collection = "publishers"
custom_shard_key = "city"
}

custom_zone_mappings {
location ="CA"
zone = "Zone 1"
}
}

data "mongodbatlas_global_cluster_config" "config" {
project_id = mongodbatlas_global_cluster_config.config.project_id
cluster_name = mongodbatlas_global_cluster_config.config.cluster_name
}
`, orgID, projectName, name)
}