-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Support dynamic blocks in adv2v2 command #67
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
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.
Pull Request Overview
Adds support for dynamic blocks in both clu2adv and adv2v2 commands by removing the limitation that num_shards
must be a numeric literal.
- Enables processing of variable
num_shards
values usingfor
expressions and dynamic block conversion - Introduces new test cases for dynamic blocks and variable
num_shards
scenarios - Refactors shared logic into
shared.go
for better code organization
Reviewed Changes
Copilot reviewed 24 out of 28 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
internal/hcl/hcl.go | Removes error prefix from GetAttrString function and adds TokensFuncConcat utility |
internal/convert/shared.go | New file containing shared helper functions for dynamic block processing |
internal/convert/clu2adv.go | Updates to use shared functions and support variable num_shards |
internal/convert/adv2v2.go | Adds dynamic block validation and variable num_shards support |
test files | Adds comprehensive test cases for dynamic blocks and variable num_shards scenarios |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@@ -120,7 +120,6 @@ dynamic "replication_specs" { | |||
|
|||
### Limitations | |||
|
|||
- [`num_shards`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/cluster#num_shards-2) in `replication_specs` must be a numeric [literal expression](https://developer.hashicorp.com/nomad/docs/job-specification/hcl2/expressions#literal-expressions), e.g. `var.num_shards` is not supported. This is to allow creating a `replication_specs` element per shard in `mongodbatlas_advanced_cluster`. This limitation doesn't apply if you're using `dynamic` blocks in `regions_config` or `replication_specs`. |
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!
internal/convert/shared.go
Outdated
|
||
// processNumShards handles num_shards for a block, returning tokens for the expanded specs. | ||
// processedBody is the body with num_shards removed and other processing done. | ||
func processNumShards(shardsAttr *hclwrite.Attribute, processedBody *hclwrite.Body) hclwrite.Tokens { |
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.
q: This functions is already assuming numShards is defined dynamically right? Potentially we can make explicit by renaming to processNumShardsWithForEach
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, changing better to processNumShardsWhenSomeIsVariable here: 308d00b
internal/convert/testdata/adv2v2/dynamic_replication_specs_different_var_name.in.tf
Show resolved
Hide resolved
project_id = var.project_id | ||
name = "geo" | ||
cluster_type = "GEOSHARDED" | ||
replication_specs = concat( |
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.
Wow!
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.
Wow. Well done 👏
Description
Support dynamic blocks in adv2v2 command
num_shards
out of dynamic blocks in both clu2adv and adv2v2 commands. (This makes the code more complex as there are multiple use cases depending on the number of replication_specs and if they use a mix of variable and numerical num_shards, see Terraform in and out test files for more info).Link to any related issue(s): CLOUDP-339840
Type of change:
Required Checklist:
Further comments