Skip to content

Commit

Permalink
Merge pull request #23518 from hashicorp/f-servicecat-config-timeouts
Browse files Browse the repository at this point in the history
servicecat: Add configurable timeouts
  • Loading branch information
YakDriver authored Mar 5, 2022
2 parents 9c0abf9 + 3c945ba commit c02b557
Show file tree
Hide file tree
Showing 39 changed files with 466 additions and 204 deletions.
51 changes: 51 additions & 0 deletions .changelog/23518.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
```release-note:enhancement
resource/aws_servicecatalog_budget_resource_association: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_constraint: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_organizations_access: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_portfolio: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_portfolio_share: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_principal_portfolio_association: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_product: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_product_portfolio_association: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_provisioned_product: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_provisioning_artifact: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_service_action: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_tag_option: Add configurable timeouts
```

```release-note:enhancement
resource/aws_servicecatalog_tag_option_resource_association: Add configurable timeouts
```
13 changes: 9 additions & 4 deletions internal/service/servicecatalog/budget_resource_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

Expand All @@ -23,6 +22,12 @@ func ResourceBudgetResourceAssociation() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(BudgetResourceAssociationReadyTimeout),
Read: schema.DefaultTimeout(BudgetResourceAssociationReadTimeout),
Delete: schema.DefaultTimeout(BudgetResourceAssociationDeleteTimeout),
},

