Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mTLS from state that returns 404 #794

Merged
merged 9 commits into from
Jan 3, 2024
15 changes: 15 additions & 0 deletions fastly/resource_fastly_tls_mutual_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down