diff --git a/fastly/resource_fastly_tls_mutual_authentication.go b/fastly/resource_fastly_tls_mutual_authentication.go index e69708925..76ed59059 100644 --- a/fastly/resource_fastly_tls_mutual_authentication.go +++ b/fastly/resource_fastly_tls_mutual_authentication.go @@ -2,9 +2,12 @@ package fastly import ( "context" + "fmt" "log" "sort" + gofastly "github.com/fastly/go-fastly/v8/fastly" + "github.com/hashicorp/go-cty/cty" "github.com/fastly/go-fastly/v8/fastly" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -104,7 +107,19 @@ func resourceFastlyTLSMutualAuthenticationRead(_ context.Context, d *schema.Reso log.Printf("[DEBUG] REFRESH: TLS Mutual Authentication input: %#v", input) tma, err := conn.GetTLSMutualAuthentication(input) + if err != nil { + if err, ok := err.(*gofastly.HTTPError); ok && err.IsNotFound() { + id := d.Id() + d.SetId("") + return diag.Diagnostics{ + diag.Diagnostic{ + Severity: diag.Warning, + Summary: fmt.Sprintf("TLS Mutual Authentication (%s) not found - removing from state", id), + AttributePath: cty.Path{cty.GetAttrStep{Name: id}}, + }, + } + } return diag.FromErr(err) }