Skip to content

Commit

Permalink
remove: mTLS from state if API returns 404 (#794)
Browse files Browse the repository at this point in the history
* Remove mTLS from state that returns 404

* Remove mTLS from state that returns 404, fix ifs

* ci: fix ok-to-test (#796)

* ci: fix ok-to-test

* ci: add missing configuration for ok-to-test behaviour

* ci: fix ok-to-test (#796)

* ci: fix ok-to-test

* ci: add missing configuration for ok-to-test behaviour

* ci: fix ok-to-test (#796)

* ci: fix ok-to-test

* ci: add missing configuration for ok-to-test behaviour

---------

Co-authored-by: Hristiyan Tonev <[email protected]>
Co-authored-by: Mark McDonnell <[email protected]>
  • Loading branch information
3 people authored Jan 3, 2024
1 parent 72bb441 commit 035a87b
Showing 1 changed file with 15 additions and 0 deletions.
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

0 comments on commit 035a87b

Please sign in to comment.