Skip to content

Commit

Permalink
Merge pull request #204 from JupiterOne/APP-15334-ability-to-recreate…
Browse files Browse the repository at this point in the history
…-question

APP-15334: Ability to re-create question if it was deleted
  • Loading branch information
bjoepfeiffer authored May 23, 2024
2 parents f5435c8 + b12ef9d commit 15dbcfd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ introspection_result.json
schema.json
schema.graphql

# Terrform lock files from testing
.terraform.lock.hcl
12 changes: 10 additions & 2 deletions jupiterone/resource_question.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jupiterone
import (
"context"
"fmt"
"strings"

"github.com/Khan/genqlient/graphql"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
Expand Down Expand Up @@ -262,8 +263,15 @@ func (r *QuestionResource) Read(ctx context.Context, req resource.ReadRequest, r

q, err := client.GetQuestionById(ctx, r.qlient, data.Id.ValueString())
if err != nil {
resp.Diagnostics.AddError("failed to get question", err.Error())
return
// If the error is a not found error, we should remove the resource so it can be recreated
if strings.Contains(err.Error(), "does not exist") {
resp.State.RemoveResource(ctx)
return
} else {
resp.Diagnostics.AddError("failed to get question", err.Error())
return
}

}

data.Title = types.StringValue(q.Question.Title)
Expand Down

0 comments on commit 15dbcfd

Please sign in to comment.