Skip to content

Commit

Permalink
Set the username when resetting the elastic password (#752)
Browse files Browse the repository at this point in the history
* Set the username when resetting the elastic password

* Changelog
  • Loading branch information
tobio authored Dec 6, 2023
1 parent 0f0fec8 commit a221e4e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/752.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/deployment: Update the elasticsearch_username when resetting the password.
```
1 change: 1 addition & 0 deletions ec/acc/deployment_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestAccDeployment_basic_tf(t *testing.T) {
ExpectNonEmptyPlan: true, // reset_elasticsearch_password will always result in a non-empty plan
Check: checkBasicDeploymentResource(resName, randomName, deploymentVersion,
resource.TestCheckResourceAttr(resName, "traffic_filter.#", "0"),
resource.TestCheckResourceAttr(resName, "elasticsearch_username", "elastic"),
func(s *terraform.State) error {
currentPw, ok := captureElasticsearchPassword(s, resName)
if !ok {
Expand Down
9 changes: 5 additions & 4 deletions ec/ecresource/deploymentresource/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,19 @@ func (r *Resource) Update(ctx context.Context, req resource.UpdateRequest, resp
}

if plan.ResetElasticsearchPassword.ValueBool() {
newPassword, diags := r.ResetElasticsearchPassword(plan.Id.ValueString(), *deployment.Elasticsearch.RefId)
newUsername, newPassword, diags := r.ResetElasticsearchPassword(plan.Id.ValueString(), *deployment.Elasticsearch.RefId)
if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() {
return
}

deployment.ElasticsearchUsername = newUsername
deployment.ElasticsearchPassword = newPassword
}

resp.Diagnostics.Append(resp.State.Set(ctx, deployment)...)
}

func (r *Resource) ResetElasticsearchPassword(deploymentID string, refID string) (string, diag.Diagnostics) {
func (r *Resource) ResetElasticsearchPassword(deploymentID string, refID string) (string, string, diag.Diagnostics) {
var diags diag.Diagnostics

resetResp, err := depresourceapi.ResetElasticsearchPassword(depresourceapi.ResetElasticsearchPasswordParams{
Expand All @@ -116,10 +117,10 @@ func (r *Resource) ResetElasticsearchPassword(deploymentID string, refID string)

if err != nil {
diags.AddError("failed to reset elasticsearch password", err.Error())
return "", diags
return "", "", diags
}

return *resetResp.Password, diags
return *resetResp.Username, *resetResp.Password, diags
}

func HandleTrafficFilterChange(ctx context.Context, client *api.API, plan v2.DeploymentTF, stateRules ruleSet) ([]string, diag.Diagnostics) {
Expand Down

0 comments on commit a221e4e

Please sign in to comment.