Skip to content

chore: Adds import checks to tests #3039

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

Merged
merged 7 commits into from
Feb 7, 2025
Merged

Conversation

EspenAlbert
Copy link
Collaborator

Description

Adds import checks to tests

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

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

@@ -53,6 +53,7 @@ var (
func TestStepImportCluster(resourceName string, ignorePrefixFields ...string) resource.TestStep {
ignorePrefixFields = append(ignorePrefixFields,
"retain_backups_enabled", // This field is TF specific and not returned by Atlas, so Import can't fill it in.
"mongo_db_major_version", // Risks plan change of 8 --> 8.0 (always normalized to `major.minor`)
Copy link
Collaborator Author

@EspenAlbert EspenAlbert Feb 6, 2025

Choose a reason for hiding this comment

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

Could potentially use a custom type to avoid plan changes, but seems overkill.
Both the apply for retain_backups_enabled and mongo_db_major_version are instant

Copy link
Member

@lantoli lantoli Feb 7, 2025

Choose a reason for hiding this comment

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

although it's instant, I think it can be confusing for the user to see these plan changes, and think for example that cluster version will change and could lose data / affect cluster config.

we might do something like in Move/Upgrade setOptionalModelAttrs :

	if mongoDBMajorVersion := getAttrFromStateObj[string](stateObj, "mongo_db_major_version"); mongoDBMajorVersion != nil {
		model.MongoDBMajorVersion = types.StringPointerValue(mongoDBMajorVersion)
	}

in Import we don't have previous state but we can get from Atlas.
Or if we shouldn't call Atlas from Import, then we can set a dummy value in mongo_db_major_version so it's not null and the good value will be set in Read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Interesting approach. But I don't see how this will solve the problem.
The problem is the support of two different formats in the config:

  1. 8
  2. 8.0
    We cannot know at import time which format they used, so we use what is returned by the API (8.0)

Copy link
Member

@lantoli lantoli Feb 7, 2025

Choose a reason for hiding this comment

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

ah, ok, the problem is only when the user specifies mongo_db_major_version in the config? there are no plan changes if mongo_db_major_version is not in the config?

in that case ok to leave it as it is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly 👍

Copy link
Member

Choose a reason for hiding this comment

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

I'm good then, thanks!

@@ -965,6 +984,7 @@ func TestAccAdvancedCluster_replicaSetScalingStrategyAndRedactClientLogDataOldSc
Config: configReplicaSetScalingStrategyAndRedactClientLogDataOldSchema(t, true, orgID, projectName, clusterName, "NODE_TYPE", false),
Check: checkReplicaSetScalingStrategyAndRedactClientLogData(true, "NODE_TYPE", false),
},
acc.TestStepImportCluster(resourceName, "replication_specs"), // Import with old schema will NOT use `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.

Example of explicit replication_specs ignore when the old sharding configuration is used

Copy link
Member

Choose a reason for hiding this comment

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

nice to add an explanation

@@ -151,7 +151,7 @@ func getTimeoutFromStateObj(stateObj map[string]tftypes.Value) timeouts.Value {
return timeouts.Value{Object: obj}
}

func setOptionalModelAttrs(ctx context.Context, stateObj map[string]tftypes.Value, model *TFModel) {
func setOptionalModelAttrs(stateObj map[string]tftypes.Value, model *TFModel) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

opportunistic removal of unused param

@EspenAlbert
Copy link
Collaborator Author

EspenAlbert commented Feb 6, 2025

Ran all tests for TPF locally (a few failures due to replication_specs and mongo_db_major_version, fix in 12ef64d

Running for SDKv2 here. A few failures.
Fixes in 17835c9 and aafc86a

@EspenAlbert EspenAlbert marked this pull request as ready for review February 7, 2025 07:14
@EspenAlbert EspenAlbert requested a review from a team as a code owner February 7, 2025 07:14
@@ -166,6 +166,7 @@ func TestAccMockableAdvancedCluster_tenantUpgrade(t *testing.T) {
Config: acc.ConvertAdvancedClusterToSchemaV2(t, true, configTenantUpgraded(projectID, clusterName, defaultZoneName)),
Check: checksTenantUpgraded(projectID, clusterName),
},
acc.TestStepImportCluster(resourceName),
Copy link
Member

Choose a reason for hiding this comment

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

nice to add more test checks/steps

@EspenAlbert EspenAlbert merged commit cfbf75b into master Feb 7, 2025
44 checks passed
@EspenAlbert EspenAlbert deleted the CLOUDP-298071_check_import branch February 7, 2025 14:00
lantoli added a commit that referenced this pull request Feb 12, 2025
* master:
  doc: Renames env var to `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER` (#3062)
  chore: Updates Atlas Go SDK (#3053)
  test: Tenant clusters with disk_size_gb is always 5 now (#3057)
  chore: Updates CHANGELOG.md for #3051
  fix: Removes `interval_min` plan modifier to avoid error on update (#3051)
  build(deps): bump go.mongodb.org/atlas-sdk (#3049)
  doc: Adds pinned_fcv.version as exported attribute in cluster and advanced cluster resource (#3047)
  update Go to 1.23.6 (#3045)
  chore: Adds HTTP status check helper methods (#3035)
  chore: Adds import checks to tests (#3039)
  chore: Updates CHANGELOG.md header for v1.26.1 release
  chore: Updates examples link in index.md for v1.26.1 release
  fix: Adds "state_name" to keepUnknown list to prevent copying volatile attributes from state (#3040)
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.

2 participants