Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error handling of entitlement polling #354

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/provider/resource_subaccount_entitlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -190,7 +191,7 @@ func (rs *subaccountEntitlementResource) createOrUpdate(ctx context.Context, req
// wait for the entitlement to become effective
createStateConf := &tfutils.StateChangeConf{
Pending: []string{cis_entitlements.StateStarted, cis_entitlements.StateProcessing},
Target: []string{cis_entitlements.StateOK, cis_entitlements.StateProcessingFailed},
Target: []string{cis_entitlements.StateOK},
Refresh: func() (interface{}, string, error) {
entitlement, _, err := rs.cli.Accounts.Entitlement.GetAssignedBySubaccount(ctx, plan.SubaccountId.ValueString(), plan.ServiceName.ValueString(), plan.PlanName.ValueString())

Expand All @@ -201,6 +202,10 @@ func (rs *subaccountEntitlementResource) createOrUpdate(ctx context.Context, req
if entitlement == nil {
return nil, cis_entitlements.StateProcessing, nil
}
// No error returned even if operation failed
if entitlement.Assignment.EntityState == cis_entitlements.StateProcessingFailed {
return *entitlement, entitlement.Assignment.EntityState, errors.New("undefined API error during entitlement processing")
}

return *entitlement, entitlement.Assignment.EntityState, nil
},
Expand Down Expand Up @@ -245,7 +250,7 @@ func (rs *subaccountEntitlementResource) Delete(ctx context.Context, req resourc

deleteStateConf := &tfutils.StateChangeConf{
Pending: []string{cis_entitlements.StateStarted, cis_entitlements.StateProcessing},
Target: []string{cis_entitlements.StateProcessingFailed, "DELETED"},
Target: []string{"DELETED"},
Refresh: func() (interface{}, string, error) {

entitlement, _, err := rs.cli.Accounts.Entitlement.GetAssignedBySubaccount(ctx, state.SubaccountId.ValueString(), state.ServiceName.ValueString(), state.PlanName.ValueString())
Expand All @@ -258,6 +263,11 @@ func (rs *subaccountEntitlementResource) Delete(ctx context.Context, req resourc
return entitlement, cis_entitlements.StateProcessingFailed, err
}

// No error returned even if operation failed
if entitlement.Assignment.EntityState == cis_entitlements.StateProcessingFailed {
return *entitlement, entitlement.Assignment.EntityState, errors.New("undefined API error during entitlement processing")
}

return entitlement, cis_entitlements.StateProcessing, nil
},
Timeout: 10 * time.Minute,
Expand Down
Loading