-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resource/aws_user_pool_domain: Remove from state when deleted + move …
…waiters to their own package (#14732) Output from acceptance testing: ``` --- PASS: TestAccAWSCognitoUserPoolDomain_disappears (15.35s) --- PASS: TestAccAWSCognitoUserPoolDomain_basic (17.98s) ```
- Loading branch information
Showing
4 changed files
with
132 additions
and
58 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
aws/internal/service/cognitoidentityprovider/waiter/status.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package waiter | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const ( | ||
userPoolDomainStatusNotFound = "NotFound" | ||
userPoolDomainStatusUnknown = "Unknown" | ||
) | ||
|
||
// UserPoolDomainStatus fetches the Operation and its Status | ||
func UserPoolDomainStatus(conn *cognitoidentityprovider.CognitoIdentityProvider, domain string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
input := &cognitoidentityprovider.DescribeUserPoolDomainInput{ | ||
Domain: aws.String(domain), | ||
} | ||
|
||
output, err := conn.DescribeUserPoolDomain(input) | ||
|
||
if err != nil { | ||
return nil, userPoolDomainStatusUnknown, err | ||
} | ||
|
||
if output == nil { | ||
return nil, userPoolDomainStatusNotFound, nil | ||
} | ||
|
||
return output, aws.StringValue(output.DomainDescription.Status), nil | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
aws/internal/service/cognitoidentityprovider/waiter/waiter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package waiter | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const ( | ||
// Maximum amount of time to wait for an Operation to return Success | ||
UserPoolDomainDeleteTimeout = 1 * time.Minute | ||
) | ||
|
||
// UserPoolDomainDeleted waits for an Operation to return Success | ||
func UserPoolDomainDeleted(conn *cognitoidentityprovider.CognitoIdentityProvider, domain string) (*cognitoidentityprovider.DescribeUserPoolDomainOutput, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
cognitoidentityprovider.DomainStatusTypeUpdating, | ||
cognitoidentityprovider.DomainStatusTypeDeleting, | ||
}, | ||
Target: []string{""}, | ||
Refresh: UserPoolDomainStatus(conn, domain), | ||
Timeout: UserPoolDomainDeleteTimeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*cognitoidentityprovider.DescribeUserPoolDomainOutput); ok { | ||
return output, err | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
func UserPoolDomainCreated(conn *cognitoidentityprovider.CognitoIdentityProvider, domain string, timeout time.Duration) (*cognitoidentityprovider.DescribeUserPoolDomainOutput, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
cognitoidentityprovider.DomainStatusTypeCreating, | ||
cognitoidentityprovider.DomainStatusTypeUpdating, | ||
}, | ||
Target: []string{ | ||
cognitoidentityprovider.DomainStatusTypeActive, | ||
}, | ||
Refresh: UserPoolDomainStatus(conn, domain), | ||
Timeout: timeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*cognitoidentityprovider.DescribeUserPoolDomainOutput); ok { | ||
return output, err | ||
} | ||
|
||
return nil, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters