Skip to content

Conversation

lantoli
Copy link
Collaborator

@lantoli lantoli commented Mar 11, 2025

Description

Supports dynamic blocks

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

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

@github-actions github-actions bot added the enhancement New feature or request label Mar 11, 2025
@lantoli lantoli changed the title feat: Supports dynamic blocks feat: Supports dynamic blocks in tags and labels Mar 11, 2025
@lantoli lantoli marked this pull request as ready for review March 17, 2025 07:01
@Copilot Copilot AI review requested due to automatic review settings March 17, 2025 07:01
@lantoli lantoli requested a review from a team as a code owner March 17, 2025 07:01
return nil, fmt.Errorf("dynamic block %s: %s or %s not found", name, nKey, nValue)
}
collectionExpr := strings.TrimSpace(string(d.forEach.Expr().BuildTokens(nil).Bytes()))
keyExpr := strings.TrimSpace(strings.ReplaceAll(string(key.Expr().BuildTokens(nil).Bytes()),
Copy link
Contributor

@EspenAlbert EspenAlbert Mar 17, 2025

Choose a reason for hiding this comment

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

A lot happening on this line. Maybe create an intermediate variable?
Or
Extract this into a function. for example, removeDynamicVarPrefx()

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: 24b5389

}
return nil
}

type dynamicBlock struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice abstraction!

priority = 7
}
}
labels {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow. Quite a big example! Static values and dynamic!!

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.

Well done!

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. Curious how much logic can be used for other attributes in the sense of mapping generic dynamic/for_each/content over to respective for/in/ value of object

Comment on lines +142 to +152
tags {
key = var.tag_key # non-literal values are supported and enclosed in parentheses
value = var.tag_value
}
dynamic "tags" {
for_each = var.tags
content {
key = tags.key
value = replace(tags.value, "/", "_")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nice that we support the possibility of dynamic + literal blocks at the same time

]
}
]
tags = var.tags
Copy link
Contributor

Choose a reason for hiding this comment

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

are we assuming that var.tags is map here? Is there a case where it could be a list?

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 examples I've found are maps, if you find any example of a list, please let me know

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, I believe it will good to keep track of these assumptions mainly for our future reference and transparency for users. Maybe a small note within Dynamic blocks in tags and labels section in the readme file?

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 @AgustinBettati , added in this follow-up PR: #33

@lantoli
Copy link
Collaborator Author

lantoli commented Mar 17, 2025

LGTM. Curious how much logic can be used for other attributes in the sense of mapping generic dynamic/for_each/content over to respective for/in/ value of object

@AgustinBettati I think we'll be able to do some reuse, for example the dynamicBlock struct and surely some funcs

@lantoli lantoli merged commit 3d13e27 into main Mar 17, 2025
7 checks passed
@lantoli lantoli deleted the CLOUDP-303941_dynamic branch March 17, 2025 11:47
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.

3 participants