Skip to content

Commit

Permalink
i/r/servicecat: Add waiter for new resource
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed May 21, 2021
1 parent 6d04b22 commit 1d759aa
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
24 changes: 24 additions & 0 deletions aws/internal/service/servicecatalog/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,27 @@ func ProvisioningArtifactStatus(conn *servicecatalog.ServiceCatalog, id, product
return output, aws.StringValue(output.Status), err
}
}

func PrincipalPortfolioAssociationStatus(conn *servicecatalog.ServiceCatalog, acceptLanguage, principalARN, portfolioID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := finder.PrincipalPortfolioAssociation(conn, acceptLanguage, principalARN, portfolioID)

if tfawserr.ErrCodeEquals(err, servicecatalog.ErrCodeResourceNotFoundException) {
return nil, StatusNotFound, &resource.NotFoundError{
Message: fmt.Sprintf("principal portfolio association not found (%s): %s", tfservicecatalog.PrincipalPortfolioAssociationID(acceptLanguage, principalARN, portfolioID), err),
}
}

if err != nil {
return nil, servicecatalog.StatusFailed, fmt.Errorf("error describing principal portfolio association: %w", err)
}

if output == nil {
return nil, StatusNotFound, &resource.NotFoundError{
Message: fmt.Sprintf("finding principal portfolio association (%s): empty response", tfservicecatalog.PrincipalPortfolioAssociationID(acceptLanguage, principalARN, portfolioID)),
}
}

return output, servicecatalog.StatusAvailable, err
}
}
33 changes: 33 additions & 0 deletions aws/internal/service/servicecatalog/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const (
ProvisioningArtifactReadyTimeout = 3 * time.Minute
ProvisioningArtifactDeletedTimeout = 3 * time.Minute

PrincipalPortfolioAssociationReadyTimeout = 3 * time.Minute
PrincipalPortfolioAssociationDeleteTimeout = 3 * time.Minute

StatusNotFound = "NOT_FOUND"
StatusUnavailable = "UNAVAILABLE"

Expand Down Expand Up @@ -407,3 +410,33 @@ func ProvisioningArtifactDeleted(conn *servicecatalog.ServiceCatalog, id, produc

return nil
}

func PrincipalPortfolioAssociationReady(conn *servicecatalog.ServiceCatalog, acceptLanguage, principalARN, portfolioID string) (*servicecatalog.Principal, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{StatusNotFound, StatusUnavailable},
Target: []string{servicecatalog.StatusAvailable},
Refresh: PrincipalPortfolioAssociationStatus(conn, acceptLanguage, principalARN, portfolioID),
Timeout: PrincipalPortfolioAssociationReadyTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*servicecatalog.Principal); ok {
return output, err
}

return nil, err
}

func PrincipalPortfolioAssociationDeleted(conn *servicecatalog.ServiceCatalog, acceptLanguage, principalARN, portfolioID string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{servicecatalog.StatusAvailable},
Target: []string{StatusNotFound, StatusUnavailable},
Refresh: PrincipalPortfolioAssociationStatus(conn, acceptLanguage, principalARN, portfolioID),
Timeout: PrincipalPortfolioAssociationDeleteTimeout,
}

_, err := stateConf.WaitForState()

return err
}

0 comments on commit 1d759aa

Please sign in to comment.