Skip to content

Commit

Permalink
published state file reset and egw remove pending state for waiting f…
Browse files Browse the repository at this point in the history
…or pps
  • Loading branch information
deepaksibm committed Oct 17, 2024
1 parent 93d8d32 commit 79fe162
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func resourceIBMIsPrivatePathServiceGatewayOperationsUpdate(context context.Cont
response, err := vpcClient.PublishPrivatePathServiceGatewayWithContext(context, publishPrivatePathServiceGatewayOptions)
if err != nil {
log.Printf("[DEBUG] PublishPrivatePathServiceGatewayWithContext failed %s\n%s", err, response)
resetPublishedSchemaValue(context, d)
return diag.FromErr(fmt.Errorf("PublishPrivatePathServiceGatewayWithContext failed %s\n%s", err, response))
}

Expand All @@ -108,13 +109,21 @@ func resourceIBMIsPrivatePathServiceGatewayOperationsUpdate(context context.Cont
response, err := vpcClient.UnpublishPrivatePathServiceGatewayWithContext(context, unpublishPrivatePathServiceGatewayOptions)
if err != nil {
log.Printf("[DEBUG] unpublishPrivatePathServiceGatewayWithContext failed %s\n%s", err, response)
resetPublishedSchemaValue(context, d)
return diag.FromErr(fmt.Errorf("unpublishublishPrivatePathServiceGatewayWithContext failed %s\n%s", err, response))
}

}
return nil
}

func resetPublishedSchemaValue(context context.Context, d *schema.ResourceData) {
if d.HasChange("published") {
oldIntf, newIntf := d.GetChange("published")
if oldIntf.(bool) != newIntf.(bool) {
d.Set("published", oldIntf.(bool))
}
}
}
func resourceIBMIsPrivatePathServiceGatewayOperationsDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {

d.SetId("")
Expand Down
15 changes: 10 additions & 5 deletions ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func resourceIBMisVirtualEndpointGatewayCreate(d *schema.ResourceData, meta inte

d.SetId(*endpointGateway.ID)

_, err = isWaitForVirtualEndpointGatewayAvailable(sess, d.Id(), d.Timeout(schema.TimeoutCreate))
_, err = isWaitForVirtualEndpointGatewayAvailable(sess, d.Id(), d.Timeout(schema.TimeoutCreate), d.Get(targetResourceTypeFmt).(string), d.IsNewResource())
if err != nil {
return err
}
Expand Down Expand Up @@ -386,6 +386,7 @@ func resourceIBMisVirtualEndpointGatewayUpdate(d *schema.ResourceData, meta inte
if err != nil {
return err
}
targetType := d.Get(isVirtualEndpointGatewayTargetResourceType).(string)
// create option
endpointGatewayPatchModel := new(vpcv1.EndpointGatewayPatch)
if d.HasChange(isVirtualEndpointGatewayName) {
Expand Down Expand Up @@ -420,7 +421,7 @@ func resourceIBMisVirtualEndpointGatewayUpdate(d *schema.ResourceData, meta inte
if err != nil {
return fmt.Errorf("Error while creating Security Group Target Binding %s\n%s", err, response)
}
_, err = isWaitForVirtualEndpointGatewayAvailable(sess, d.Id(), d.Timeout(schema.TimeoutUpdate))
_, err = isWaitForVirtualEndpointGatewayAvailable(sess, d.Id(), d.Timeout(schema.TimeoutUpdate), targetType, d.IsNewResource())
if err != nil {
return err
}
Expand All @@ -444,7 +445,7 @@ func resourceIBMisVirtualEndpointGatewayUpdate(d *schema.ResourceData, meta inte
if err != nil {
return fmt.Errorf("Error Deleting Security Group Target for this endpoint gateway : %s\n%s", err, response)
}
_, err = isWaitForVirtualEndpointGatewayAvailable(sess, d.Id(), d.Timeout(schema.TimeoutUpdate))
_, err = isWaitForVirtualEndpointGatewayAvailable(sess, d.Id(), d.Timeout(schema.TimeoutUpdate), targetType, d.IsNewResource())
if err != nil {
return err
}
Expand Down Expand Up @@ -541,11 +542,15 @@ func flattenDataSourceSecurityGroups(securityGroupList []vpcv1.SecurityGroupRefe
return securitygroupList
}

func isWaitForVirtualEndpointGatewayAvailable(sess *vpcv1.VpcV1, endPointGatewayId string, timeout time.Duration) (interface{}, error) {
func isWaitForVirtualEndpointGatewayAvailable(sess *vpcv1.VpcV1, endPointGatewayId string, timeout time.Duration, targetResourceType string, isNewResource bool) (interface{}, error) {
log.Printf("Waiting for virtual endpoint gateway (%s) to be available.", endPointGatewayId)
pendingStatuses := []string{"waiting", "updating"}

if targetResourceType != "private_path_service_gateway" || !isNewResource {
pendingStatuses = append(pendingStatuses, "pending")
}
stateConf := &resource.StateChangeConf{
Pending: []string{"waiting", "pending", "updating"},
Pending: pendingStatuses,
Target: []string{"stable", "failed", ""},
Refresh: isVirtualEndpointGatewayRefreshFunc(sess, endPointGatewayId),
Timeout: timeout,
Expand Down

0 comments on commit 79fe162

Please sign in to comment.