From 03731b8617d3e3729a30ef42cb296d25a76d04d2 Mon Sep 17 00:00:00 2001 From: Jordan Caussat Date: Thu, 5 Apr 2018 11:48:55 +0200 Subject: [PATCH 1/2] TER-258: Remove app from state if not found --- ghost/resource_ghost_app.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ghost/resource_ghost_app.go b/ghost/resource_ghost_app.go index cbb551e..423c403 100644 --- a/ghost/resource_ghost_app.go +++ b/ghost/resource_ghost_app.go @@ -502,7 +502,11 @@ func resourceGhostAppRead(d *schema.ResourceData, meta interface{}) error { app, err := client.GetApp(d.Id()) if err != nil { - d.SetId("") + // If app was not found, return nil to show that app is gone + if err.Error()[len(err.Error())-3:] == "404" { + d.SetId("") + return nil + } return fmt.Errorf("[ERROR] error reading Ghost app: %v", err) } From abea5470d1aafe26069ec5c74087b71f181bda7f Mon Sep 17 00:00:00 2001 From: Jordan Caussat Date: Fri, 6 Apr 2018 10:45:03 +0200 Subject: [PATCH 2/2] TER-258: Log when removing app from state --- ghost/resource_ghost_app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ghost/resource_ghost_app.go b/ghost/resource_ghost_app.go index 423c403..a49da64 100644 --- a/ghost/resource_ghost_app.go +++ b/ghost/resource_ghost_app.go @@ -505,6 +505,7 @@ func resourceGhostAppRead(d *schema.ResourceData, meta interface{}) error { // If app was not found, return nil to show that app is gone if err.Error()[len(err.Error())-3:] == "404" { d.SetId("") + log.Printf("[WARN] Ghost app (%s) not found, removing from state", d.Id()) return nil } return fmt.Errorf("[ERROR] error reading Ghost app: %v", err)