-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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/user_pool_domain - remove from state when deleted + move waiters to their own package #14732
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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" | ||
) | ||
|
||
// 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, "", err | ||
} | ||
|
||
if output == nil { | ||
return nil, "", nil | ||
} | ||
|
||
return output, aws.StringValue(output.DomainDescription.Status), nil | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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 | ||
UserPoolDomainCreateTimeout = 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{""}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the "correct" way to do this is This code runs when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this failed for me
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I guess the AWS API may be returning a non-null response but the status is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's what's happening here:
|
||
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), | ||
MinTimeout: UserPoolDomainCreateTimeout, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed! tests are passing |
||
Timeout: timeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*cognitoidentityprovider.DescribeUserPoolDomainOutput); ok { | ||
return output, err | ||
} | ||
|
||
return nil, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest a pattern of
Although these statuses are never explicitly tested, I think having a value other than
""
helps with logging etc.Having the constant names lowercase ensures they're not used outside this package.