Skip to content
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

chore: Implements tags and labels as MapAttribute in advanced_cluster schema v2 #2996

Merged
merged 16 commits into from
Jan 24, 2025

Conversation

lantoli
Copy link
Member

@lantoli lantoli commented Jan 23, 2025

Description

Implements tags and labels as MapAttribute in advanced_cluster schema v2.

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

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

@lantoli lantoli changed the title chore: Cloudp 295198 tpf tags labels chore: Implements tags and labels as MapAttribute in advanced_cluster schema v2 Jan 23, 2025
* master:
  chore: Updates repository to use supported Terraform versions (#2997)
  chore: Updates CHANGELOG.md header for v1.26.0 release
  chore: Updates examples link in index.md for v1.26.0 release
  doc: Upgrade guide for v1.26.0 (#2992)
* master:
  chore: Extracts out SDK logic from TPF to facilitate reuse in SDKv2 for advanced_cluster (#2982)
  ci: Adds clean-atlas-org action and related tests for project cleanup (#2960)
  chore: Adds MacT documentation (#2993)
@lantoli lantoli marked this pull request as ready for review January 24, 2025 16:24
@lantoli lantoli requested a review from a team as a code owner January 24, 2025 16:24
value := block["value"]
checks = append(checks,
acc.TestCheckResourceAttrSchemaV2(isAcc, resourceName, key, value),
)
Copy link
Member Author

Choose a reason for hiding this comment

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

thanks @EspenAlbert for the tips for checking maps

elms := make(map[string]string)
if input != nil {
for _, item := range *input {
key := conversion.SafeValue(item.Key)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason why we are not using item.GetKey()?

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks changed here: f24f8dc

Value: types.StringValue(item.Value),
func NewTagsObjType(ctx context.Context, diags *diag.Diagnostics, input *[]admin.ResourceTag) types.Map {
elms := make(map[string]string)
if input != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice refactor!

@@ -113,25 +115,26 @@ func resolveZoneNameOrUseDefault(item *TFReplicationSpecsModel) string {
return *zoneName
}

func newResourceTag(ctx context.Context, input types.Set, diags *diag.Diagnostics) *[]admin.ResourceTag {
func newResourceTag(ctx context.Context, diags *diag.Diagnostics, input types.Map) *[]admin.ResourceTag {
if input.IsUnknown() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

input.IsUnknown() can be removed now that it is optional only

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks changed here: f24f8dc

@@ -94,6 +94,11 @@ func setStateResponse(ctx context.Context, diags *diag.Diagnostics, stateIn *tfp
return
}
setOptionalModelAttrs(ctx, stateObj, model)

// Set tags and labels to null instead of empty so there is no plan change if there are no tags or labels when Read is called.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess you had to learn this the hard way? If you do nothing they are set to empty map? {}?

Copy link
Member Author

Choose a reason for hiding this comment

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

ha ha, exactly

if mapIn.IsNull() {
*mapOut = types.MapNull(types.StringType)
} else {
*mapOut = types.MapValueMust(types.StringType, nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice usage of Must

tags = {
"Key Tag 1" = "Value Tag 1"
"Key Tag 2" = "Value Tag 2"
tag = "tagvalue"
Copy link
Collaborator

Choose a reason for hiding this comment

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

cool how it only uses " when necessary

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, i love it

Copy link
Collaborator

@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.

A few minor comments. But looks good!

* master:
  chore: Adds cipher config & default_max_time_ms to advanced_cluster_tpf (#2972)
@lantoli lantoli merged commit 3057211 into master Jan 24, 2025
67 of 68 checks passed
@lantoli lantoli deleted the CLOUDP-295198_tpf_tags_labels branch January 24, 2025 21:07
Comment on lines +25 to +28
overrideMapStringWithPrevStateValue(&modelIn.Labels, &modelOut.Labels)
overrideMapStringWithPrevStateValue(&modelIn.Tags, &modelOut.Tags)
}
func overrideMapStringWithPrevStateValue(mapIn, mapOut *types.Map) {
Copy link
Member

Choose a reason for hiding this comment

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

I see for cases of the empty lists/map we sometimes go for setting nil directly (example) or in cases like this one support defining the empty map in the config. I would assess what is the drawback UX wise if we dont have this logic to avoid relying on previous state is not ideal.

Copy link
Member Author

Choose a reason for hiding this comment

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

discussed offline

oarbusi pushed a commit that referenced this pull request Jan 27, 2025
…uster` schema v2 (#2996)

* schema change

* model change

* create TF models

* create Admin models

* labels & tags conversion

* TEMPORARY skip mocked tests

* handle null vs []

* Revert "TEMPORARY skip mocked tests"

This reverts commit 3653edc.

* temporary don't test check label and tags

* improve update and override

* fix plan changes in state upgrade

* test checks for labels and tags

* apply feedback
lantoli added a commit that referenced this pull request Feb 3, 2025
* master:
  chore: Adds nil check before retrieving httpResponse data from API calls (#3015)
  chore: Run advanced_cluster_tpf tests group only on workflow dispatch (#3016)
  test: Adds a case for finding `DISK_SIZE_GB_INCONSISTENT` error from API and update TPF implementation in advanced_cluster (#3014)
  chore: Bump github.com/hashicorp/terraform-exec from 0.21.0 to 0.22.0 (#3007)
  chore: Bump github.com/hashicorp/terraform-plugin-framework-timeouts (#3009)
  chore: Bump github.com/evanphx/json-patch/v5 from 5.9.0 to 5.9.11 (#3010)
  chore: Bump github.com/zclconf/go-cty from 1.16.1 to 1.16.2 (#3011)
  chore: Uses always new schema when moving from cluster (#3004)
  chore: Implements `tags` and `labels` as MapAttribute in `advanced_cluster` schema v2 (#2996)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants