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 replication_specs (#37)
* change condition to make it clearer
* failing test
* all dynamic blocks in replication_specs
* initial fillReplicationSpecsWithDynamicBlock
* pass tests
* rename test
* test with different var names
* doc
* typo
* reference to guide
* Update README.md
Co-authored-by: Marco Suma <[email protected]>
* remove error-prone sentence
* add guide
* doc adjustment
* doc small change
---------
Co-authored-by: Marco Suma <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+33-11Lines changed: 33 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,8 @@ atlas plugin list
30
30
31
31
### Usage
32
32
33
+
You can find more information in the [Migration Guide: Cluster to Advanced Cluster](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/cluster-to-advanced-cluster-migration-guide).
34
+
33
35
**Note**: In order to use the **Preview for MongoDB Atlas Provider 2.0.0** of `mongodbatlas_advanced_cluster`, you need to set the environment variable `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER` to `true`.
34
36
35
37
If you want to convert a Terraform configuration from `mongodbatlas_cluster` to `mongodbatlas_advanced_cluster`, use the following command:
@@ -75,31 +77,51 @@ dynamic "tags" {
75
77
76
78
#### Dynamic blocks in regions_config
77
79
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.
80
+
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. See this [guide](./docs/guide_clu2adv_dynamic_block.md) to learn more about some limitations.
79
81
This is an example of how to use dynamic blocks in `regions_config`:
80
82
```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
83
+
replication_specs {
84
+
num_shards = var.replication_specs.num_shards
85
+
zone_name = var.replication_specs.zone_name # only needed if you're using zones
You can use `dynamic` blocks for `replication_specs`. The plugin assumes that `for_each` has an expression which is evaluated to a `list` of objects. See this [guide](./docs/guide_clu2adv_dynamic_block.md) to learn more about some limitations.
101
+
This is an example of how to use dynamic blocks in `replication_specs`:
102
+
```hcl
103
+
dynamic "replication_specs" {
104
+
for_each = var.replication_specs
105
+
content {
106
+
num_shards = replication_specs.value.num_shards
107
+
zone_name = replication_specs.value.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
120
99
121
### Limitations
100
122
101
123
-[`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`.
124
+
-`dynamic` blocks are supported with some [limitations](./docs/guide_clu2adv_dynamic_block.md).
# Guide to handle dynamic block limitations in regions_config and replication_specs
2
+
3
+
The plugin command to convert `mongodbatlas_cluster` resources to `mongodbatlas_advanced_cluster` supports `dynamic` blocks for `regions_config` and `replication_specs`. However, there are some limitations when using `dynamic` blocks in these fields. This guide explains how to handle these limitations.
4
+
5
+
If you need to use the plugin for use cases not yet supported, please send us [feedback](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/issues).
6
+
7
+
## Dynamic block and individual blocks in the same resource
8
+
9
+
Dynamic block and individual blocks for `regions_config` or `replication_specs` are not supported at the same time. The recommended way to handle this is to remove the individual `regions_config` or `replication_specs` blocks and use a local variable to add the individual block information to the variable you're using in the `for_each` expression, 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.
10
+
11
+
Let's see an example with `regions_config`, it is the same for `replication_specs`. In the original configuration file, the `mongodb_cluster` resource is used inside a module that receives the `regions_config` elements in a `list` variable and we want to add an additional `region_config` with a read-only node.
We modify the configuration file to create an intermediate `local` variable to merge the `regions_config` variable elements and the additional `region_config`:
This modified configuration file has the same behavior as the original one, but it doesn't have individual blocks anymore, only the `dynamic` block, so it is supported by the plugin.
0 commit comments