Skip to content

Commit 8fc0daa

Browse files
committed
failing replication_specs test
1 parent 552f37b commit 8fc0daa

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
resource "mongodbatlas_advanced_cluster" "dynamic_replication_specs" {
2+
project_id = var.project_id
3+
name = var.cluster_name
4+
cluster_type = "GEOSHARDED"
5+
dynamic "replication_specs" {
6+
for_each = var.replication_specs
7+
content {
8+
num_shards = replication_specs.value.num_shards
9+
zone_name = replication_specs.value.zone_name
10+
dynamic "region_configs" {
11+
for_each = replication_specs.value.region_configs
12+
content {
13+
priority = region_configs.value.priority
14+
provider_name = region_configs.value.provider_name
15+
region_name = region_configs.value.region_name
16+
electable_specs {
17+
instance_size = region_configs.value.instance_size
18+
node_count = region_configs.value.electable_node_count
19+
}
20+
read_only_specs {
21+
instance_size = region_configs.value.instance_size
22+
node_count = region_configs.value.read_only_node_count
23+
}
24+
}
25+
}
26+
}
27+
}
28+
}
29+
30+
# example of variable for demostration purposes, not used in the conversion
31+
variable "replication_specs" {
32+
description = "List of replication specifications in mongodbatlas_advanced_cluster format"
33+
type = list(object({
34+
num_shards = number
35+
zone_name = string
36+
region_configs = list(object({
37+
provider_name = string
38+
region_name = string
39+
instance_size = string
40+
electable_node_count = number
41+
read_only_node_count = number
42+
priority = number
43+
}))
44+
}))
45+
default = [
46+
{
47+
num_shards = 1
48+
zone_name = "Zone A"
49+
region_configs = [
50+
{
51+
provider_name = "AWS"
52+
region_name = "US_EAST_1"
53+
instance_size = "M10"
54+
electable_node_count = 3
55+
read_only_node_count = 0
56+
priority = 7
57+
}
58+
]
59+
}, {
60+
num_shards = 2
61+
zone_name = "Zone B"
62+
region_configs = [
63+
{
64+
provider_name = "AWS"
65+
region_name = "US_WEST_2"
66+
instance_size = "M10"
67+
electable_node_count = 2
68+
read_only_node_count = 1
69+
priority = 7
70+
}, {
71+
provider_name = "AWS"
72+
region_name = "EU_WEST_1"
73+
instance_size = "M10"
74+
electable_node_count = 1
75+
read_only_node_count = 0
76+
priority = 6
77+
}
78+
]
79+
}
80+
]
81+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
resource "mongodbatlas_advanced_cluster" "dynamic_replication_specs" {
2+
project_id = var.project_id
3+
name = var.cluster_name
4+
cluster_type = "GEOSHARDED"
5+
replication_specs = flatten([
6+
for spec in var.replication_specs : [
7+
for i in range(spec.num_shards) : {
8+
zone_name = spec.zone_name
9+
region_configs = [
10+
for region in spec.region_configs : {
11+
provider_name = region.provider_name
12+
region_name = region.region_name
13+
priority = region.priority
14+
electable_specs = {
15+
node_count = region.electable_node_count
16+
instance_size = region.instance_size
17+
}
18+
read_only_specs = {
19+
node_count = region.read_only_node_count
20+
instance_size = region.instance_size
21+
}
22+
}
23+
]
24+
}
25+
]
26+
])
27+
28+
# Updated by atlas-cli-plugin-terraform, please review the changes.
29+
}
30+
31+
32+
# example of variable for demostration purposes, not used in the conversion
33+
variable "replication_specs" {
34+
description = "List of replication specifications in mongodbatlas_advanced_cluster format"
35+
type = list(object({
36+
num_shards = number
37+
zone_name = string
38+
region_configs = list(object({
39+
provider_name = string
40+
region_name = string
41+
instance_size = string
42+
electable_node_count = number
43+
read_only_node_count = number
44+
priority = number
45+
}))
46+
}))
47+
default = [
48+
{
49+
num_shards = 1
50+
zone_name = "Zone A"
51+
region_configs = [
52+
{
53+
provider_name = "AWS"
54+
region_name = "US_EAST_1"
55+
instance_size = "M10"
56+
electable_node_count = 3
57+
read_only_node_count = 0
58+
priority = 7
59+
}
60+
]
61+
}, {
62+
num_shards = 2
63+
zone_name = "Zone B"
64+
region_configs = [
65+
{
66+
provider_name = "AWS"
67+
region_name = "US_WEST_2"
68+
instance_size = "M10"
69+
electable_node_count = 2
70+
read_only_node_count = 1
71+
priority = 7
72+
}, {
73+
provider_name = "AWS"
74+
region_name = "EU_WEST_1"
75+
instance_size = "M10"
76+
electable_node_count = 1
77+
read_only_node_count = 0
78+
priority = 6
79+
}
80+
]
81+
}
82+
]
83+
}

0 commit comments

Comments
 (0)