Skip to content

Conversation

lantoli
Copy link
Collaborator

@lantoli lantoli commented Feb 17, 2025

Description

Converts clusters with multiple replications_specs, region_configs and shards

Link to any related issue(s): CLOUDP-299292

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

@@ -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
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

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

@lantoli lantoli marked this pull request as ready for review February 18, 2025 07:12
@lantoli lantoli requested a review from a team as a code owner February 18, 2025 07:12
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`.
Copy link
Contributor

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?

Copy link
Collaborator Author

@lantoli lantoli Feb 18, 2025

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

Copy link
Contributor

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?

Suggested change
- `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`.

Copy link
Collaborator Author

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

Copy link
Contributor

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?

Copy link
Collaborator Author

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?

Copy link
Contributor

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

Copy link
Collaborator Author

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?

Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok, got it

Copy link
Contributor

@AgustinBettati AgustinBettati left a 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
Comment on lines 38 to 39
- `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`.
Copy link
Contributor

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

Copy link
Collaborator Author

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
Copy link
Contributor

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

Copy link
Collaborator Author

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)
Copy link
Contributor

@EspenAlbert EspenAlbert Feb 18, 2025

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?

Copy link
Collaborator Author

@lantoli lantoli Feb 18, 2025

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" {
Copy link
Contributor

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?

Copy link
Collaborator Author

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

Copy link
Contributor

@EspenAlbert EspenAlbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Copy link
Contributor

@marcosuma marcosuma left a 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`.
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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"

@lantoli lantoli merged commit c4722c9 into main Feb 18, 2025
6 checks passed
@lantoli lantoli deleted the CLOUDP-299292_shards branch February 18, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants