Skip to content

Commit

Permalink
Fix guard against funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Jun 20, 2023
1 parent 993ea3d commit 72a013e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
16 changes: 15 additions & 1 deletion internal/auth0/organization/resource_connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,25 @@ func guardAgainstErasingUnwantedConnections(
return nil
}

alreadyEnabledConnectionsIDs := make([]string, 0)
for _, conn := range alreadyEnabledConnections {
alreadyEnabledConnectionsIDs = append(alreadyEnabledConnectionsIDs, conn.GetConnectionID())
}

connectionIDsToAdd := make([]string, 0)
for _, conn := range connectionsToAdd {
connectionIDsToAdd = append(connectionIDsToAdd, conn.GetConnectionID())
}

if cmp.Equal(connectionIDsToAdd, alreadyEnabledConnectionsIDs) {
return nil
}

return diag.Diagnostics{
diag.Diagnostic{
Severity: diag.Error,
Summary: "Organization with non empty enabled connections",
Detail: cmp.Diff(connectionsToAdd, alreadyEnabledConnections) +
Detail: cmp.Diff(connectionIDsToAdd, alreadyEnabledConnectionsIDs) +
fmt.Sprintf("\nThe organization already has enabled connections attached to it. "+
"Import the resource instead in order to proceed with the changes. "+
"Run: 'terraform import auth0_organization_connections.<given-name> %s'.", organizationID),
Expand Down
13 changes: 11 additions & 2 deletions internal/auth0/organization/resource_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,26 @@ func deleteOrganizationMembers(_ context.Context, data *schema.ResourceData, met
func guardAgainstErasingUnwantedMembers(
organizationID string,
alreadyMembers []management.OrganizationMember,
membersToAdd []string,
memberIDsToAdd []string,
) diag.Diagnostics {
if len(alreadyMembers) == 0 {
return nil
}

alreadyMemberIDs := make([]string, 0)
for _, member := range alreadyMembers {
alreadyMemberIDs = append(alreadyMemberIDs, member.GetUserID())
}

if cmp.Equal(memberIDsToAdd, alreadyMemberIDs) {
return nil
}

return diag.Diagnostics{
diag.Diagnostic{
Severity: diag.Error,
Summary: "Organization with non empty members",
Detail: cmp.Diff(membersToAdd, alreadyMembers) +
Detail: cmp.Diff(memberIDsToAdd, alreadyMemberIDs) +
fmt.Sprintf("\nThe organization already has members attached to it. "+
"Import the resource instead in order to proceed with the changes. "+
"Run: 'terraform import auth0_organization_members.<given-name> %s'.", organizationID),
Expand Down

0 comments on commit 72a013e

Please sign in to comment.