Schema: map[string]*schema.Schema{
"budget_name": {
Type: schema.TypeString,
Expand All @@ -47,7 +52,7 @@ func resourceBudgetResourceAssociationCreate(d *schema.ResourceData, meta interf
}

var output *servicecatalog.AssociateBudgetWithResourceOutput
err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
var err error

output, err = conn.AssociateBudgetWithResource(input)
Expand Down Expand Up @@ -89,7 +94,7 @@ func resourceBudgetResourceAssociationRead(d *schema.ResourceData, meta interfac
return fmt.Errorf("could not parse ID (%s): %w", d.Id(), err)
}

output, err := WaitBudgetResourceAssociationReady(conn, budgetName, resourceID)
output, err := WaitBudgetResourceAssociationReady(conn, budgetName, resourceID, d.Timeout(schema.TimeoutRead))

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Service Catalog Budget Resource Association (%s) not found, removing from state", d.Id())
Expand Down Expand Up @@ -135,7 +140,7 @@ func resourceBudgetResourceAssociationDelete(d *schema.ResourceData, meta interf
return fmt.Errorf("error disassociating Service Catalog Budget from Resource (%s): %w", d.Id(), err)
}

err = WaitBudgetResourceAssociationDeleted(conn, budgetName, resourceID)
err = WaitBudgetResourceAssociationDeleted(conn, budgetName, resourceID, d.Timeout(schema.TimeoutDelete))

if err != nil && !tfresource.NotFound(err) {
return fmt.Errorf("error waiting for Service Catalog Budget Resource Disassociation (%s): %w", d.Id(), err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func testAccCheckBudgetResourceAssociationDestroy(s *terraform.State) error {
return fmt.Errorf("could not parse ID (%s): %w", rs.Primary.ID, err)
}

err = tfservicecatalog.WaitBudgetResourceAssociationDeleted(conn, budgetName, resourceID)
err = tfservicecatalog.WaitBudgetResourceAssociationDeleted(conn, budgetName, resourceID, tfservicecatalog.BudgetResourceAssociationDeleteTimeout)

if tfresource.NotFound(err) {
continue
Expand Down Expand Up @@ -109,7 +109,7 @@ func testAccCheckBudgetResourceAssociationExists(resourceName string) resource.T

conn := acctest.Provider.Meta().(*conns.AWSClient).ServiceCatalogConn

_, err = tfservicecatalog.WaitBudgetResourceAssociationReady(conn, budgetName, resourceID)
_, err = tfservicecatalog.WaitBudgetResourceAssociationReady(conn, budgetName, resourceID, tfservicecatalog.BudgetResourceAssociationReadyTimeout)

if err != nil {
return fmt.Errorf("waiting for Service Catalog Budget Resource Association existence (%s): %w", rs.Primary.ID, err)
Expand Down
16 changes: 11 additions & 5 deletions internal/service/servicecatalog/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
Expand All @@ -26,6 +25,13 @@ func ResourceConstraint() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(ConstraintReadyTimeout),
Read: schema.DefaultTimeout(ConstraintReadTimeout),
Update: schema.DefaultTimeout(ConstraintUpdateTimeout),
Delete: schema.DefaultTimeout(ConstraintDeleteTimeout),
},

Schema: map[string]*schema.Schema{
"accept_language": {
Type: schema.TypeString,
Expand Down Expand Up @@ -92,7 +98,7 @@ func resourceConstraintCreate(d *schema.ResourceData, meta interface{}) error {
}

var output *servicecatalog.CreateConstraintOutput
err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
var err error

output, err = conn.CreateConstraint(input)
Expand Down Expand Up @@ -132,7 +138,7 @@ func resourceConstraintCreate(d *schema.ResourceData, meta interface{}) error {
func resourceConstraintRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).ServiceCatalogConn

output, err := WaitConstraintReady(conn, d.Get("accept_language").(string), d.Id())
output, err := WaitConstraintReady(conn, d.Get("accept_language").(string), d.Id(), d.Timeout(schema.TimeoutRead))

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Service Catalog Constraint (%s) not found, removing from state", d.Id())
Expand Down Expand Up @@ -189,7 +195,7 @@ func resourceConstraintUpdate(d *schema.ResourceData, meta interface{}) error {
input.Parameters = aws.String(d.Get("parameters").(string))
}

err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError {
err := resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
_, err := conn.UpdateConstraint(input)

if tfawserr.ErrMessageContains(err, servicecatalog.ErrCodeInvalidParametersException, "profile does not exist") {
Expand Down Expand Up @@ -235,7 +241,7 @@ func resourceConstraintDelete(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error deleting Service Catalog Constraint (%s): %w", d.Id(), err)
}

err = WaitConstraintDeleted(conn, d.Get("accept_language").(string), d.Id())
err = WaitConstraintDeleted(conn, d.Get("accept_language").(string), d.Id(), d.Timeout(schema.TimeoutDelete))

if err != nil && !tfresource.NotFound(err) {
return fmt.Errorf("error waiting for Service Catalog Constraint (%s) to be deleted: %w", d.Id(), err)
Expand Down
6 changes: 5 additions & 1 deletion internal/service/servicecatalog/constraint_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func DataSourceConstraint() *schema.Resource {
return &schema.Resource{
Read: dataSourceConstraintRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(ConstraintReadTimeout),
},

Schema: map[string]*schema.Schema{
"accept_language": {
Type: schema.TypeString,
Expand Down Expand Up @@ -60,7 +64,7 @@ func DataSourceConstraint() *schema.Resource {
func dataSourceConstraintRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).ServiceCatalogConn

output, err := WaitConstraintReady(conn, d.Get("accept_language").(string), d.Get("id").(string))
output, err := WaitConstraintReady(conn, d.Get("accept_language").(string), d.Get("id").(string), d.Timeout(schema.TimeoutRead))

if err != nil {
return fmt.Errorf("error describing Service Catalog Constraint: %w", err)
Expand Down
22 changes: 13 additions & 9 deletions internal/service/servicecatalog/launch_paths_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func DataSourceLaunchPaths() *schema.Resource {
return &schema.Resource{
Read: dataSourceLaunchPathsRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(LaunchPathsReadyTimeout),
},

Schema: map[string]*schema.Schema{
"accept_language": {
Type: schema.TypeString,
Expand Down Expand Up @@ -67,13 +71,13 @@ func dataSourceLaunchPathsRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).ServiceCatalogConn
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

summaries, err := WaitLaunchPathsReady(conn, d.Get("accept_language").(string), d.Get("product_id").(string))
summaries, err := WaitLaunchPathsReady(conn, d.Get("accept_language").(string), d.Get("product_id").(string), d.Timeout(schema.TimeoutRead))

if err != nil {
return fmt.Errorf("error describing Service Catalog Launch Paths: %w", err)
}

if err := d.Set("summaries", flattenServiceCatalogLaunchPathSummaries(summaries, ignoreTagsConfig)); err != nil {
if err := d.Set("summaries", flattenLaunchPathSummaries(summaries, ignoreTagsConfig)); err != nil {
return fmt.Errorf("error setting summaries: %w", err)
}

Expand All @@ -82,15 +86,15 @@ func dataSourceLaunchPathsRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

func flattenServiceCatalogLaunchPathSummary(apiObject *servicecatalog.LaunchPathSummary, ignoreTagsConfig *tftags.IgnoreConfig) map[string]interface{} {
func flattenLaunchPathSummary(apiObject *servicecatalog.LaunchPathSummary, ignoreTagsConfig *tftags.IgnoreConfig) map[string]interface{} {
if apiObject == nil {
return nil
}

tfMap := map[string]interface{}{}

if len(apiObject.ConstraintSummaries) > 0 {
tfMap["constraint_summaries"] = flattenServiceCatalogConstraintSummaries(apiObject.ConstraintSummaries)
tfMap["constraint_summaries"] = flattenConstraintSummaries(apiObject.ConstraintSummaries)
}

if apiObject.Id != nil {
Expand All @@ -108,7 +112,7 @@ func flattenServiceCatalogLaunchPathSummary(apiObject *servicecatalog.LaunchPath
return tfMap
}

func flattenServiceCatalogLaunchPathSummaries(apiObjects []*servicecatalog.LaunchPathSummary, ignoreTagsConfig *tftags.IgnoreConfig) []interface{} {
func flattenLaunchPathSummaries(apiObjects []*servicecatalog.LaunchPathSummary, ignoreTagsConfig *tftags.IgnoreConfig) []interface{} {
if len(apiObjects) == 0 {
return nil
}
Expand All @@ -120,13 +124,13 @@ func flattenServiceCatalogLaunchPathSummaries(apiObjects []*servicecatalog.Launc
continue
}

tfList = append(tfList, flattenServiceCatalogLaunchPathSummary(apiObject, ignoreTagsConfig))
tfList = append(tfList, flattenLaunchPathSummary(apiObject, ignoreTagsConfig))
}

return tfList
}

func flattenServiceCatalogConstraintSummary(apiObject *servicecatalog.ConstraintSummary) map[string]interface{} {
func flattenConstraintSummary(apiObject *servicecatalog.ConstraintSummary) map[string]interface{} {
if apiObject == nil {
return nil
}
Expand All @@ -144,7 +148,7 @@ func flattenServiceCatalogConstraintSummary(apiObject *servicecatalog.Constraint
return tfMap
}

func flattenServiceCatalogConstraintSummaries(apiObjects []*servicecatalog.ConstraintSummary) []interface{} {
func flattenConstraintSummaries(apiObjects []*servicecatalog.ConstraintSummary) []interface{} {
if len(apiObjects) == 0 {
return nil
}
Expand All @@ -156,7 +160,7 @@ func flattenServiceCatalogConstraintSummaries(apiObjects []*servicecatalog.Const
continue
}

tfList = append(tfList, flattenServiceCatalogConstraintSummary(apiObject))
tfList = append(tfList, flattenConstraintSummary(apiObject))
}

return tfList
Expand Down
6 changes: 5 additions & 1 deletion internal/service/servicecatalog/organizations_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func ResourceOrganizationsAccess() *schema.Resource {
Read: resourceOrganizationsAccessRead,
Delete: resourceOrganizationsAccessDelete,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(OrganizationsAccessStableTimeout),
},

Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -56,7 +60,7 @@ func resourceOrganizationsAccessCreate(d *schema.ResourceData, meta interface{})
func resourceOrganizationsAccessRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).ServiceCatalogConn

output, err := WaitOrganizationsAccessStable(conn)
output, err := WaitOrganizationsAccessStable(conn, d.Timeout(schema.TimeoutRead))

if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, servicecatalog.ErrCodeResourceNotFoundException) {
// theoretically this should not be possible
Expand Down
4 changes: 2 additions & 2 deletions internal/service/servicecatalog/organizations_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func testAccCheckOrganizationsAccessDestroy(s *terraform.State) error {
continue
}

output, err := tfservicecatalog.WaitOrganizationsAccessStable(conn)
output, err := tfservicecatalog.WaitOrganizationsAccessStable(conn, tfservicecatalog.OrganizationsAccessStableTimeout)

if err != nil {
return fmt.Errorf("error describing Service Catalog AWS Organizations Access (%s): %w", rs.Primary.ID, err)
Expand All @@ -70,7 +70,7 @@ func testAccCheckOrganizationsAccessExists(resourceName string) resource.TestChe

conn := acctest.Provider.Meta().(*conns.AWSClient).ServiceCatalogConn

output, err := tfservicecatalog.WaitOrganizationsAccessStable(conn)
output, err := tfservicecatalog.WaitOrganizationsAccessStable(conn, tfservicecatalog.OrganizationsAccessStableTimeout)

if err != nil {
return fmt.Errorf("error describing Service Catalog AWS Organizations Access (%s): %w", rs.Primary.ID, err)
Expand Down
7 changes: 4 additions & 3 deletions internal/service/servicecatalog/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ func ResourcePortfolio() *schema.Resource {
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
Create: schema.DefaultTimeout(PortfolioCreateTimeout),
Read: schema.DefaultTimeout(PortfolioReadTimeout),
Update: schema.DefaultTimeout(PortfolioUpdateTimeout),
Delete: schema.DefaultTimeout(PortfolioDeleteTimeout),
},

Schema: map[string]*schema.Schema{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func DataSourcePortfolioConstraints() *schema.Resource {
return &schema.Resource{
Read: dataSourcePortfolioConstraintsRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(PortfolioConstraintsReadyTimeout),
},

Schema: map[string]*schema.Schema{
"accept_language": {
Type: schema.TypeString,
Expand Down Expand Up @@ -68,7 +72,7 @@ func DataSourcePortfolioConstraints() *schema.Resource {
func dataSourcePortfolioConstraintsRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).ServiceCatalogConn

output, err := WaitPortfolioConstraintsReady(conn, d.Get("accept_language").(string), d.Get("portfolio_id").(string), d.Get("product_id").(string))
output, err := WaitPortfolioConstraintsReady(conn, d.Get("accept_language").(string), d.Get("portfolio_id").(string), d.Get("product_id").(string), d.Timeout(schema.TimeoutRead))

if err != nil {
return fmt.Errorf("error describing Service Catalog Portfolio Constraints: %w", err)
Expand All @@ -88,7 +92,7 @@ func dataSourcePortfolioConstraintsRead(d *schema.ResourceData, meta interface{}
d.Set("portfolio_id", d.Get("portfolio_id").(string))
d.Set("product_id", d.Get("product_id").(string))

if err := d.Set("details", flattenServiceCatalogConstraintDetails(output)); err != nil {
if err := d.Set("details", flattenConstraintDetails(output)); err != nil {
return fmt.Errorf("error setting details: %w", err)
}

Expand All @@ -97,7 +101,7 @@ func dataSourcePortfolioConstraintsRead(d *schema.ResourceData, meta interface{}
return nil
}

func flattenServiceCatalogConstraintDetail(apiObject *servicecatalog.ConstraintDetail) map[string]interface{} {
func flattenConstraintDetail(apiObject *servicecatalog.ConstraintDetail) map[string]interface{} {
if apiObject == nil {
return nil
}
Expand Down Expand Up @@ -131,7 +135,7 @@ func flattenServiceCatalogConstraintDetail(apiObject *servicecatalog.ConstraintD
return tfMap
}

func flattenServiceCatalogConstraintDetails(apiObjects []*servicecatalog.ConstraintDetail) []interface{} {
func flattenConstraintDetails(apiObjects []*servicecatalog.ConstraintDetail) []interface{} {
if len(apiObjects) == 0 {
return nil
}
Expand All @@ -143,7 +147,7 @@ func flattenServiceCatalogConstraintDetails(apiObjects []*servicecatalog.Constra
continue
}

tfList = append(tfList, flattenServiceCatalogConstraintDetail(apiObject))
tfList = append(tfList, flattenConstraintDetail(apiObject))
}

return tfList
Expand Down
Loading

0 comments on commit c02b557

Please sign in to comment.