-
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
Changes from 27 commits
1459a03
da42d28
e27d5a4
0ec0ed7
88653b0
0c349b1
1a508f3
2eb0958
52c69e8
646a4e2
23593a5
3a64a89
3ed0cde
e643483
ed10890
a9eaa90
0c68989
b58b254
57f8832
64c0774
a6be82a
7fd7785
a6df286
f5f57f1
6c0a7cb
2c6afef
3f5d2b2
eddaa86
2459d09
45ce5d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,219 @@ | ||||||||||
# Convert mongodbatlas_advanced_cluster to Provider 2.0.0 schema | ||||||||||
|
||||||||||
The advancedClusterToV2 (adv2v2) command helps you migrate previous `mongodbatlas_advanced_cluster` configurations to the new Provider 2.0.0 schema. | ||||||||||
|
||||||||||
This revised file migrates the Terraform configurations and state to the latest version and doesn't modify the resources deployed in MongoDB Atlas. | ||||||||||
|
||||||||||
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. | ||||||||||
We recommend reviewing the output and making sure it fits your needs. | ||||||||||
|
||||||||||
### Dynamic blocks in tags and labels | ||||||||||
|
||||||||||
You can use `dynamic` blocks for `tags` and `labels`. The plugin assumes that the value of `for_each` is an expression which evaluates 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, for example: | ||||||||||
```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 the value of `for_each` is an expression which evaluates to a `list` of objects. | ||||||||||
|
||||||||||
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 the value of `for_each` is an expression which evaluates to a `list` of objects. | ||||||||||
|
||||||||||
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). | ||||||||||
|
||||||||||
#### Combination of blocks with dynamic and inline expressions | ||||||||||
|
||||||||||
Dynamic blocks and individual blocks for `region_configs` or `replication_specs` are not supported at the same time. 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. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, changed here: eddaa86 |
||||||||||
|
||||||||||
Let's see an example with `region_configs`; it's 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. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, changed here: eddaa86 |
||||||||||
```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's supported by the plugin. |
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