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

fix: Removes SchemaConfigModeAttr from resources #1961

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions internal/service/advancedcluster/model_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ func SchemaAdvancedConfigDS() *schema.Schema {

func SchemaConnectionStrings() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
ConfigMode: schema.SchemaConfigModeAttr,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"standard": {
Expand All @@ -133,19 +132,17 @@ func SchemaConnectionStrings() *schema.Schema {
Computed: true,
},
"private_endpoint": {
Type: schema.TypeList,
Computed: true,
ConfigMode: schema.SchemaConfigModeAttr,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"connection_string": {
Type: schema.TypeString,
Computed: true,
},
"endpoints": {
Type: schema.TypeList,
Computed: true,
ConfigMode: schema.SchemaConfigModeAttr,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"endpoint_id": {
Expand Down Expand Up @@ -185,11 +182,10 @@ func SchemaConnectionStrings() *schema.Schema {

func SchemaAdvancedConfig() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
Computed: true,
ConfigMode: schema.SchemaConfigModeAttr,
MaxItems: 1,
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default_read_concern": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package advancedcluster_test

import (
"fmt"
"os"
"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"
)
Expand Down Expand Up @@ -66,3 +68,106 @@ func TestAccMigrationAdvancedCluster_multiCloud(t *testing.T) {
},
})
}

func TestAccMigrationAdvancedCluster_partialAdvancedConf(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
rName = acc.RandomClusterName()
processArgs = `advanced_configuration {
fail_index_key_too_long = false
javascript_enabled = true
minimum_enabled_tls_protocol = "TLS1_1"
no_table_scan = false
}`
biConnector = `bi_connector_config {
enabled = true
}`
processArgsUpdated = `advanced_configuration {
fail_index_key_too_long = false
javascript_enabled = true
minimum_enabled_tls_protocol = "TLS1_1"
no_table_scan = false
default_read_concern = "available"
sample_size_bi_connector = 110
sample_refresh_interval_bi_connector = 310
}`
biConnectorUpdated = `bi_connector_config {
enabled = false
read_preference = "secondary"
}`
config = configPartialAdvancedConfig(orgID, projectName, rName, processArgs, biConnector)
configUpdated = configPartialAdvancedConfig(orgID, projectName, rName, processArgsUpdated, biConnectorUpdated)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: config,
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.fail_index_key_too_long", "false"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.javascript_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.minimum_enabled_tls_protocol", "TLS1_1"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.no_table_scan", "false"),
resource.TestCheckResourceAttr(resourceName, "bi_connector_config.0.enabled", "true"),
),
},
mig.TestStepCheckEmptyPlan(config),
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not against but it looks like adding steps after mig one is like mixing mig and acc test together

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention is here is to not only ensure that plans are empty but also that updates and everything work as expected.

ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: configUpdated,
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.fail_index_key_too_long", "false"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.javascript_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.minimum_enabled_tls_protocol", "TLS1_1"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.no_table_scan", "false"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.sample_refresh_interval_bi_connector", "310"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.sample_size_bi_connector", "110"),
resource.TestCheckResourceAttr(resourceName, "bi_connector_config.0.enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "bi_connector_config.0.read_preference", "secondary"),
),
},
},
})
}

func configPartialAdvancedConfig(orgID, projectName, name, processArgs, biConnector string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "cluster_project" {
name = %[2]q
org_id = %[1]q
}
resource "mongodbatlas_advanced_cluster" "test" {
project_id = mongodbatlas_project.cluster_project.id
name = %[3]q
cluster_type = "REPLICASET"

%[5]s

replication_specs {
region_configs {
electable_specs {
instance_size = "M10"
node_count = 3
}
analytics_specs {
instance_size = "M10"
node_count = 1
}
provider_name = "AWS"
priority = 7
region_name = "EU_WEST_1"
}
}

%[4]s

}

`, orgID, projectName, name, processArgs, biConnector)
}
24 changes: 10 additions & 14 deletions internal/service/cluster/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ func Resource() *schema.Resource {
Description: "Flag that indicates whether to retain backup snapshots for the deleted dedicated cluster",
},
"bi_connector_config": {
Type: schema.TypeList,
Optional: true,
ConfigMode: schema.SchemaConfigModeAttr,
Computed: true,
MaxItems: 1,
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Expand Down Expand Up @@ -1204,9 +1203,8 @@ func updateCluster(ctx context.Context, conn *matlas.Client, request *matlas.Clu

func computedCloudProviderSnapshotBackupPolicySchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
ConfigMode: schema.SchemaConfigModeAttr,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cluster_id": {
Expand Down Expand Up @@ -1238,19 +1236,17 @@ func computedCloudProviderSnapshotBackupPolicySchema() *schema.Schema {
Computed: true,
},
"policies": {
Type: schema.TypeList,
Computed: true,
ConfigMode: schema.SchemaConfigModeAttr,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"policy_item": {
Type: schema.TypeList,
Computed: true,
ConfigMode: schema.SchemaConfigModeAttr,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Expand Down
Loading