Skip to content

Commit

Permalink
Set the username when resetting the elastic password
Browse files Browse the repository at this point in the history
  • Loading branch information
tobio committed Dec 6, 2023
1 parent 0f0fec8 commit c537f11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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 c537f11

Please sign in to comment.