diff --git a/internal/convert/adv2v2.go b/internal/convert/adv2v2.go index 0f8661d..f1c659e 100644 --- a/internal/convert/adv2v2.go +++ b/internal/convert/adv2v2.go @@ -50,7 +50,7 @@ func updateResource(resource *hclwrite.Block) (bool, error) { if err := fillTagsLabelsOpt(resourceb, nLabels); err != nil { return false, err } - fillBlockOpt(resourceb, nAdvConf) + fillAdvConfigOpt(resourceb) fillBlockOpt(resourceb, nBiConnector) fillBlockOpt(resourceb, nPinnedFCV) fillBlockOpt(resourceb, nTimeouts) @@ -132,7 +132,7 @@ func hasExpectedBlocksAsAttributes(resourceb *hclwrite.Body) bool { nRepSpecs, nTags, nLabels, - nAdvConf, + nAdvConfig, nBiConnector, nPinnedFCV, nTimeouts, diff --git a/internal/convert/clu2adv.go b/internal/convert/clu2adv.go index a3b9c9a..6897f67 100644 --- a/internal/convert/clu2adv.go +++ b/internal/convert/clu2adv.go @@ -95,7 +95,6 @@ func convertDataSource(block *hclwrite.Block) bool { } if newName, found := convertMap[getResourceName(block)]; found { setResourceName(block, newName) - block.Body().SetAttributeValue(nUseRepSpecsPerShard, cty.True) return true } return false @@ -165,7 +164,7 @@ func fillCluster(resourceb *hclwrite.Body) error { if err := fillTagsLabelsOpt(resourceb, nLabels); err != nil { return err } - fillBlockOpt(resourceb, nAdvConf) + fillAdvConfigOpt(resourceb) fillBlockOpt(resourceb, nBiConnector) fillBlockOpt(resourceb, nPinnedFCV) fillBlockOpt(resourceb, nTimeouts) @@ -304,6 +303,20 @@ func fillBlockOpt(resourceb *hclwrite.Body, name string) { resourceb.SetAttributeRaw(name, hcl.TokensObject(block.Body())) } +func fillAdvConfigOpt(resourceb *hclwrite.Body) { + block := resourceb.FirstMatchingBlock(nAdvConfig, nil) + if block == nil { + return + } + blockBody := block.Body() + + // Remove deprecated attributes from advanced_configuration + blockBody.RemoveAttribute(nFailIndexKeyTooLong) + blockBody.RemoveAttribute(nDefaultReadConcern) + + fillBlockOpt(resourceb, nAdvConfig) +} + // fillReplicationSpecsWithDynamicBlock used for dynamic blocks in replication_specs func fillReplicationSpecsWithDynamicBlock(resourceb *hclwrite.Body, root attrVals) (dynamicBlock, error) { dSpec, err := getDynamicBlock(resourceb, nRepSpecs) diff --git a/internal/convert/const.go b/internal/convert/const.go index b0ca30b..350f210 100644 --- a/internal/convert/const.go +++ b/internal/convert/const.go @@ -29,7 +29,7 @@ const ( nTags = "tags" nLabels = "labels" nTimeouts = "timeouts" - nAdvConf = "advanced_configuration" + nAdvConfig = "advanced_configuration" nPinnedFCV = "pinned_fcv" nBiConnector = "bi_connector_config" nElectableSpecs = "electable_specs" @@ -70,7 +70,6 @@ const ( nZoneName = "zone_name" nKey = "key" nValue = "value" - nUseRepSpecsPerShard = "use_replication_spec_per_shard" nMoved = "moved" nFrom = "from" nTo = "to" @@ -79,4 +78,6 @@ const ( nContent = "content" nRegion = "region" nSpec = "spec" + nFailIndexKeyTooLong = "fail_index_key_too_long" + nDefaultReadConcern = "default_read_concern" ) diff --git a/internal/convert/testdata/adv2v2/adv_config_bi_connector_pinned_fcv.in.tf b/internal/convert/testdata/adv2v2/adv_config_bi_connector_pinned_fcv.in.tf index 0272377..fcbb254 100644 --- a/internal/convert/testdata/adv2v2/adv_config_bi_connector_pinned_fcv.in.tf +++ b/internal/convert/testdata/adv2v2/adv_config_bi_connector_pinned_fcv.in.tf @@ -16,7 +16,9 @@ resource "mongodbatlas_advanced_cluster" "this" { advanced_configuration { # comments in advanced_configuration are kept - javascript_enabled = true + javascript_enabled = true + fail_index_key_too_long = false # deprecated so removed in output + default_read_concern = "available" # deprecated so removed in output } bi_connector_config { diff --git a/internal/convert/testdata/clu2adv/adv_config_bi_connector_pinned_fcv.in.tf b/internal/convert/testdata/clu2adv/adv_config_bi_connector_pinned_fcv.in.tf index 5488361..9d18bd3 100644 --- a/internal/convert/testdata/clu2adv/adv_config_bi_connector_pinned_fcv.in.tf +++ b/internal/convert/testdata/clu2adv/adv_config_bi_connector_pinned_fcv.in.tf @@ -6,7 +6,9 @@ resource "mongodbatlas_cluster" "this" { provider_instance_size_name = var.instance_size advanced_configuration { # comments in advanced_configuration are kept - javascript_enabled = true + javascript_enabled = true + fail_index_key_too_long = false # deprecated so removed in output + default_read_concern = "available" # deprecated so removed in output } bi_connector_config { # comments in bi_connector_config are kept diff --git a/internal/convert/testdata/clu2adv/data_sources.out.tf b/internal/convert/testdata/clu2adv/data_sources.out.tf index 2ba949f..5df4b12 100644 --- a/internal/convert/testdata/clu2adv/data_sources.out.tf +++ b/internal/convert/testdata/clu2adv/data_sources.out.tf @@ -1,9 +1,8 @@ data "mongodbatlas_advanced_cluster" "singular" { # data source content is kept - singular - project_id = mongodbatlas_advanced_cluster.example.project_id - name = mongodbatlas_advanced_cluster.example.name - depends_on = [mongodbatlas_privatelink_endpoint_service.example_endpoint] - use_replication_spec_per_shard = true + project_id = mongodbatlas_advanced_cluster.example.project_id + name = mongodbatlas_advanced_cluster.example.name + depends_on = [mongodbatlas_privatelink_endpoint_service.example_endpoint] # Generated by atlas-cli-plugin-terraform. # Please review the changes and confirm that references to this resource are updated. @@ -11,8 +10,7 @@ data "mongodbatlas_advanced_cluster" "singular" { data "mongodbatlas_advanced_clusters" "plural" { # data source content is kept - plural - project_id = mongodbatlas_advanced_cluster.example.project_id - use_replication_spec_per_shard = true + project_id = mongodbatlas_advanced_cluster.example.project_id # Generated by atlas-cli-plugin-terraform. # Please review the changes and confirm that references to this resource are updated. diff --git a/internal/convert/testdata/clu2adv/dynamic_regions_config_auto_scaling.in.tf b/internal/convert/testdata/clu2adv/dynamic_regions_config_auto_scaling.in.tf index bbc64bc..1f126d7 100644 --- a/internal/convert/testdata/clu2adv/dynamic_regions_config_auto_scaling.in.tf +++ b/internal/convert/testdata/clu2adv/dynamic_regions_config_auto_scaling.in.tf @@ -33,6 +33,8 @@ resource "mongodbatlas_cluster" "cluster" { } advanced_configuration { + fail_index_key_too_long = false # deprecated so removed in output + default_read_concern = "available" # deprecated so removed in output oplog_size_mb = var.oplog_size_mb transaction_lifetime_limit_seconds = var.transaction_lifetime_limit_seconds minimum_enabled_tls_protocol = "TLS1_2"