-
Notifications
You must be signed in to change notification settings - Fork 1
doc: Update doc for adv2v2 command #68
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
1459a03
initial doc
lantoli da42d28
remove guide_clu2adv_dynamic_block
lantoli e27d5a4
move info in file guide_adv2v2_dynamic_block.md to command_adv2v2.md
lantoli 0ec0ed7
update clu2adv doc
lantoli 88653b0
update adv2v2 doc
lantoli 0c349b1
typos
lantoli 1a508f3
fix individual region
lantoli 2eb0958
typo
lantoli 52c69e8
Update docs/command_adv2v2.md
lantoli 646a4e2
installation first
lantoli 23593a5
Update docs/command_clu2adv.md
lantoli 3a64a89
change dynamic block section name
lantoli 3ed0cde
add doc clarification about underlaying resources not being changed
lantoli e643483
Update docs/command_adv2v2.md
lantoli ed10890
Update docs/command_adv2v2.md
lantoli a9eaa90
Update docs/command_adv2v2.md
lantoli 0c68989
Update docs/command_clu2adv.md
lantoli b58b254
Update docs/command_clu2adv.md
lantoli 57f8832
Update docs/command_clu2adv.md
lantoli 64c0774
Update docs/command_adv2v2.md
lantoli a6be82a
Update docs/command_clu2adv.md
lantoli 7fd7785
Update docs/command_clu2adv.md
lantoli a6df286
Update docs/command_adv2v2.md
lantoli f5f57f1
Update docs/command_adv2v2.md
lantoli 6c0a7cb
Update docs/command_adv2v2.md
lantoli 2c6afef
Update docs/command_clu2adv.md
lantoli 3f5d2b2
apply feedback
lantoli eddaa86
apply more feedback
lantoli 2459d09
Update docs/command_adv2v2.md
lantoli 45ce5d8
doc replaceOutput
lantoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
# Convert mongodbatlas_advanced_cluster to Provider 2.0.0 schema | ||
|
||
advancedClusterToV2 (adv2v2) command helps you migrate previous `mongodbatlas_advanced_cluster` configurations to the new Provider 2.0.0 schema. | ||
bodegus marked this conversation as resolved.
Show resolved
Hide resolved
lantoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
MongoDB Atlas Provider 2.0.0 introduces a new, cleaner structure for `mongodbatlas_advanced_cluster` resources. The main changes include the use of nested attributes instead of blocks and deletion of deprecated attributes like `disk_size_gb` at root level or `num_shards`. | ||
|
||
## Usage | ||
|
||
To convert a Terraform configuration from the previous `mongodbatlas_advanced_cluster` schema to the Provider 2.0.0 schema, use the following command: | ||
|
||
```bash | ||
atlas terraform advancedClusterToV2 --file in.tf --output out.tf | ||
``` | ||
|
||
You can also use shorter aliases: | ||
```bash | ||
atlas tf adv2v2 -f in.tf -o out.tf | ||
``` | ||
|
||
### Command Options | ||
|
||
- `--file` or `-f`: Input file path containing the `mongodbatlas_advanced_cluster` configuration | ||
- `--output` or `-o`: Output file path for the converted Provider 2.0.0 configuration | ||
- `--replaceOutput` or `-r`: Overwrite the output file if it exists, or even use the same output file as the input file | ||
lantoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `--watch` or `-w`: Keep the plugin running and watching for changes in the input file | ||
|
||
## Examples | ||
|
||
You can find [here](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/tree/main/internal/convert/testdata/adv2v2) examples of input files (suffix .in.tf) and the corresponding output files (suffix .out.tf). | ||
|
||
## Dynamic Blocks | ||
|
||
`dynamic` blocks are used to generate multiple nested blocks based on a set of values. | ||
Given the different ways of using dynamic blocks, we recommend reviewing the output and making sure it fits your needs. | ||
lantoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Dynamic blocks in tags and labels | ||
|
||
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. | ||
You can also combine the use of dynamic blocks in `tags` and `labels` with individual blocks in the same cluster definition, e.g.: | ||
lantoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```hcl | ||
tags { | ||
key = "environment" | ||
value = var.environment | ||
} | ||
dynamic "tags" { | ||
for_each = var.tags | ||
content { | ||
key = tags.key | ||
value = replace(tags.value, "/", "_") | ||
} | ||
} | ||
``` | ||
|
||
### Dynamic blocks in region_configs | ||
|
||
You can use `dynamic` blocks for `region_configs`. The plugin assumes that `for_each` has an expression which is evaluated to a `list` of objects. | ||
lantoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This is an example of how to use dynamic blocks in `region_configs`: | ||
```hcl | ||
replication_specs { | ||
num_shards = var.replication_specs.num_shards | ||
zone_name = var.replication_specs.zone_name # only needed if you're using zones | ||
dynamic "region_configs" { | ||
for_each = var.replication_specs.region_configs | ||
content { | ||
priority = region_configs.value.priority | ||
provider_name = region_configs.value.provider_name | ||
region_name = region_configs.value.region_name | ||
electable_specs { | ||
instance_size = region_configs.value.instance_size | ||
node_count = region_configs.value.electable_node_count | ||
} | ||
# read_only_specs, analytics_specs, auto_scaling and analytics_auto_scaling can also be defined | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Dynamic blocks in replication_specs | ||
|
||
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. | ||
lantoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This is an example of how to use dynamic blocks in `replication_specs`: | ||
```hcl | ||
dynamic "replication_specs" { | ||
for_each = var.replication_specs | ||
content { | ||
num_shards = replication_specs.value.num_shards | ||
zone_name = replication_specs.value.zone_name # only needed if you're using zones | ||
dynamic "region_configs" { | ||
for_each = replication_specs.value.region_configs | ||
priority = region_configs.value.priority | ||
provider_name = region_configs.value.provider_name | ||
region_name = region_configs.value.region_name | ||
electable_specs { | ||
instance_size = region_configs.value.instance_size | ||
node_count = region_configs.value.electable_node_count | ||
} | ||
# read_only_specs, analytics_specs, auto_scaling and analytics_auto_scaling can also be defined | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Limitations | ||
|
||
If you need to use the plugin for `dynamic` block use cases not yet supported, please send us [feedback](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/issues). | ||
|
||
#### Dynamic block and individual blocks in the same resource | ||
|
||
Dynamic block and individual blocks for `region_configs` or `replication_specs` are not supported at the same time. The recommended way to handle this is to remove the individual `region_configs` or `replication_specs` blocks and use a local `list` variable with [concat](https://developer.hashicorp.com/terraform/language/functions/concat) to add the individual block information to the variable you're using in the `for_each` expression. | ||
lantoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Let's see an example with `region_configs`, it is the same idea for `replication_specs`. In the original configuration file, the `mongodb_cluster` resource is used inside a module that receives the `region_configs` elements in a `list` variable and we want to add an additional `region_configs` with a read-only node. | ||
lantoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```hcl | ||
variable "replication_specs" { | ||
type = object({ | ||
num_shards = number | ||
region_configs = list(object({ | ||
priority = number | ||
provider_name = string | ||
region_name = string | ||
instance_size = string | ||
electable_node_count = number | ||
read_only_node_count = number | ||
})) | ||
}) | ||
} | ||
|
||
resource "mongodbatlas_advanced_cluster" "this" { | ||
project_id = var.project_id | ||
name = var.cluster_name | ||
cluster_type = var.cluster_type | ||
replication_specs { | ||
num_shards = var.replication_specs.num_shards | ||
dynamic "region_configs" { | ||
for_each = var.replication_specs.region_configs | ||
priority = region_configs.value.priority | ||
provider_name = region_configs.value.provider_name | ||
region_name = region_configs.value.region_name | ||
electable_specs { | ||
instance_size = region_configs.value.instance_size | ||
node_count = region_configs.value.electable_node_count | ||
} | ||
read_only_specs { | ||
instance_size = region_configs.value.instance_size | ||
node_count = region_configs.value.read_only_node_count | ||
} | ||
} | ||
region_configs { # individual region | ||
priority = 0 | ||
provider_name = "AWS" | ||
region_name = "US_EAST_1" | ||
read_only_specs { | ||
instance_size = var.instance_size | ||
node_count = 1 | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
We modify the configuration file to create an intermediate `local` variable to merge the `region_configs` variable elements and the additional `region_configs`: | ||
```hcl | ||
variable "replication_specs" { | ||
type = object({ | ||
num_shards = number | ||
region_configs = list(object({ | ||
priority = number | ||
provider_name = string | ||
region_name = string | ||
instance_size = string | ||
electable_node_count = number | ||
read_only_node_count = number | ||
})) | ||
}) | ||
} | ||
|
||
locals { | ||
region_configs_all = concat( | ||
var.replication_specs.region_configs, | ||
[ | ||
{ | ||
priority = 0 | ||
provider_name = "AWS" | ||
region_name = "US_EAST_1" | ||
instance_size = var.instance_size | ||
electable_node_count = 0 | ||
read_only_node_count = 1 | ||
}, | ||
] | ||
) | ||
} | ||
|
||
resource "mongodbatlas_advanced_cluster" "this" { | ||
project_id = var.project_id | ||
name = var.cluster_name | ||
cluster_type = var.cluster_type | ||
replication_specs { | ||
num_shards = var.replication_specs.num_shards | ||
dynamic "region_configs" { | ||
for_each = local.region_configs_all # changed to use the local variable | ||
priority = region_configs.value.priority | ||
provider_name = region_configs.value.provider_name | ||
region_name = region_configs.value.region_name | ||
electable_specs { | ||
instance_size = region_configs.value.instance_size | ||
node_count = region_configs.value.electable_node_count | ||
} | ||
read_only_specs { | ||
instance_size = region_configs.value.instance_size | ||
node_count = region_configs.value.read_only_node_count | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
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. | ||
lantoli marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be after installation perhaps?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's fair, changed here: 646a4e2