Skip to content

Commit 3f93627

Browse files
committed
remove limitations for priority and electable_nodes
1 parent ae8471b commit 3f93627

File tree

8 files changed

+102
-24
lines changed

8 files changed

+102
-24
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ Dynamic block and individual blocks for `regions_config` are not supported at th
8080

8181
### Limitations
8282

83-
- The plugin doesn't support `regions_config` without `electable_nodes` as there can be some issues with `priority` when they only have `analytics_nodes` and/or `electable_nodes`.
84-
- [`priority`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/cluster#priority-1) is required in `regions_config` and must be a numeric [literal expression](https://developer.hashicorp.com/nomad/docs/job-specification/hcl2/expressions#literal-expressions) between 7 and 1, e.g. `var.priority` is not supported. This is to allow reordering them by descending priority as this is expected in `mongodbatlas_advanced_cluster`.
8583
- [`num_shards`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/cluster#num_shards-2) in `replication_specs` must be a numeric [literal expression](https://developer.hashicorp.com/nomad/docs/job-specification/hcl2/expressions#literal-expressions), e.g. `var.num_shards` is not supported. This is to allow creating a `replication_specs` element per shard in `mongodbatlas_advanced_cluster`.
8684
- `dynamic` blocks are currently supported only for `tags`, `labels` and `regions_config`. **Coming soon**: support for `replication_specs`.
8785

internal/convert/convert.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,9 @@ func getRegionConfig(configSrc *hclwrite.Block, root attrVals) (*hclwrite.File,
368368
if err := hcl.MoveAttr(configSrc.Body(), fileb, nPriority, nPriority, errRepSpecs); err != nil {
369369
return nil, err
370370
}
371-
electable, errElec := getSpecs(configSrc, nElectableNodes, root)
372-
if errElec != nil {
373-
return nil, errElec
371+
if electable, _ := getSpecs(configSrc, nElectableNodes, root); electable != nil {
372+
fileb.SetAttributeRaw(nElectableSpecs, electable)
374373
}
375-
fileb.SetAttributeRaw(nElectableSpecs, electable)
376374
if readOnly, _ := getSpecs(configSrc, nReadOnlyNodes, root); readOnly != nil {
377375
fileb.SetAttributeRaw(nReadOnlySpecs, readOnly)
378376
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,24 @@ resource "mongodbatlas_cluster" "ar" {
1818
}
1919
}
2020
}
21+
22+
resource "mongodbatlas_cluster" "ar_not_electable" {
23+
project_id = var.project_id
24+
name = "ar"
25+
cluster_type = "REPLICASET"
26+
provider_name = "AWS"
27+
provider_instance_size_name = "M10"
28+
disk_size_gb = 90
29+
provider_volume_type = "PROVISIONED"
30+
provider_disk_iops = 100
31+
replication_specs {
32+
num_shards = 1
33+
regions_config {
34+
region_name = "US_EAST_1"
35+
priority = 7
36+
electable_nodes = 0
37+
analytics_nodes = 2
38+
read_only_nodes = 1
39+
}
40+
}
41+
}

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,37 @@ resource "mongodbatlas_advanced_cluster" "ar" {
3838
# Generated by atlas-cli-plugin-terraform.
3939
# Please review the changes and confirm that references to this resource are updated.
4040
}
41+
42+
resource "mongodbatlas_advanced_cluster" "ar_not_electable" {
43+
project_id = var.project_id
44+
name = "ar"
45+
cluster_type = "REPLICASET"
46+
replication_specs = [
47+
{
48+
region_configs = [
49+
{
50+
provider_name = "AWS"
51+
region_name = "US_EAST_1"
52+
priority = 7
53+
read_only_specs = {
54+
node_count = 1
55+
instance_size = "M10"
56+
disk_size_gb = 90
57+
ebs_volume_type = "PROVISIONED"
58+
disk_iops = 100
59+
}
60+
analytics_specs = {
61+
node_count = 2
62+
instance_size = "M10"
63+
disk_size_gb = 90
64+
ebs_volume_type = "PROVISIONED"
65+
disk_iops = 100
66+
}
67+
}
68+
]
69+
}
70+
]
71+
72+
# Generated by atlas-cli-plugin-terraform.
73+
# Please review the changes and confirm that references to this resource are updated.
74+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,20 @@ resource "mongodbatlas_cluster" "ar" {
1515
}
1616
}
1717
}
18+
19+
resource "mongodbatlas_cluster" "ar_not_electable" {
20+
project_id = var.project_id
21+
name = "ar"
22+
cluster_type = "REPLICASET"
23+
provider_name = "AWS"
24+
provider_instance_size_name = "M10"
25+
replication_specs {
26+
num_shards = 1
27+
regions_config {
28+
region_name = "US_EAST_1"
29+
priority = 7
30+
analytics_nodes = 2
31+
read_only_nodes = 1
32+
}
33+
}
34+
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,31 @@ resource "mongodbatlas_advanced_cluster" "ar" {
2929
# Generated by atlas-cli-plugin-terraform.
3030
# Please review the changes and confirm that references to this resource are updated.
3131
}
32+
33+
resource "mongodbatlas_advanced_cluster" "ar_not_electable" {
34+
project_id = var.project_id
35+
name = "ar"
36+
cluster_type = "REPLICASET"
37+
replication_specs = [
38+
{
39+
region_configs = [
40+
{
41+
provider_name = "AWS"
42+
region_name = "US_EAST_1"
43+
priority = 7
44+
read_only_specs = {
45+
node_count = 1
46+
instance_size = "M10"
47+
}
48+
analytics_specs = {
49+
node_count = 2
50+
instance_size = "M10"
51+
}
52+
}
53+
]
54+
}
55+
]
56+
57+
# Generated by atlas-cli-plugin-terraform.
58+
# Please review the changes and confirm that references to this resource are updated.
59+
}

internal/convert/testdata/clu2adv/errors.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"free_cluster_missing_attribute": "free cluster (because no replication_specs): attribute backing_provider_name not found",
44
"autoscaling_missing_attribute": "setting replication_specs: attribute provider_instance_size_name not found",
55
"replication_specs_missing_regions_config": "setting replication_specs: regions_config not found",
6-
"regions_config_missing_electable_nodes": "setting replication_specs: attribute electable_nodes not found",
76
"regions_config_missing_priority": "setting replication_specs: attribute priority not found",
87
"replication_specs_unsupported_dynamic": "dynamic blocks are not supported",
98
"replication_specs_non_literal_num_shards": "setting num_shards: failed to evaluate number",

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

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

0 commit comments

Comments
 (0)