diff --git a/.gitignore b/.gitignore index 6d97d4bc..5231da26 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ introspection_result.json schema.json schema.graphql +# Terrform lock files from testing +.terraform.lock.hcl \ No newline at end of file diff --git a/jupiterone/resource_question.go b/jupiterone/resource_question.go index 8f03c07e..ec6adbf9 100644 --- a/jupiterone/resource_question.go +++ b/jupiterone/resource_question.go @@ -3,6 +3,7 @@ package jupiterone import ( "context" "fmt" + "strings" "github.com/Khan/genqlient/graphql" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" @@ -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)