Skip to content

Commit 3bbf4fe

Browse files
Delete gracefully if user no longer exist in grafana (#991)
When applying a terraform plan that was created with `-refresh=false` the detection of resources that no longer exist in grafana does not work, as the resources are not read at all. Thus on apply, a deletion of a user that no longer exists in grafana fails with: ``` Error: status: 404, body: {"message":"user not found"} ``` This change modifies `DeleteUser` so that it catches this case and does not return an error.
1 parent 1d42628 commit 3bbf4fe

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

internal/resources/grafana/resource_user.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package grafana
33
import (
44
"context"
55
"strconv"
6+
"strings"
67

78
gapi "github.com/grafana/grafana-api-golang-client"
89
"github.com/grafana/terraform-provider-grafana/internal/common"
@@ -145,7 +146,9 @@ func DeleteUser(ctx context.Context, d *schema.ResourceData, meta interface{}) d
145146
return diag.FromErr(err)
146147
}
147148
if err = client.DeleteUser(id); err != nil {
148-
return diag.FromErr(err)
149+
if !strings.Contains(err.Error(), common.NotFoundError) {
150+
return diag.FromErr(err)
151+
}
149152
}
150153

151154
return diag.Diagnostics{}

0 commit comments

Comments
 (0)