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: Upgrades federated_settings_org_config to latest SDK. #2244

Merged
merged 4 commits into from
May 7, 2024

Conversation

marcosuma
Copy link
Collaborator

@marcosuma marcosuma commented May 7, 2024

Description

Please include a summary of the fix/feature/change, including any relevant motivation and context.

Link to any related issue(s):

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 defined an isolated PR with a relevant title as it will be used in the auto-generated changelog.
  • 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

Sorry, something went wrong.

@marcosuma marcosuma changed the title chorse: Upgrades federated_settings_org_config to latest SDK. chore: Upgrades federated_settings_org_config to latest SDK. May 7, 2024
@marcosuma
Copy link
Collaborator Author

TestAccFederatedSettingsOrg_basic manually verified and succeeded.

@marcosuma marcosuma marked this pull request as ready for review May 7, 2024 12:24
@marcosuma marcosuma requested a review from a team as a code owner May 7, 2024 12:24
@@ -60,7 +60,7 @@ func Resource() *schema.Resource {

func resourceMongoDBAtlasFederatedSettingsOrganizationConfigRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
// Get client connection.
conn := meta.(*config.MongoDBClient).Atlas
conn := meta.(*config.MongoDBClient).AtlasV2

if d.Id() == "" {
d.SetId("")
Copy link
Member

Choose a reason for hiding this comment

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

isn't this SetId redundant after entering the if statement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

short answer: Not sure why, but it's beyond the scope of the PR which would be better to keep them focused to single topic.

long answer: might be trivial to remove but I am not sure if there's any weird difference behind it. Looking at the code:

// SetId sets the ID of the resource. If the value is blank, then the
// resource is destroyed.
func (d *ResourceData) SetId(v string) {
	d.once.Do(d.init)
	d.newState.ID = v

	// once we transition away from the legacy state types, "id" will no longer
	// be a special field, and will become a normal attribute.
	// set the attribute normally
	d.setWriter.unsafeWriteField("id", v)

	// Make sure the newState is also set, otherwise the old value
	// may get precedence.
	if d.newState.Attributes == nil {
		d.newState.Attributes = map[string]string{}
	}
	d.newState.Attributes["id"] = v
}


// Id returns the ID of the resource.
func (d *ResourceData) Id() string {
	var result string

	if d.state != nil {
		result = d.state.ID
		if result == "" {
			result = d.state.Attributes["id"]
		}
	}

	if d.newState != nil {
		result = d.newState.ID
		if result == "" {
			result = d.newState.Attributes["id"]
		}
	}

	return result
}

Without solid testing, it's an unnecessary risk the one of removing this statement (and, as I said, not related to the title of this PR).

Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't be afraid of changing any code as this perpetuates code that nobody knows why it is there, but agree that that we need to have good tests as a safety net.
agreed it doesn't belong strictly to this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are two similar cases in the code base where there is an if d.Id() == "" {d.setId("")} - we should figure why this is done and make sure there are tests around it before changing it. @lantoli do you want to create a Jira issue for that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually let me just create that Jira issue, thank you for calling that out.

Copy link
Member

Choose a reason for hiding this comment

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

thanks

federation_settings_id = %[1]q
org_id = %[2]q
domain_restriction_enabled = false
domain_allow_list = ["mydomain.com"]
Copy link
Member

Choose a reason for hiding this comment

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

seeing this test data change it looks like we're not checking that param in the tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch @lantoli! Took two actions:

  1. restored to original values (I was making some tests initially because it wasn't working).
  2. Added more test checks to cover the other attributes.
    Let me know if this works for you.

…_settings_connected_org.go

Co-authored-by: Leo Antoli <430982+lantoli@users.noreply.github.com>
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.

LGTM. Thank you :D

marcosuma added 2 commits May 7, 2024 15:36
Copy link
Collaborator

@maastha maastha left a comment

Choose a reason for hiding this comment

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

LGTM

@marcosuma marcosuma merged commit 948a7f6 into master May 7, 2024
32 checks passed
@marcosuma marcosuma deleted the CLOUDP-246323-federated_settings_org_config branch May 7, 2024 14:30
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.

None yet

5 participants