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

Fix mongodb role that constantly update at each Update #536

Merged
merged 6 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
stop trim admin db in mongodb role and force user to alway input auth…
… db for consistency
  • Loading branch information
lpatte committed Jan 15, 2024
commit 3b0f9aabafd79b081e6468ba0c4b0942d5fe657c
10 changes: 9 additions & 1 deletion ovh/resource_cloud_project_database_mongodb_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/url"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -63,10 +64,17 @@ func resourceCloudProjectDatabaseMongodbUser() *schema.Resource {
},
"roles": {
Type: schema.TypeSet,
Description: "Roles the user belongs to (without authentication database)",
Description: "Roles the user belongs to with the authentication database",
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of this error, couldn't you manually add the @admin part to the role when it is not present ? This way we would avoid the breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

I think for this one we won't be able to dodge the breaking change.
We should not imply the @admin for the customer as it determine on which database the user have rights. For this reason we would prefer customer to be fully aware of the value it will be set to.

value := v.(string)
if !strings.Contains(value, "@") {
errors = append(errors, fmt.Errorf("Value %s do not have authentication database", value))
}
return
},
},
},

Expand Down
3 changes: 0 additions & 3 deletions ovh/types_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,6 @@ func (v CloudProjectDatabaseMongodbUserResponse) ToMap() map[string]interface{}
obj["id"] = v.Id
obj["name"] = v.Username
obj["status"] = v.Status
for i := range v.Roles {
v.Roles[i] = strings.TrimSuffix(v.Roles[i], "@admin")
}
obj["roles"] = v.Roles

return obj
Expand Down