Skip to content

Commit 08116f2

Browse files
committed
all dynamic blocks in replication_specs
1 parent 2fd47c2 commit 08116f2

File tree

4 files changed

+18
-44
lines changed

4 files changed

+18
-44
lines changed

internal/convert/convert.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const (
3737
)
3838

3939
var (
40-
dynamicBlockAllowList = []string{nTags, nLabels, nConfigSrc}
40+
dynamicBlockAllowList = []string{nTags, nLabels, nConfigSrc, nRepSpecs}
4141
)
4242

4343
type attrVals struct {
@@ -91,17 +91,22 @@ func convertResource(block *hclwrite.Block) (bool, error) {
9191
}
9292

9393
var err error
94-
if blockb.FirstMatchingBlock(nRepSpecs, nil) != nil {
95-
err = fillCluster(blockb)
96-
} else {
94+
if isFreeTierCluster(blockb) {
9795
err = fillFreeTierCluster(blockb)
96+
} else {
97+
err = fillCluster(blockb)
9898
}
9999
if err != nil {
100100
return false, err
101101
}
102102
return true, nil
103103
}
104104

105+
func isFreeTierCluster(resourceb *hclwrite.Body) bool {
106+
d, _ := getDynamicBlock(resourceb, nRepSpecs)
107+
return resourceb.FirstMatchingBlock(nRepSpecs, nil) == nil && !d.IsPresent()
108+
}
109+
105110
func convertDataSource(block *hclwrite.Block) bool {
106111
if block.Type() != dataSourceType {
107112
return false

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# Based on https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/examples/migrate_cluster_to_advanced_cluster/module_maintainer/v1/main.tf
2-
resource "mongodbatlas_advanced_cluster" "dynamic_regions_config" {
2+
resource "mongodbatlas_advanced_cluster" "this" {
33
lifecycle {
44
precondition {
55
condition = !(var.auto_scaling_disk_gb_enabled && var.disk_size > 0)
66
error_message = "Must use either auto_scaling_disk_gb_enabled or disk_size, not both."
77
}
88
}
99

10-
project_id = var.project_id
11-
name = var.cluster_name
12-
auto_scaling_disk_gb_enabled = var.auto_scaling_disk_gb_enabled
13-
cluster_type = var.cluster_type
14-
mongo_db_major_version = var.mongo_db_major_version
10+
project_id = var.project_id
11+
name = var.cluster_name
12+
cluster_type = var.cluster_type
13+
mongo_db_major_version = var.mongo_db_major_version
1514

1615
replication_specs = flatten([
1716
for spec in var.replication_specs : [
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
2+
"autoscaling_missing_attribute": "setting replication_specs: attribute provider_instance_size_name not found",
23
"configuration_file_error": "failed to parse Terraform config file",
34
"free_cluster_missing_attribute": "free cluster (because no replication_specs): attribute backing_provider_name not found",
4-
"autoscaling_missing_attribute": "setting replication_specs: attribute provider_instance_size_name not found",
5-
"replication_specs_missing_regions_config": "setting replication_specs: regions_config not found",
65
"regions_config_missing_priority": "setting replication_specs: attribute priority not found",
7-
"replication_specs_unsupported_dynamic": "dynamic blocks are not supported",
8-
"replication_specs_non_literal_num_shards": "setting num_shards: failed to evaluate number",
9-
"replication_specs_missing_num_shards": "num_shards not found"
6+
"replication_specs_missing_num_shards": "num_shards not found",
7+
"replication_specs_missing_regions_config": "setting replication_specs: regions_config not found",
8+
"replication_specs_non_literal_num_shards": "setting num_shards: failed to evaluate number"
109
}

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

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)