From 035a87b87a3c50c99361204f3c1c555d46f6ba58 Mon Sep 17 00:00:00 2001 From: hvtonev <41945933+hvtonev@users.noreply.github.com> Date: Wed, 3 Jan 2024 11:34:14 +0200 Subject: [PATCH] remove: mTLS from state if API returns 404 (#794) * 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 Co-authored-by: Mark McDonnell --- .../resource_fastly_tls_mutual_authentication.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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) }