From eb1807eac643e03ac1d4db32d479220beb810617 Mon Sep 17 00:00:00 2001 From: kavya498 Date: Wed, 19 May 2021 14:32:02 +0530 Subject: [PATCH] Fix: Remove resource from statefile for pending_reclamation state --- ibm/resource_ibm_cis.go | 4 ++-- ibm/resource_ibm_database.go | 4 ++-- ibm/resource_ibm_resource_instance.go | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ibm/resource_ibm_cis.go b/ibm/resource_ibm_cis.go index 996d5f368f..c7a37b0d86 100644 --- a/ibm/resource_ibm_cis.go +++ b/ibm/resource_ibm_cis.go @@ -437,8 +437,8 @@ func resourceIBMCISInstanceExists(d *schema.ResourceData, meta interface{}) (boo } return false, fmt.Errorf("Error communicating with the API: %s %s", err, response) } - if strings.Contains(*instance.State, "removed") { - log.Printf("[WARN] Removing instance from state because it's in removed state") + if instance != nil && (strings.Contains(*instance.State, "removed") || strings.Contains(*instance.State, cisInstanceReclamation)) { + log.Printf("[WARN] Removing instance from state because it's in removed or pending_reclamation state") d.SetId("") return false, nil } diff --git a/ibm/resource_ibm_database.go b/ibm/resource_ibm_database.go index 438aea79cc..e35ab7424e 100644 --- a/ibm/resource_ibm_database.go +++ b/ibm/resource_ibm_database.go @@ -1818,8 +1818,8 @@ func resourceIBMDatabaseInstanceExists(d *schema.ResourceData, meta interface{}) } return false, fmt.Errorf("Error communicating with the API: %s %s", err, response) } - if strings.Contains(*instance.State, "removed") { - log.Printf("[WARN] Removing instance from state because it's in removed state") + if instance != nil && (strings.Contains(*instance.State, "removed") || strings.Contains(*instance.State, databaseInstanceReclamation)) { + log.Printf("[WARN] Removing instance from state because it's in removed or pending_reclamation state") d.SetId("") return false, nil } diff --git a/ibm/resource_ibm_resource_instance.go b/ibm/resource_ibm_resource_instance.go index e7eed1e2c8..8e7a36d85d 100644 --- a/ibm/resource_ibm_resource_instance.go +++ b/ibm/resource_ibm_resource_instance.go @@ -758,6 +758,11 @@ func resourceIBMResourceInstanceExists(d *schema.ResourceData, meta interface{}) } return false, fmt.Errorf("Error communicating with the API: %s with resp code: %s", err, resp) } + if instance != nil && (strings.Contains(*instance.State, "removed") || strings.Contains(*instance.State, rsInstanceReclamation)) { + log.Printf("[WARN] Removing instance from state because it's in removed or pending_reclamation state") + d.SetId("") + return false, nil + } return *instance.ID == instanceID, nil }