-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Supports dynamic blocks in replication_specs #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
222a235
2fd47c2
08116f2
ab86332
dbde632
4bd2d11
06b3f32
204b118
bd78ea8
24737a0
0c13a4a
e04dead
919fc02
4dea79b
342043d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,5 @@ const ( | |
nForEach = "for_each" | ||
nContent = "content" | ||
nRegion = "region" | ||
nSpec = "spec" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,27 +23,27 @@ resource "mongodbatlas_advanced_cluster" "cluster" { | |
provider_name = var.provider_name | ||
region_name = region.region_name | ||
priority = region.priority | ||
electable_specs = region.electable_nodes > 0 ? { | ||
electable_specs = region.electable_nodes == 0 ? null : { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: easier to read as we only need to change the first line of the object but not the last one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that any of these are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, read_only_nodes for sure, and in the latest PR I also allow electable_nodes to be null (e.g. a region only with read-only nodes) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lantoli, will the comparison crash if region.read_only_nodes are null? |
||
node_count = region.electable_nodes | ||
instance_size = var.provider_instance_size_name | ||
disk_size_gb = var.disk_size_gb | ||
ebs_volume_type = var.provider_volume_type | ||
disk_iops = var.provider_disk_iops | ||
} : null | ||
read_only_specs = region.read_only_nodes > 0 ? { | ||
} | ||
read_only_specs = region.read_only_nodes == 0 ? null : { | ||
node_count = region.read_only_nodes | ||
instance_size = var.provider_instance_size_name | ||
disk_size_gb = var.disk_size_gb | ||
ebs_volume_type = var.provider_volume_type | ||
disk_iops = var.provider_disk_iops | ||
} : null | ||
analytics_specs = region.analytics_nodes > 0 ? { | ||
} | ||
analytics_specs = region.analytics_nodes == 0 ? null : { | ||
node_count = region.analytics_nodes | ||
instance_size = var.provider_instance_size_name | ||
disk_size_gb = var.disk_size_gb | ||
ebs_volume_type = var.provider_volume_type | ||
disk_iops = var.provider_disk_iops | ||
} : null | ||
} | ||
auto_scaling = { | ||
disk_gb_enabled = var.auto_scaling_disk_gb_enabled | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Based on https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/examples/migrate_cluster_to_advanced_cluster/module_maintainer/v1/main.tf | ||
resource "mongodbatlas_cluster" "this" { | ||
lifecycle { | ||
precondition { | ||
condition = !(var.auto_scaling_disk_gb_enabled && var.disk_size > 0) | ||
error_message = "Must use either auto_scaling_disk_gb_enabled or disk_size, not both." | ||
} | ||
} | ||
|
||
project_id = var.project_id | ||
name = var.cluster_name | ||
auto_scaling_disk_gb_enabled = var.auto_scaling_disk_gb_enabled | ||
cluster_type = var.cluster_type | ||
disk_size_gb = var.disk_size | ||
mongo_db_major_version = var.mongo_db_major_version | ||
provider_instance_size_name = var.instance_size | ||
provider_name = var.provider_name | ||
|
||
dynamic "tags" { | ||
for_each = var.tags | ||
content { | ||
key = tags.key | ||
value = tags.value | ||
} | ||
} | ||
|
||
dynamic "replication_specs" { | ||
for_each = var.replication_specs | ||
content { | ||
num_shards = replication_specs.value.num_shards | ||
zone_name = replication_specs.value.zone_name | ||
|
||
dynamic "regions_config" { | ||
for_each = replication_specs.value.regions_config | ||
content { | ||
electable_nodes = regions_config.value.electable_nodes | ||
priority = regions_config.value.priority | ||
read_only_nodes = regions_config.value.read_only_nodes | ||
region_name = regions_config.value.region_name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
# example of variable for demostration purposes, not used in the conversion | ||
variable "replication_specs" { | ||
description = "List of replication specifications in mongodbatlas_cluster format" | ||
type = list(object({ | ||
num_shards = number | ||
zone_name = string | ||
regions_config = list(object({ | ||
region_name = string | ||
electable_nodes = number | ||
priority = number | ||
read_only_nodes = optional(number, 0) | ||
})) | ||
})) | ||
default = [ | ||
{ | ||
num_shards = 1 | ||
zone_name = "Zone 1" | ||
regions_config = [ | ||
{ | ||
region_name = "US_EAST_1" | ||
electable_nodes = 3 | ||
priority = 7 | ||
} | ||
] | ||
}, { | ||
num_shards = 2 | ||
zone_name = "Zone 2" | ||
regions_config = [ | ||
{ | ||
region_name = "US_WEST_2" | ||
electable_nodes = 2 | ||
priority = 6 | ||
read_only_nodes = 1 | ||
}, { | ||
region_name = "EU_WEST_1" | ||
electable_nodes = 3 | ||
priority = 7 | ||
} | ||
] | ||
} | ||
] | ||
} |
Uh oh!
There was an error while loading. Please reload this page.