-
Notifications
You must be signed in to change notification settings - Fork 178
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: Avoids sending database user password in update request if the value has not changed #2005
Changes from 3 commits
2741f70
6a0b414
b01d5d1
a93ffea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,7 +212,7 @@ func (r *databaseUserRS) Create(ctx context.Context, req resource.CreateRequest, | |
return | ||
} | ||
|
||
dbUserReq, d := NewMongoDBDatabaseUser(ctx, databaseUserPlan) | ||
dbUserReq, d := NewMongoDBDatabaseUser(ctx, types.StringNull(), databaseUserPlan) | ||
resp.Diagnostics.Append(d...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
|
@@ -231,6 +231,8 @@ func (r *databaseUserRS) Create(ctx context.Context, req resource.CreateRequest, | |
return | ||
} | ||
|
||
resp.Diagnostics.AddWarning("If the password value will be managed externally it is advised to remove the attribute", "More details can be found in resource documentation under the 'password' attribute") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this warning shown always or it has some condition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will always be shown, not really any particular condition we can use because password will always be defined for create operation (fails in API otherwise) |
||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &dbUserModel)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
|
@@ -286,14 +288,15 @@ func (r *databaseUserRS) Read(ctx context.Context, req resource.ReadRequest, res | |
|
||
func (r *databaseUserRS) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { | ||
var databaseUserPlan *TfDatabaseUserModel | ||
var databaseUserState *TfDatabaseUserModel | ||
|
||
diags := req.Plan.Get(ctx, &databaseUserPlan) | ||
resp.Diagnostics.Append(diags...) | ||
resp.Diagnostics.Append(req.Plan.Get(ctx, &databaseUserPlan)...) | ||
resp.Diagnostics.Append(req.State.Get(ctx, &databaseUserState)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
dbUserReq, d := NewMongoDBDatabaseUser(ctx, databaseUserPlan) | ||
dbUserReq, d := NewMongoDBDatabaseUser(ctx, databaseUserState.Password, databaseUserPlan) | ||
resp.Diagnostics.Append(d...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ Accepted values include: | |
* `project_id` - (Required) The unique ID for the project to create the database user. | ||
* `roles` - (Required) List of user’s roles and the databases / collections on which the roles apply. A role allows the user to perform particular actions on the specified database. A role on the admin database can include privileges that apply to the other databases as well. See [Roles](#roles) below for more details. | ||
* `username` - (Required) Username for authenticating to MongoDB. USER_ARN or ROLE_ARN if `aws_iam_type` is USER or ROLE. | ||
* `password` - (Required) User's initial password. A value is required to create the database user, however the argument but may be removed from your Terraform configuration after user creation without impacting the user, password or Terraform management. IMPORTANT --- Passwords may show up in Terraform related logs and it will be stored in the Terraform state file as plain-text. Password can be changed after creation using your preferred method, e.g. via the MongoDB Atlas UI, to ensure security. If you do change management of the password to outside of Terraform be sure to remove the argument from the Terraform configuration so it is not inadvertently updated to the original password. | ||
* `password` - (Required) User's initial password. A value is required to create the database user, however the argument may be removed from your Terraform configuration after user creation without impacting the user, password or Terraform management. If you do change management of the password to outside of Terraform it is advised to remove the argument from the Terraform configuration. IMPORTANT --- Passwords may show up in Terraform related logs and it will be stored in the Terraform state file as plain-text. Password can be changed after creation using your preferred method, e.g. via the MongoDB Atlas UI, to ensure security. | ||
Comment on lines
134
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a warning at the top of this page to make sure that this warning message is not missed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense, included. |
||
|
||
* `x509_type` - (Optional) X.509 method by which the provided username is authenticated. If no value is given, Atlas uses the default value of NONE. The accepted types are: | ||
* `NONE` - The user does not use X.509 authentication. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess this also covers if the password attribute is deleted, then we set nil so it's not sent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, added an additional unit test to cover this case as well, thanks