Skip to content

Commit

Permalink
if resource is not found we should be fine
Browse files Browse the repository at this point in the history
  • Loading branch information
juandspy committed Oct 28, 2022
1 parent 1f477b4 commit 82972f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rhoas/kafka/resource_kafka.go
Expand Up @@ -2,11 +2,13 @@ package kafka

import (
"context"
"net/http"
"strings"
"time"

kafkainstanceclient "github.com/redhat-developer/app-services-sdk-go/kafkainstance/apiv1/client"
"github.com/redhat-developer/terraform-provider-rhoas/rhoas/acl"
"github.com/redhat-developer/terraform-provider-rhoas/rhoas/localize"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -184,6 +186,9 @@ func kafkaDelete(ctx context.Context, d *schema.ResourceData, m interface{}) dia
},
Refresh: func() (interface{}, string, error) {
data, resp, err1 := factory.KafkaMgmt().GetKafkaById(ctx, d.Id()).Execute()
if resp.StatusCode == http.StatusNotFound {
return data, "deleted", nil
}
if apiErr := utils.GetAPIError(factory, resp, err1); apiErr != nil {
return nil, "", apiErr
}
Expand Down
4 changes: 4 additions & 0 deletions rhoas/tests/kafka_test.go
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"context"
"fmt"
"net/http"
"regexp"
"testing"

Expand Down Expand Up @@ -127,6 +128,9 @@ func testAccCheckKafkaDestroy(s *terraform.State) error {

// Retrieve the kafka struct by referencing it's state ID for API lookup
kafka, resp, err := factory.KafkaMgmt().GetKafkaById(context.Background(), rs.Primary.ID).Execute()
if resp.StatusCode == http.StatusNotFound {
return nil
}
if apiErr := utils.GetAPIError(factory, resp, err); apiErr != nil {
return apiErr
}
Expand Down
4 changes: 4 additions & 0 deletions rhoas/tests/serviceaccount_test.go
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"context"
"fmt"
"net/http"
"regexp"
"testing"

Expand Down Expand Up @@ -188,6 +189,9 @@ func testAccCheckServiceAccountDestroy(s *terraform.State) error {

// Retrieve the service account struct by referencing it's state ID for API lookup
serviceAccount, resp, err := factory.ServiceAccountMgmt().GetServiceAccount(context.Background(), rs.Primary.ID).Execute()
if resp.StatusCode == http.StatusNotFound {
return nil
}
if apiErr := utils.GetAPIError(factory, resp, err); apiErr != nil {
return apiErr
}
Expand Down

0 comments on commit 82972f5

Please sign in to comment.