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

Adds configurable timeouts for aws_config_organization_conformance_pack #20560

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .changelog/20560.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_config_organization_conformance_pack: Add configurable timeouts
```
16 changes: 6 additions & 10 deletions aws/configservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const (
ConfigConformancePackCreateTimeout = 5 * time.Minute
ConfigConformancePackDeleteTimeout = 5 * time.Minute

ConfigOrganizationConformancePackCreateTimeout = 10 * time.Minute
ConfigOrganizationConformancePackUpdateTimeout = 10 * time.Minute
ConfigOrganizationConformancePackDeleteTimeout = 20 * time.Minute

ConfigConformancePackStatusNotFound = "NotFound"
ConfigConformancePackStatusUnknown = "Unknown"
)
Expand Down Expand Up @@ -417,11 +413,11 @@ func configWaitForConformancePackStateDeleteComplete(conn *configservice.ConfigS
return err
}

func configWaitForOrganizationConformancePackStatusCreateSuccessful(conn *configservice.ConfigService, name string) error {
func configWaitForOrganizationConformancePackStatusCreateSuccessful(conn *configservice.ConfigService, name string, timeout time.Duration) error {
stateChangeConf := resource.StateChangeConf{
Pending: []string{configservice.OrganizationResourceStatusCreateInProgress},
Target: []string{configservice.OrganizationResourceStatusCreateSuccessful},
Timeout: ConfigOrganizationConformancePackCreateTimeout,
Timeout: timeout,
Refresh: configRefreshOrganizationConformancePackCreationStatus(conn, name),
// Include a delay to help avoid ResourceDoesNotExist errors
Delay: 30 * time.Second,
Expand All @@ -433,11 +429,11 @@ func configWaitForOrganizationConformancePackStatusCreateSuccessful(conn *config

}

func configWaitForOrganizationConformancePackStatusUpdateSuccessful(conn *configservice.ConfigService, name string) error {
func configWaitForOrganizationConformancePackStatusUpdateSuccessful(conn *configservice.ConfigService, name string, timeout time.Duration) error {
stateChangeConf := resource.StateChangeConf{
Pending: []string{configservice.OrganizationResourceStatusUpdateInProgress},
Target: []string{configservice.OrganizationResourceStatusUpdateSuccessful},
Timeout: ConfigOrganizationConformancePackUpdateTimeout,
Timeout: timeout,
Refresh: configRefreshOrganizationConformancePackStatus(conn, name),
}

Expand All @@ -446,11 +442,11 @@ func configWaitForOrganizationConformancePackStatusUpdateSuccessful(conn *config
return err
}

func configWaitForOrganizationConformancePackStatusDeleteSuccessful(conn *configservice.ConfigService, name string) error {
func configWaitForOrganizationConformancePackStatusDeleteSuccessful(conn *configservice.ConfigService, name string, timeout time.Duration) error {
stateChangeConf := resource.StateChangeConf{
Pending: []string{configservice.OrganizationResourceStatusDeleteInProgress},
Target: []string{configservice.OrganizationResourceStatusDeleteSuccessful},
Timeout: ConfigOrganizationConformancePackDeleteTimeout,
Timeout: timeout,
Refresh: configRefreshOrganizationConformancePackStatus(conn, name),
}

Expand Down
13 changes: 10 additions & 3 deletions aws/resource_aws_config_organization_conformance_pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"regexp"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/configservice"
Expand All @@ -23,6 +24,12 @@ func resourceAwsConfigOrganizationConformancePack() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(20 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -141,7 +148,7 @@ func resourceAwsConfigOrganizationConformancePackCreate(d *schema.ResourceData,

d.SetId(name)

if err := configWaitForOrganizationConformancePackStatusCreateSuccessful(conn, d.Id()); err != nil {
if err := configWaitForOrganizationConformancePackStatusCreateSuccessful(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return fmt.Errorf("error waiting for Config Organization Conformance Pack (%s) to be created: %w", d.Id(), err)
}

Expand Down Expand Up @@ -226,7 +233,7 @@ func resourceAwsConfigOrganizationConformancePackUpdate(d *schema.ResourceData,
return fmt.Errorf("error updating Config Organization Conformance Pack (%s): %w", d.Id(), err)
}

if err := configWaitForOrganizationConformancePackStatusUpdateSuccessful(conn, d.Id()); err != nil {
if err := configWaitForOrganizationConformancePackStatusUpdateSuccessful(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return fmt.Errorf("error waiting for Config Organization Conformance Pack (%s) to be updated: %w", d.Id(), err)
}

Expand All @@ -250,7 +257,7 @@ func resourceAwsConfigOrganizationConformancePackDelete(d *schema.ResourceData,
return fmt.Errorf("erorr deleting Config Organization Conformance Pack (%s): %w", d.Id(), err)
}

if err := configWaitForOrganizationConformancePackStatusDeleteSuccessful(conn, d.Id()); err != nil {
if err := configWaitForOrganizationConformancePackStatusDeleteSuccessful(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil {
if tfawserr.ErrCodeEquals(err, configservice.ErrCodeNoSuchOrganizationConformancePackException) {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ In addition to all arguments above, the following attributes are exported:
* `arn` - Amazon Resource Name (ARN) of the organization conformance pack.
* `id` - The name of the organization conformance pack.

## Timeouts

`aws_config_organization_conformance_pack` provides the following
[Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options:

- `create` - (Default `10 minutes`) Used for creating conformance pack
- `update` - (Default `10 minutes`) Used for conformance pack modifications
- `delete` - (Default `20 minutes`) Used for destroying conformance pack

## Import

Config Organization Conformance Packs can be imported using the `name`, e.g.
Expand Down