-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Converts clusters with multiple replications_specs, region_configs and shards #22
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
Conversation
@@ -16,7 +16,6 @@ resource "mongodbatlas_cluster" "this" { | |||
pinned_fcv { | |||
# comments in pinned_fcv are kept | |||
expiration_date = var.fcv_date | |||
version = var.fcv_date |
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.
@AgustinBettati removed version following this comment, thanks: #21 (comment)
if err := fillRegionConfigs(specb, specbSrc, root); err != nil { | ||
return err | ||
} | ||
for range shardsVal { |
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.
@AgustinBettati FYI use num_shards to duplicate the replication_specs
README.md
Outdated
@@ -36,6 +36,7 @@ If you want to overwrite the output file if it exists, or even use the same outp | |||
|
|||
- The plugin doesn't support `regions_config` without `electable_nodes` as there can be some issues with `priority` when they only have `analytics_nodes` and/or `electable_nodes`. | |||
- `priority` is required in `regions_config` and must be a resolved number 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` is required in `replication_specs` and must be a resolved number, e.g. `var.num_shards` is not supported. This is to allow creating a `replication_specs` element per shard in `mongodbatlas_advanced_cluster`. |
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.
will this limitation go away? considering the field is optional, can't we assume that absence of it means = 1
?
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.
num_shards is required in replication_specs: https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/cluster#num_shards-2
your link is to num_shards at root level
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.
ah my bad - so I am not following this limitation..
num_shards
is required ...
gives me the feeling that the field must be set as a requirement for the tool, not because it's already required. Does it make sense to just remove the "is required"? And could you perhaps add the link to the field from the official doc?
- `num_shards` is required in `replication_specs` and must be a resolved number, e.g. `var.num_shards` is not supported. This is to allow creating a `replication_specs` element per shard in `mongodbatlas_advanced_cluster`. | |
- `num_shards` in `replication_specs` must be a resolved number, e.g. `var.num_shards` is not supported. This is to allow creating a `replication_specs` element per shard in `mongodbatlas_advanced_cluster`. |
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.
changed here: 8de0488
@@ -36,6 +36,7 @@ If you want to overwrite the output file if it exists, or even use the same outp | |||
|
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.
extending my question here: is your plan to remove all these limitations?
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.
sorry, what's the limitation you're referring to here?
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.
all these limitations
I don't understand if these entries in the limitations section are temporary or will go away with more implementation
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.
all current limitations in README are hard to remove so they'll probably stay as limitations. is there any specific limitation that you think we should try to remove?
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.
none in particular. I only recall there were limitations that were removed, so if there are some that you think will go away, just call it out in the doc
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.
ah, ok, got it
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.
LGTM
README.md
Outdated
- `priority` is required in `regions_config` and must be a resolved number 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` is required in `replication_specs` and must be a resolved number, e.g. `var.num_shards` is not supported. This is to allow creating a `replication_specs` element per shard in `mongodbatlas_advanced_cluster`. |
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.
small nit on phrasing, would replace "resolved" with Literal expression
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.
thanks, changed here: 8de0488
provider_instance_size_name = "M10" | ||
replication_specs { | ||
zone_name = "Zone 1" | ||
# missing num_shards |
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.
I would not be concerned about testing invalid mongodbatlas_cluster
configurations but no concern in leaving this
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.
you're right, we don't normally check for cluster validation, e.g. if you have a "hello" attribute at root level, I will be kept in adv_cluster, which is invalid.
In this case I wanted to add the test to make sure that we don't panic if num_shards is not present.
for range shardsVal { | ||
specbs = append(specbs, specb) | ||
} | ||
resourceb.RemoveBlock(specSrc) |
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.
Nice approach of using a while
loop. Didn't know about this RemoveBlock
.
Looks like we are also able to maintain all extra info, such as comments since we are using specSrc.Body()
?
I guess if num_shards
> 1, then we will duplicate all extra comments?
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.
No, unfortunately we're not keeping the comments here as we just move the attributes we need, and then we remove the original blocks.
We only copy comments (and everything in the blocks) in a block when we don't need to do any transformation, i.e. when using fillBlockOpt with timeouts, adv_configudation, bi_connector, labels and tags and. In this case we only need to wrap the body in an attribute, but not need to treat the internal attributes.
@@ -0,0 +1,59 @@ | |||
resource "mongodbatlas_cluster" "multirep" { |
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.
why not use different files?
One is multi_replication_specs_with_num_shards?
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.
I'm trying to find a balance as we're starting to have many files, so I'm trying to group some clusters with similar tests in the same file, similar to what was done here: https://github.com/mongodb-labs/atlas-cli-plugin-terraform/blob/main/internal/convert/testdata/clu2adv/tags_labels_timeouts.in.tf
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.
Nice
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.
LGTM! only a minor comment
@@ -35,7 +35,8 @@ If you want to overwrite the output file if it exists, or even use the same outp | |||
### Limitations | |||
|
|||
- The plugin doesn't support `regions_config` without `electable_nodes` as there can be some issues with `priority` when they only have `analytics_nodes` and/or `electable_nodes`. | |||
- `priority` is required in `regions_config` and must be a resolved number 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`. | |||
- [`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`. |
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.
@lantoli similar question here, in what context the "is required" is true? is it for the plugin to work? and it's because of the re-ordering?
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.
yes for the plugin to work, right now the plugin will raise an error if it's not provided. It's because the reordering, and also because it's required in Atlas when electable_specs are specified, so in reality a valid (old) c luster should almost always have priority, except if there are only analytics or read_only nodes, that we're not supporting in the plugin as in the first limitation.
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.
added more info in the doc tab "Plugin additional features"
Description
Converts clusters with multiple replications_specs, region_configs and shards
Link to any related issue(s): CLOUDP-299292
Type of change:
Required Checklist:
Further comments