Add check to read func and check for resource existence
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/jfrog/terraform-provider-shared/packer"
"github.com/jfrog/terraform-provider-shared/predicate"
+ "net/http"
"regexp"
"strings"
"time"
@@ -239,12 +240,16 @@ func ResourceArtifactoryScopedToken() *schema.Resource {
var accessTokenRead = func(_ context.Context, data *schema.ResourceData, m interface{}) diag.Diagnostics {
accessToken := AccessTokenGet{}
- _, err := m.(*resty.Client).R().
+ resp, err := m.(*resty.Client).R().
SetPathParam("id", data.Id()).
SetResult(&accessToken).
Get("access/api/v1/tokens/{id}")
if err != nil {
+ if resp != nil && resp.StatusCode() == http.StatusNotFound {
+ data.SetId("")
+ return nil
+ }
return diag.FromErr(err)
}
