You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Supports dynamic blocks in regions_config (#33)
* doc assumption for dynamic blocks in tags and labels
* dynamic_regions_config example
* range for priorities
* allow dynamic block in regions_config
* doc
* update comment
* minimum implementation to have test failing because difference in golden file
* export enclose funcs
* create EncloseNewLines and remove SetAttrExpr
* root replication_specs
* remove priority checks about numerical literal
* reuse getRegionConfig from dynamic block logic
* only sort by priority if all priorities are numerical literals
* remove limitations for priority and electable_nodes
* use config in dynamic blocks from individual
* passing test
* add auto_scaling example
* fix region_configs name replacement
* refactor isDynamicBlock
* go back to unexported tokenNewLine
* add analytics specs
* example in readme
* clarify num_shards limitation
* feedback section
* getDynamicBlockRegionConfigsRegionArray
* refactor fillRegionConfigsDynamicBlock
* EncloseBracketsNewLines
* fillRegionConfigsDynamicBlock doc
* move shards closer to where it's used
* add comment for priority loop
* add dynamic block doc
* small doc adjustment
* rename to fillReplicationSpecsWithDynamicRegionConfigs
* Update README.md
Co-authored-by: Marco Suma <[email protected]>
* link to limitations
* how to handle limitation
---------
Co-authored-by: Marco Suma <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+31-5Lines changed: 31 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,8 @@ Given the different ways of using dynamic blocks, we recommend reviewing the out
57
57
58
58
#### Dynamic blocks in tags and labels
59
59
60
-
You can use `dynamic` blocks for `tags` and `labels`. You can also combine the use of dynamic blocks in `tags` and `labels` with individual blocks in the same cluster definition, e.g.:
60
+
You can use `dynamic` blocks for `tags` and `labels`. The plugin assumes that `for_each` has an expression which is evaluated to a `map` of strings.
61
+
You can also combine the use of dynamic blocks in `tags` and `labels` with individual blocks in the same cluster definition, e.g.:
61
62
```hcl
62
63
tags {
63
64
key = "environment"
@@ -72,12 +73,37 @@ dynamic "tags" {
72
73
}
73
74
```
74
75
76
+
#### Dynamic blocks in regions_config
77
+
78
+
You can use `dynamic` blocks for `regions_config`. The plugin assumes that `for_each` has an expression which is evaluated to a `list` or `set` of objects.
79
+
This is an example of how to use dynamic blocks in `regions_config`:
80
+
```hcl
81
+
replication_specs {
82
+
num_shards = var.replication_specs.num_shards
83
+
zone_name = var.replication_specs.zone_name # only needed if you're using zones
Dynamic block and individual blocks for `regions_config` are not supported at the same time. If you need this use case, please send us [feedback](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/issues). There are currently two main approaches to handle this:
96
+
- (Recommended) Remove the individual `regions_config` blocks and add their information to the variable you're using in the `for_each` expression, e.g. using [concat](https://developer.hashicorp.com/terraform/language/functions/concat) if you're using a list or [setunion](https://developer.hashicorp.com/terraform/language/functions/setunion) for sets. In this way, you don't need to change the generated `mongodb_advanced_cluster` configuration.
97
+
- Change the generated `mongodb_advanced_cluster` configuration to join the individual blocks to the code generated for the `dynamic` block. This approach is more error-prone.
98
+
75
99
### Limitations
76
100
77
-
- 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`.
78
-
-[`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`.
79
-
-[`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`.
80
-
-`dynamic` blocks are currently supported only for `tags` and `labels`. **Coming soon**: support for `replication_specs` and `regions_config`.
101
+
-[`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`. This limitation doesn't apply if you're using `dynamic` blocks in `regions_config` or `replication_specs`.
102
+
-`dynamic` blocks are currently supported only for `tags`, `labels` and `regions_config`. See limitations for `regions_config` support in [its section](#dynamic-blocks-in-regions_config) above. **Coming soon**: support for `replication_specs`.
103
+
104
+
## Feedback
105
+
106
+
If you find any issues or have any suggestions, please open an [issue](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/issues) in this repository.
0 commit comments