diff --git a/ibm/resource_ibm_is_instance_group.go b/ibm/resource_ibm_is_instance_group.go index 15dad02cf1..7d76495bd7 100644 --- a/ibm/resource_ibm_is_instance_group.go +++ b/ibm/resource_ibm_is_instance_group.go @@ -239,7 +239,7 @@ func resourceIBMISInstanceGroupCreate(d *schema.ResourceData, meta interface{}) } d.SetId(*instanceGroup.ID) - _, healthError := waitForHealthyInstanceGroup(d, meta, d.Timeout(schema.TimeoutCreate)) + _, healthError := waitForHealthyInstanceGroup(d.Id(), meta, d.Timeout(schema.TimeoutCreate)) if healthError != nil { return healthError } @@ -339,7 +339,7 @@ func resourceIBMISInstanceGroupUpdate(d *schema.ResourceData, meta interface{}) } // wait for instance group health update with update timeout configured. - _, healthError := waitForHealthyInstanceGroup(d, meta, d.Timeout(schema.TimeoutUpdate)) + _, healthError := waitForHealthyInstanceGroup(instanceGroupID, meta, d.Timeout(schema.TimeoutUpdate)) if healthError != nil { return healthError } @@ -445,7 +445,7 @@ func resourceIBMISInstanceGroupDelete(d *schema.ResourceData, meta interface{}) if err != nil { return fmt.Errorf("Error updating instanceGroup's instance count to 0 : %s\n%s", err, response) } - _, healthError := waitForHealthyInstanceGroup(d, meta, d.Timeout(schema.TimeoutUpdate)) + _, healthError := waitForHealthyInstanceGroup(instanceGroupID, meta, d.Timeout(schema.TimeoutUpdate)) if healthError != nil { return healthError } @@ -511,13 +511,12 @@ func resourceIBMISInstanceGroupExists(d *schema.ResourceData, meta interface{}) return true, nil } -func waitForHealthyInstanceGroup(d *schema.ResourceData, meta interface{}, timeout time.Duration) (interface{}, error) { +func waitForHealthyInstanceGroup(instanceGroupID string, meta interface{}, timeout time.Duration) (interface{}, error) { sess, err := vpcClient(meta) if err != nil { return nil, err } - instanceGroupID := d.Id() getInstanceGroupOptions := vpcv1.GetInstanceGroupOptions{ID: &instanceGroupID} healthStateConf := &resource.StateChangeConf{ diff --git a/ibm/resource_ibm_is_instance_group_manager_policy.go b/ibm/resource_ibm_is_instance_group_manager_policy.go index b6f2f03ee4..97b4702801 100644 --- a/ibm/resource_ibm_is_instance_group_manager_policy.go +++ b/ibm/resource_ibm_is_instance_group_manager_policy.go @@ -128,6 +128,16 @@ func resourceIBMISInstanceGroupManagerPolicyCreate(d *schema.ResourceData, meta InstanceGroupManagerID: &instanceGroupManagerID, InstanceGroupManagerPolicyPrototype: &instanceGroupManagerPolicyPrototype, } + + isInsGrpKey := "Instance_Group_Key_" + instanceGroupID + ibmMutexKV.Lock(isInsGrpKey) + defer ibmMutexKV.Unlock(isInsGrpKey) + + _, healthError := waitForHealthyInstanceGroup(instanceGroupID, meta, d.Timeout(schema.TimeoutCreate)) + if healthError != nil { + return healthError + } + data, response, err := sess.CreateInstanceGroupManagerPolicy(&createInstanceGroupManagerPolicyOptions) if err != nil || data == nil { return fmt.Errorf("Error Creating InstanceGroup Manager Policy: %s\n%s", err, response) @@ -180,6 +190,15 @@ func resourceIBMISInstanceGroupManagerPolicyUpdate(d *schema.ResourceData, meta updateInstanceGroupManagerPolicyOptions.InstanceGroupID = &instanceGroupID updateInstanceGroupManagerPolicyOptions.InstanceGroupManagerID = &instanceGroupManagerID + isInsGrpKey := "Instance_Group_Key_" + instanceGroupID + ibmMutexKV.Lock(isInsGrpKey) + defer ibmMutexKV.Unlock(isInsGrpKey) + + _, healthError := waitForHealthyInstanceGroup(instanceGroupID, meta, d.Timeout(schema.TimeoutUpdate)) + if healthError != nil { + return healthError + } + _, response, err := sess.UpdateInstanceGroupManagerPolicy(&updateInstanceGroupManagerPolicyOptions) if err != nil { return fmt.Errorf("Error Updating InstanceGroup Manager Policy: %s\n%s", err, response) @@ -245,6 +264,16 @@ func resourceIBMISInstanceGroupManagerPolicyDelete(d *schema.ResourceData, meta InstanceGroupManagerID: &instanceGroupManagerID, InstanceGroupID: &instanceGroupID, } + + isInsGrpKey := "Instance_Group_Key_" + instanceGroupID + ibmMutexKV.Lock(isInsGrpKey) + defer ibmMutexKV.Unlock(isInsGrpKey) + + _, healthError := waitForHealthyInstanceGroup(instanceGroupID, meta, d.Timeout(schema.TimeoutDelete)) + if healthError != nil { + return healthError + } + response, err := sess.DeleteInstanceGroupManagerPolicy(&deleteInstanceGroupManagerPolicyOptions) if err != nil { if response != nil && response.StatusCode == 404 {