@@ -3,6 +3,7 @@ package incapsula
33import (
44 "fmt"
55 "log"
6+ "strconv"
67 "testing"
78
89 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -116,6 +117,16 @@ func testAccCheckIncapsulaDeliveryRuleDestroy(state *terraform.State) error {
116117 }
117118
118119 siteID , ok := res .Primary .Attributes ["site_id" ]
120+ if siteID == "" {
121+ // There is a bug in Terraform: https://github.com/hashicorp/terraform/issues/23635
122+ // Specifically, upgrades/destroys are happening simulatneously and not honoroing
123+ // dependencies. In this case, it's possible that the site has already been deleted,
124+ // which means that all of the subresources will have been cleared out.
125+ // Ordinarily, this should return an error, but until this gets addressed, we're
126+ // going to simply return nil.
127+ // return fmt.Errorf("Incapsula site ID does not exist")
128+ return nil
129+ }
119130 if ! ok {
120131 return fmt .Errorf ("Incapsula Site ID does not exist" )
121132 }
@@ -126,6 +137,17 @@ func testAccCheckIncapsulaDeliveryRuleDestroy(state *terraform.State) error {
126137
127138 deliveryRulesListDTO , diags := client .ReadDeliveryRuleConfiguration (siteID , category )
128139
140+ // If the site has already been deleted then return nil
141+ // Otherwise check the delivery rules list
142+ siteIdInt , err := strconv .Atoi (siteID )
143+ if err != nil {
144+ return fmt .Errorf ("Couldn't parse site ID: %s " , siteID )
145+ }
146+ _ , siteStatusErr := client .SiteStatus (domain , siteIdInt )
147+ if siteStatusErr != nil {
148+ return nil
149+ }
150+
129151 if diags != nil {
130152 log .Printf ("[ERROR] Failed to read delivery rules in category %s for Site ID %s" , category , siteID )
131153 return fmt .Errorf ("failed to read delivery rules in category %s for Site ID %s\" " , category , siteID )
0 commit comments