Skip to content

Commit 97d04dc

Browse files
authored
feat: Update clu2adv command so it doesn't produce deprecated attributes (#66)
1 parent d3b06dc commit 97d04dc

File tree

7 files changed

+32
-14
lines changed

7 files changed

+32
-14
lines changed

internal/convert/adv2v2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func updateResource(resource *hclwrite.Block) (bool, error) {
5050
if err := fillTagsLabelsOpt(resourceb, nLabels); err != nil {
5151
return false, err
5252
}
53-
fillBlockOpt(resourceb, nAdvConf)
53+
fillAdvConfigOpt(resourceb)
5454
fillBlockOpt(resourceb, nBiConnector)
5555
fillBlockOpt(resourceb, nPinnedFCV)
5656
fillBlockOpt(resourceb, nTimeouts)
@@ -132,7 +132,7 @@ func hasExpectedBlocksAsAttributes(resourceb *hclwrite.Body) bool {
132132
nRepSpecs,
133133
nTags,
134134
nLabels,
135-
nAdvConf,
135+
nAdvConfig,
136136
nBiConnector,
137137
nPinnedFCV,
138138
nTimeouts,

internal/convert/clu2adv.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ func convertDataSource(block *hclwrite.Block) bool {
9595
}
9696
if newName, found := convertMap[getResourceName(block)]; found {
9797
setResourceName(block, newName)
98-
block.Body().SetAttributeValue(nUseRepSpecsPerShard, cty.True)
9998
return true
10099
}
101100
return false
@@ -165,7 +164,7 @@ func fillCluster(resourceb *hclwrite.Body) error {
165164
if err := fillTagsLabelsOpt(resourceb, nLabels); err != nil {
166165
return err
167166
}
168-
fillBlockOpt(resourceb, nAdvConf)
167+
fillAdvConfigOpt(resourceb)
169168
fillBlockOpt(resourceb, nBiConnector)
170169
fillBlockOpt(resourceb, nPinnedFCV)
171170
fillBlockOpt(resourceb, nTimeouts)
@@ -304,6 +303,20 @@ func fillBlockOpt(resourceb *hclwrite.Body, name string) {
304303
resourceb.SetAttributeRaw(name, hcl.TokensObject(block.Body()))
305304
}
306305

306+
func fillAdvConfigOpt(resourceb *hclwrite.Body) {
307+
block := resourceb.FirstMatchingBlock(nAdvConfig, nil)
308+
if block == nil {
309+
return
310+
}
311+
blockBody := block.Body()
312+
313+
// Remove deprecated attributes from advanced_configuration
314+
blockBody.RemoveAttribute(nFailIndexKeyTooLong)
315+
blockBody.RemoveAttribute(nDefaultReadConcern)
316+
317+
fillBlockOpt(resourceb, nAdvConfig)
318+
}
319+
307320
// fillReplicationSpecsWithDynamicBlock used for dynamic blocks in replication_specs
308321
func fillReplicationSpecsWithDynamicBlock(resourceb *hclwrite.Body, root attrVals) (dynamicBlock, error) {
309322
dSpec, err := getDynamicBlock(resourceb, nRepSpecs)

internal/convert/const.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929
nTags = "tags"
3030
nLabels = "labels"
3131
nTimeouts = "timeouts"
32-
nAdvConf = "advanced_configuration"
32+
nAdvConfig = "advanced_configuration"
3333
nPinnedFCV = "pinned_fcv"
3434
nBiConnector = "bi_connector_config"
3535
nElectableSpecs = "electable_specs"
@@ -70,7 +70,6 @@ const (
7070
nZoneName = "zone_name"
7171
nKey = "key"
7272
nValue = "value"
73-
nUseRepSpecsPerShard = "use_replication_spec_per_shard"
7473
nMoved = "moved"
7574
nFrom = "from"
7675
nTo = "to"
@@ -79,4 +78,6 @@ const (
7978
nContent = "content"
8079
nRegion = "region"
8180
nSpec = "spec"
81+
nFailIndexKeyTooLong = "fail_index_key_too_long"
82+
nDefaultReadConcern = "default_read_concern"
8283
)

internal/convert/testdata/adv2v2/adv_config_bi_connector_pinned_fcv.in.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ resource "mongodbatlas_advanced_cluster" "this" {
1616

1717
advanced_configuration {
1818
# comments in advanced_configuration are kept
19-
javascript_enabled = true
19+
javascript_enabled = true
20+
fail_index_key_too_long = false # deprecated so removed in output
21+
default_read_concern = "available" # deprecated so removed in output
2022
}
2123

2224
bi_connector_config {

internal/convert/testdata/clu2adv/adv_config_bi_connector_pinned_fcv.in.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ resource "mongodbatlas_cluster" "this" {
66
provider_instance_size_name = var.instance_size
77
advanced_configuration {
88
# comments in advanced_configuration are kept
9-
javascript_enabled = true
9+
javascript_enabled = true
10+
fail_index_key_too_long = false # deprecated so removed in output
11+
default_read_concern = "available" # deprecated so removed in output
1012
}
1113
bi_connector_config {
1214
# comments in bi_connector_config are kept

internal/convert/testdata/clu2adv/data_sources.out.tf

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
data "mongodbatlas_advanced_cluster" "singular" {
22
# data source content is kept - singular
3-
project_id = mongodbatlas_advanced_cluster.example.project_id
4-
name = mongodbatlas_advanced_cluster.example.name
5-
depends_on = [mongodbatlas_privatelink_endpoint_service.example_endpoint]
6-
use_replication_spec_per_shard = true
3+
project_id = mongodbatlas_advanced_cluster.example.project_id
4+
name = mongodbatlas_advanced_cluster.example.name
5+
depends_on = [mongodbatlas_privatelink_endpoint_service.example_endpoint]
76

87
# Generated by atlas-cli-plugin-terraform.
98
# Please review the changes and confirm that references to this resource are updated.
109
}
1110

1211
data "mongodbatlas_advanced_clusters" "plural" {
1312
# data source content is kept - plural
14-
project_id = mongodbatlas_advanced_cluster.example.project_id
15-
use_replication_spec_per_shard = true
13+
project_id = mongodbatlas_advanced_cluster.example.project_id
1614

1715
# Generated by atlas-cli-plugin-terraform.
1816
# Please review the changes and confirm that references to this resource are updated.

internal/convert/testdata/clu2adv/dynamic_regions_config_auto_scaling.in.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ resource "mongodbatlas_cluster" "cluster" {
3333
}
3434

3535
advanced_configuration {
36+
fail_index_key_too_long = false # deprecated so removed in output
37+
default_read_concern = "available" # deprecated so removed in output
3638
oplog_size_mb = var.oplog_size_mb
3739
transaction_lifetime_limit_seconds = var.transaction_lifetime_limit_seconds
3840
minimum_enabled_tls_protocol = "TLS1_2"

0 commit comments

Comments
 (0)