Skip to content

Conversation

@AgustinBettati
Copy link
Member

@AgustinBettati AgustinBettati commented Jan 15, 2025

Description

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

Recap of changes made in PR:

  • Adapt pinned fcv test defined in advancedcluster to also run with advancedclustertpf implementation.
  • Implement pinned fcv in advancedclustertpf extracting common logic where possible, specifically pinning logic and generation of warning messages.

Known TPF vs SDK v2 differences:

  • pinned_fcv is defined as a single nested attribute, which makes accessing the attribute different (pinned_fcv[0].version vs pinned_fcv.version) as well as its null value ([] vs null).

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

sdkv2diag "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)

func FromTPFDiagsToSDKV2Diags(diagsTpf []diag.Diagnostic) sdkv2diag.Diagnostics {
Copy link
Member

Choose a reason for hiding this comment

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

i like the idea of this type of funcs to transform from TFP responses back to SDKv2 (and the opposite for request attrs)

return modelOut
}

func (r *rs) applyPinnedFCVChanges(ctx context.Context, diags *diag.Diagnostics, state, plan *TFModel) *admin.ClusterDescription20240805 {
Copy link
Member

Choose a reason for hiding this comment

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

i guess this main flow logic can't be made common

Copy link
Member Author

Choose a reason for hiding this comment

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

correct, I think if we want to extract further we would have to start thinking of a common model that is agnostic of either TFModel (tpf) or ResourceData (sdk)

return ""
}

func PinFCV(ctx context.Context, api admin.ClustersApi, projectID, clusterName, expirationDateStr string) error {
Copy link
Member

Choose a reason for hiding this comment

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

this common logic is great! i guess no more common logic can be extracted at the moment

}

func CheckRSAndDSSchemaV2(isAcc bool, resourceName string, dataSourceName, pluralDataSourceName *string, attrsSet []string, attrsMap map[string]string, extra ...resource.TestCheckFunc) resource.TestCheckFunc {
checks := []resource.TestCheckFunc{}
Copy link
Member

Choose a reason for hiding this comment

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

can CheckRSAndDSSchemaV2 implementation rely on CheckRSAndDS and be in advanced_cluster_schema_v2.go?

e.g.

func CheckRSAndDSSchemaV2(isAcc bool, resourceName string, dataSourceName, pluralDataSourceName *string, attrsSet []string, attrsMap map[string]string, extra ...resource.TestCheckFunc) resource.TestCheckFunc {
	return CheckRSAndDS(resourceName, dataSourceName, pluralDataSourceName, ConvertToSchemaV2AttrsSet(isAcc, attrsSet), ConvertToSchemaV2AttrsMap(isAcc, attrsMap), extra...)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

great suggestion, had not thought of this approach. Adjusted.

}

func configFCVPinning(orgID, projectName, clusterName string, pinningExpirationDate *string, mongoDBMajorVersion string) string {
func configFCVPinning(t *testing.T, isAcc bool, orgID, projectName, clusterName string, pinningExpirationDate *string, mongoDBMajorVersion string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

are we planning a migration test? (why is isAcc introduced)

Copy link
Member Author

Choose a reason for hiding this comment

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

good question, not really, will remove the parameter for now and if we eventually have the need the parameter can be added to the config function.

return resource.ComposeAggregateTestCheckFunc(checks...)
extraChecks := extra
extraChecks = append(extraChecks, acc.CheckExistsCluster(resourceName))
return acc.CheckRSAndDSSchemaV2(isAcc, resourceName, admin.PtrString(dataSourceName), nil, attrsSet, attrsMap, extraChecks...)
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

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.

Good job!

@AgustinBettati AgustinBettati marked this pull request as ready for review January 16, 2025 13:12
@AgustinBettati AgustinBettati requested a review from a team as a code owner January 16, 2025 13:12
@AgustinBettati AgustinBettati merged commit e4a1590 into master Jan 16, 2025
116 of 123 checks passed
@AgustinBettati AgustinBettati deleted the CLOUDP-291160 branch January 16, 2025 16:12
lantoli added a commit that referenced this pull request Jan 16, 2025
* master:
  chore: Bring `pinned_fcv` feature into advanced_cluster TPF implementation (#2970)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants