Skip to content

Commit

Permalink
Removed synchronous deletion as it broke one of the tests (fake-async…
Browse files Browse the repository at this point in the history
…-plan)
  • Loading branch information
janosbinder committed Jun 15, 2018
1 parent e89ac63 commit 5f90fbf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 35 deletions.
8 changes: 0 additions & 8 deletions cloudfoundry/cfapi/service_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,6 @@ func (sm *ServiceManager) DeleteServiceInstance(serviceInstanceID string) (err e

}

// DeleteServiceInstanceSync -
func (sm *ServiceManager) DeleteServiceInstanceSync(serviceInstanceID string) (err error) {

err = sm.ccGateway.DeleteResource(sm.apiEndpoint, fmt.Sprintf("/v2/service_instances/%s", serviceInstanceID))
return err

}

// CreateUserProvidedService -
func (sm *ServiceManager) CreateUserProvidedService(
name string,
Expand Down
38 changes: 14 additions & 24 deletions cloudfoundry/resource_cf_service_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,33 +205,23 @@ func resourceServiceInstanceDelete(d *schema.ResourceData, meta interface{}) (er
if session == nil {
return fmt.Errorf("client is nil")
}
session.Log.DebugMessage("begin resourceServiceInstanceDelete via %s service operation", terminal.EntityNameColor("synchronous"))
session.Log.DebugMessage("begin resourceServiceInstanceDelete")

sm := session.ServiceManager()

if err = sm.DeleteServiceInstanceSync(id); err != nil {
// This logic first tries to delete the service via a synchronous service operation
// If that does not work, it does asynchronous service operation which takes longer due to the constant pooling of the status.
if strings.Contains(err.Error(), "error code: 10001") {
session.Log.DebugMessage("Service Instance : %s does not support deletion via %s service operation", terminal.EntityNameColor(id), terminal.EntityNameColor("synchronous"))
session.Log.DebugMessage("begin resourceServiceInstanceDelete via %s service operation", terminal.EntityNameColor("asynchronous"))
if err = sm.DeleteServiceInstance(id); err != nil {
return err
}
stateConf := &resource.StateChangeConf{
Pending: resourceServiceInstancePendingStates,
Target: resourceServiceInstanceSucceesStates,
Refresh: resourceServiceInstanceStateFunc(id, "delete", meta),
Timeout: d.Timeout(schema.TimeoutDelete),
PollInterval: 5 * time.Second,
}
// Wait, catching any errors
if _, err = stateConf.WaitForState(); err != nil {
return err
}
} else {
return err
}
if err = sm.DeleteServiceInstance(id); err != nil {
return err
}
stateConf := &resource.StateChangeConf{
Pending: resourceServiceInstancePendingStates,
Target: resourceServiceInstanceSucceesStates,
Refresh: resourceServiceInstanceStateFunc(id, "delete", meta),
Timeout: d.Timeout(schema.TimeoutDelete),
PollInterval: 5 * time.Second,
}
// Wait, catching any errors
if _, err = stateConf.WaitForState(); err != nil {
return err
}

session.Log.DebugMessage("Deleted Service Instance : %s", terminal.EntityNameColor(d.Id()))
Expand Down
6 changes: 3 additions & 3 deletions cloudfoundry/resource_cf_service_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ resource "cf_service_broker" "fake-service-broker" {
%s
`

const serviceInstanceResourceAsyncCreateWithFakePlan=`
const serviceInstanceResourceAsyncCreateWithFakePlan = `
resource "cf_service_instance" "fake-service-instance-with-fake-plan" {
name = "fake-service-instance-with-fake-plan"
Expand All @@ -137,7 +137,7 @@ resource "cf_service_instance" "fake-service-instance-with-fake-plan" {
}
`

const serviceInstanceResourceAsyncCreateWithAsyncFakePlan=`
const serviceInstanceResourceAsyncCreateWithAsyncFakePlan = `
resource "cf_service_instance" "fake-service-instance-with-fake-async-plan" {
name = "fake-service-instance-with-fake-async-plan"
space = "${data.cf_space.space.id}"
Expand All @@ -146,7 +146,7 @@ resource "cf_service_instance" "fake-service-instance-with-fake-async-plan" {
}
`

const serviceInstanceResourceAsyncCreateWithAsyncOnlyFakePlan=`
const serviceInstanceResourceAsyncCreateWithAsyncOnlyFakePlan = `
resource "cf_service_instance" "fake-service-instance-with-fake-async-only-plan" {
name = "fake-service-instance-with-fake-async-only-plan"
space = "${data.cf_space.space.id}"
Expand Down

0 comments on commit 5f90fbf

Please sign in to comment.