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

r/servicecatalog_service_action: New resource #19369

Merged
merged 12 commits into from
May 19, 2021
Merged
3 changes: 3 additions & 0 deletions .changelog/19369.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_servicecatalog_service_action
```
12 changes: 12 additions & 0 deletions aws/diff_suppress_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ func suppressEquivalentJsonDiffs(k, old, new string, d *schema.ResourceData) boo
return jsonBytesEqual(ob.Bytes(), nb.Bytes())
}

func suppressEquivalentJsonEmptyNilDiffs(k, old, new string, d *schema.ResourceData) bool {
if old == "[]" && new == "" {
return true
}

if old == "" && new == "[]" {
return true
}

return suppressEquivalentJsonDiffs(k, old, new, d)
}

func suppressOpenIdURL(k, old, new string, d *schema.ResourceData) bool {
oldUrl, err := url.Parse(old)
if err != nil {
Expand Down
29 changes: 29 additions & 0 deletions aws/internal/service/servicecatalog/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func OrganizationsAccessStatus(conn *servicecatalog.ServiceCatalog) resource.Sta
}

if err != nil {

return nil, OrganizationAccessStatusError, fmt.Errorf("error getting Organizations Access: %w", err)
}

Expand Down Expand Up @@ -197,3 +198,31 @@ func ProductPortfolioAssociationStatus(conn *servicecatalog.ServiceCatalog, acce
return output, servicecatalog.StatusAvailable, err
}
}

func ServiceActionStatus(conn *servicecatalog.ServiceCatalog, acceptLanguage, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &servicecatalog.DescribeServiceActionInput{
Id: aws.String(id),
}

if acceptLanguage != "" {
input.AcceptLanguage = aws.String(acceptLanguage)
}

output, err := conn.DescribeServiceAction(input)

if tfawserr.ErrCodeEquals(err, servicecatalog.ErrCodeResourceNotFoundException) {
return nil, StatusNotFound, err
}

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

if output == nil || output.ServiceActionDetail == nil {
return nil, StatusUnavailable, fmt.Errorf("error describing Service Action: empty Service Action Detail")
}

return output.ServiceActionDetail, servicecatalog.StatusAvailable, nil
}
}
37 changes: 37 additions & 0 deletions aws/internal/service/servicecatalog/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const (
ProductPortfolioAssociationReadyTimeout = 3 * time.Minute
ProductPortfolioAssociationDeleteTimeout = 3 * time.Minute

ServiceActionReadyTimeout = 3 * time.Minute
ServiceActionDeleteTimeout = 3 * time.Minute

StatusNotFound = "NOT_FOUND"
StatusUnavailable = "UNAVAILABLE"

Expand Down Expand Up @@ -263,3 +266,37 @@ func ProductPortfolioAssociationDeleted(conn *servicecatalog.ServiceCatalog, acc

return err
}

func ServiceActionReady(conn *servicecatalog.ServiceCatalog, acceptLanguage, id string) (*servicecatalog.ServiceActionDetail, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{StatusNotFound, StatusUnavailable},
Target: []string{servicecatalog.StatusAvailable},
Refresh: ServiceActionStatus(conn, acceptLanguage, id),
Timeout: ServiceActionReadyTimeout,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}

func ServiceActionDeleted(conn *servicecatalog.ServiceCatalog, acceptLanguage, id string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{servicecatalog.StatusAvailable},
Target: []string{StatusNotFound, StatusUnavailable},
Refresh: ServiceActionStatus(conn, acceptLanguage, id),
Timeout: ServiceActionDeleteTimeout,
}

_, err := stateConf.WaitForState()

if tfawserr.ErrCodeEquals(err, servicecatalog.ErrCodeResourceNotFoundException) {
return nil
}

return err
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ func Provider() *schema.Provider {
"aws_servicecatalog_portfolio": resourceAwsServiceCatalogPortfolio(),
"aws_servicecatalog_portfolio_share": resourceAwsServiceCatalogPortfolioShare(),
"aws_servicecatalog_product": resourceAwsServiceCatalogProduct(),
"aws_servicecatalog_service_action": resourceAwsServiceCatalogServiceAction(),
"aws_servicecatalog_tag_option": resourceAwsServiceCatalogTagOption(),
"aws_servicecatalog_product_portfolio_association": resourceAwsServiceCatalogProductPortfolioAssociation(),
"aws_service_discovery_http_namespace": resourceAwsServiceDiscoveryHttpNamespace(),
Expand Down
Loading