feat: Supports dynamic blocks in regions_config#33
Conversation
marcosuma
left a comment
There was a problem hiding this comment.
Great job, it's also nice to see the amount of test changes
| #### Dynamic blocks in regions_config | ||
|
|
||
| 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. | ||
| Dynamic block and individual blocks for `regions_config` are not supported at the same time in a `replication_specs`. This is an example of how to use dynamic blocks in `regions_config`: |
There was a problem hiding this comment.
- should we move what's not supported in the limitations?
- is there an "easy" why we don't support dynamic and individual blocks?
- would a workaround be to execute the command twice, one with dynamic block only and one with individual?
There was a problem hiding this comment.
- As we have specific sections for the different dynamic blocks where we explain them in more details, I think it's better to keep the limitation for each dynamic block in their specific section, but I've added a note here: 32ca654
- The main reasons are:
- Customers won't probably have definitions file like that.
- Effort and complexity to support it is not trivial.
- The result output will be quite complicated.
I've added a comment in the previous commit regarding this so they can give feedback if some customer needs it. For example we support it in tags and label as some customers are using it, e.g:
- That workaround might help, at the end I think the solution would be to use the
mergefunction like in tags.
There was a problem hiding this comment.
The point I was trying to get is: customers will come at us with questions. For limitations we are aware, it's useful to have clear instructions on "why" the limitation and "what is the alternative". (this internal thread should teach us).
Said that, it looks like the "why" is more on "we are not investing on it", which is fine. Can we at least have a "what's the alternative" clearly written in the docs?
| - [`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`. | ||
| - [`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`. | ||
| - `dynamic` blocks are currently supported only for `tags` and `labels`. **Coming soon**: support for `replication_specs` and `regions_config`. | ||
| - [`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`. |
There was a problem hiding this comment.
so great to see our limitations going away. Great stuff @lantoli
| replication_specs = [ | ||
| for i in range(var.replication_specs.num_shards) : { | ||
| region_configs = flatten([ | ||
| for priority in range(7, 0, -1) : [ |
| if priorityStr == "" { | ||
| return nil, fmt.Errorf("%s: %s not found", errRepSpecs, nPriority) | ||
| } | ||
| region, err := getRegionConfig(d.content, root, true) |
There was a problem hiding this comment.
@AgustinBettati FYI region config object creation is reused in individual and dynamic block
| - [`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`. | ||
| - `dynamic` blocks are currently supported only for `tags` and `labels`. **Coming soon**: support for `replication_specs` and `regions_config`. | ||
| - [`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`. | ||
| - `dynamic` blocks are currently supported only for `tags`, `labels` and `regions_config`. See limitations in their corresponding dynamic block sections above. **Coming soon**: support for `replication_specs`. |
There was a problem hiding this comment.
can you link "See limitations" to "#### Dynamic blocks in regions_config"?
Co-authored-by: Marco Suma <smumrc@gmail.com>
AgustinBettati
left a comment
There was a problem hiding this comment.
leaving one doubt for my understanding
| - [`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`. | ||
| - [`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`. | ||
| - `dynamic` blocks are currently supported only for `tags` and `labels`. **Coming soon**: support for `replication_specs` and `regions_config`. | ||
| - [`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`. |
There was a problem hiding this comment.
This limitation doesn't apply if you're using
dynamicblocks inregions_configorreplication_specs
I am not fully clear why we can support this case but not when is a regular literal replication_specs block.
There was a problem hiding this comment.
because in the literal case we physically replicate the block num_shard times so we avoid to introduce for loops and the adv_cluster is straighthforward. However in the module case as we need to create the loops and introduce some complexity, it's ok to also iterate through the priorities. We could potentially support that case if some customers are interested
|
|
||
| backup_enabled = var.backup_enabled | ||
| replication_specs = [ | ||
| for i in range(var.replication_specs.num_shards) : { |
There was a problem hiding this comment.
like the simple way of supporting num_shards
There was a problem hiding this comment.
@AgustinBettati yeah exactly, we could do it using the for loop, right now we copy the block shard times
Description
Supports dynamic blocks in
regions_config. In follow-up support forreplication_specswill be done.Additionally in this PR, limitations for
num_shards,electable_specsandpriorityhave been removed.regions_configpriority reorder is now done if possible (priorities are numerical literals), elseregions_configoriginal order is kept.Link to any related issue(s): CLOUDP-303941
Type of change:
Required Checklist:
Further comments