in internal/elasticsearch/security/system_user.go [73:121]
func resourceSecuritySystemUserPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client, diags := clients.NewApiClientFromSDKResource(d, meta)
if diags.HasError() {
return diags
}
usernameId := d.Get("username").(string)
id, diags := client.ID(ctx, usernameId)
if diags.HasError() {
return diags
}
user, diags := elasticsearch.GetUser(ctx, client, usernameId)
if diags.HasError() {
return diags
}
if user == nil || !user.IsSystemUser() {
return diag.Errorf(`System user "%s" not found`, usernameId)
}
var userPassword models.UserPassword
if v, ok := d.GetOk("password"); ok && d.HasChange("password") {
password := v.(string)
userPassword.Password = &password
}
if v, ok := d.GetOk("password_hash"); ok && d.HasChange("password_hash") {
pass_hash := v.(string)
userPassword.PasswordHash = &pass_hash
}
if userPassword.Password != nil || userPassword.PasswordHash != nil {
if diags := elasticsearch.ChangeUserPassword(ctx, client, usernameId, &userPassword); diags.HasError() {
return diags
}
}
if d.HasChange("enabled") {
if d.Get("enabled").(bool) {
if diags := elasticsearch.EnableUser(ctx, client, usernameId); diags.HasError() {
return diags
}
} else {
if diags := elasticsearch.DisableUser(ctx, client, usernameId); diags.HasError() {
return diags
}
}
}
d.SetId(id.String())
return resourceSecuritySystemUserRead(ctx, d, meta)
}