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
Dynamic blocks for `tags` and `labels` are converted from block syntax to object syntax:
361
+
362
+
**Tags Input:**
363
+
```hcl
364
+
dynamic "tags" {
365
+
for_each = var.tags
366
+
content {
367
+
key = tags.key
368
+
value = tags.value
369
+
}
370
+
}
371
+
```
372
+
373
+
**Tags Output:**
374
+
```hcl
375
+
tags = {
376
+
for tag in var.tags : tag.key => tag.value
377
+
}
378
+
```
379
+
380
+
### Handling num_shards with Dynamic Blocks
381
+
382
+
The converter properly handles `num_shards` expansion:
383
+
384
+
1.**For literal num_shards values**: The converter expands the replication spec for each shard
385
+
2.**For variable num_shards values**: The converter uses `range()` function to handle the expansion dynamically
386
+
387
+
**Example with variable num_shards:**
388
+
```hcl
389
+
# Input
390
+
dynamic "replication_specs" {
391
+
for_each = var.specs
392
+
content {
393
+
num_shards = replication_specs.value.shards
394
+
# ... config
395
+
}
396
+
}
397
+
398
+
# Output
399
+
replication_specs = flatten([
400
+
for spec in var.specs : [
401
+
for i in range(spec.shards) : {
402
+
# ... config
403
+
}
404
+
]
405
+
])
406
+
```
407
+
408
+
### Mixed Static and Dynamic Blocks
409
+
410
+
If you have both static and dynamic blocks for `replication_specs` or `region_configs`, the converter handles them separately:
411
+
412
+
**Input:**
413
+
```hcl
414
+
replication_specs {
415
+
num_shards = 1
416
+
region_configs {
417
+
region_name = "US_EAST_1"
418
+
# ... config
419
+
}
420
+
}
421
+
422
+
dynamic "replication_specs" {
423
+
for_each = var.additional_specs
424
+
content {
425
+
# ... config
426
+
}
427
+
}
428
+
```
429
+
430
+
**Output:**
431
+
```hcl
432
+
replication_specs = concat(
433
+
[{
434
+
config = [{
435
+
region_name = "US_EAST_1"
436
+
# ... config
437
+
}]
438
+
}],
439
+
flatten([
440
+
for spec in var.additional_specs : [
441
+
# ... transformed dynamic content
442
+
]
443
+
])
444
+
)
445
+
```
446
+
219
447
## Limitations
220
448
449
+
### Dynamic Block Limitations
450
+
451
+
1.**Complex for_each expressions**: While the converter preserves complex expressions in `for_each`, they should be verified after conversion to ensure they work with the new structure.
452
+
453
+
2.**Custom functions in dynamic blocks**: If you use custom functions or complex conditionals within dynamic blocks, these are preserved but must be tested thoroughly.
454
+
455
+
3.**Variable references transformation**: The converter updates variable references (e.g., `replication_specs.value` to `spec`), but complex nested references should be reviewed.
456
+
457
+
4.**Block ordering**: The Provider 2.0.0 format may handle block ordering differently. Ensure any dependencies on block order are maintained.
458
+
459
+
### General Limitations
460
+
221
461
- The converter requires valid HCL syntax in the input file
222
-
- Complex expressions in dynamic blocks may require manual review
223
-
- Custom functions or complex conditionals in `for_each` expressions are preserved but should be tested
224
-
- See the [dynamic blocks guide](./guide_adv2v2_dynamic_block.md) for more details on dynamic block handling
462
+
- Manual review is recommended for complex configurations
463
+
- Always run `terraform plan` after conversion to verify the changes
464
+
465
+
If you encounter use cases not yet supported, please send us [feedback](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/issues).
466
+
467
+
## Best Practices
468
+
469
+
1.**Review the output**: Always review the converted configuration to ensure it matches your intentions.
470
+
2.**Test incrementally**: Test the converted configuration in a development environment before applying to production.
471
+
3.**Simplify when possible**: If the converter produces complex nested expressions, consider simplifying them manually for better readability.
472
+
4.**Use terraform plan**: Always run `terraform plan` after conversion to verify that the changes are as expected.
473
+
474
+
## More Examples
475
+
476
+
You can find more examples of dynamic block conversions in the [test data directory](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/tree/main/internal/convert/testdata/adv2v2), particularly:
0 commit comments