Skip to content

Commit

Permalink
fix: unexpected topic state change and acceptance test (IBM-Cloud#5620)
Browse files Browse the repository at this point in the history
* fix: unexpected state change for topic

* fix: replace deprecated rc v1 API in instance check
  • Loading branch information
JunliWang authored Sep 9, 2024
1 parent 6228bfc commit 4fc8775
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 2 additions & 0 deletions ibm/service/eventstreams/resource_ibm_event_streams_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log"
"os"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -288,6 +289,7 @@ func createSaramaAdminClient(d *schema.ResourceData, meta interface{}) (sarama.C
d.Set("kafka_http_url", adminURL)
log.Printf("[INFO] createSaramaAdminClient kafka_http_url is set to %s", adminURL)
brokerAddress := flex.ExpandStringList(instance.Extensions["kafka_brokers_sasl"].([]interface{}))
slices.Sort(brokerAddress)
d.Set("kafka_brokers_sasl", brokerAddress)
log.Printf("[INFO] createSaramaAdminClient kafka_brokers_sasl is set to %s", brokerAddress)
tenantID := strings.TrimPrefix(strings.Split(adminURL, ".")[0], "https://")
Expand Down
21 changes: 11 additions & 10 deletions ibm/service/eventstreams/resource_ibm_event_streams_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func createEventStreamsTopicResourceWithConfig(createInstance bool, topicName st
}

func testAccCheckIBMEventStreamsInstanceDestroy(s *terraform.State) error {
rsContClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).ResourceControllerAPI()
rsContClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).ResourceControllerAPIV2()
if err != nil {
return err
}
Expand All @@ -311,16 +311,17 @@ func testAccCheckIBMEventStreamsInstanceDestroy(s *terraform.State) error {
continue
}
instanceID := rs.Primary.ID
instance, err := rsContClient.ResourceServiceInstance().GetInstance(instanceID)

if err == nil {
if !reflect.DeepEqual(instance, models.ServiceInstance{}) && instance.State == "active" {
return fmt.Errorf("Instance still exists: %s", rs.Primary.ID)
}
} else {
if !strings.Contains(err.Error(), "404") {
return fmt.Errorf("[ERROR] Error checking if instance (%s) has been destroyed: %s", rs.Primary.ID, err)
instance, err := rsContClient.ResourceServiceInstanceV2().GetInstance(instanceID)
if err != nil {
if strings.Contains(err.Error(), "404") {
return nil
}
return fmt.Errorf("[ERROR] Error checking if instance (%s) has been destroyed: %s", rs.Primary.ID, err)
}

if !reflect.DeepEqual(instance, models.ServiceInstanceV2{}) &&
instance.State != "removed" && instance.State != "pending_reclamation" {
return fmt.Errorf("[ERROR] Instance (%s) is not removed", rs.Primary.ID)
}
}
return nil
Expand Down

0 comments on commit 4fc8775

Please sign in to comment.